2008-05-30 11:40:08 +00:00
|
|
|
<?php
|
|
|
|
/* SVN FILE: $Id$ */
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-05-30 11:40:08 +00:00
|
|
|
/**
|
2009-03-19 21:10:13 +00:00
|
|
|
* ThemeViewTest file
|
2008-05-30 11:40:08 +00:00
|
|
|
*
|
|
|
|
* Long description for file
|
|
|
|
*
|
|
|
|
* PHP versions 4 and 5
|
|
|
|
*
|
|
|
|
* CakePHP(tm) Tests <https://trac.cakephp.org/wiki/Developement/TestSuite>
|
2008-10-30 17:30:26 +00:00
|
|
|
* Copyright 2005-2008, Cake Software Foundation, Inc. (http://www.cakefoundation.org)
|
2008-05-30 11:40:08 +00:00
|
|
|
*
|
|
|
|
* Licensed under The Open Group Test Suite License
|
|
|
|
* Redistributions of files must retain the above copyright notice.
|
|
|
|
*
|
|
|
|
* @filesource
|
2008-10-30 17:30:26 +00:00
|
|
|
* @copyright Copyright 2005-2008, Cake Software Foundation, Inc. (http://www.cakefoundation.org)
|
|
|
|
* @link https://trac.cakephp.org/wiki/Developement/TestSuite CakePHP(tm) Tests
|
2009-03-19 21:10:13 +00:00
|
|
|
* @package cake
|
2008-10-30 17:30:26 +00:00
|
|
|
* @subpackage cake.tests.cases.libs
|
|
|
|
* @since CakePHP(tm) v 1.2.0.4206
|
|
|
|
* @version $Revision$
|
|
|
|
* @modifiedby $LastChangedBy$
|
|
|
|
* @lastmodified $Date$
|
|
|
|
* @license http://www.opensource.org/licenses/opengroup.php The Open Group Test Suite License
|
2008-05-30 11:40:08 +00:00
|
|
|
*/
|
2008-07-30 13:57:24 +00:00
|
|
|
App::import('Core', array('Theme', 'Controller'));
|
2009-03-19 21:10:13 +00:00
|
|
|
|
2008-07-30 13:57:24 +00:00
|
|
|
if (!class_exists('ErrorHandler')) {
|
|
|
|
App::import('Core', array('Error'));
|
|
|
|
}
|
2008-05-30 11:40:08 +00:00
|
|
|
if (!defined('CAKEPHP_UNIT_TEST_EXECUTION')) {
|
|
|
|
define('CAKEPHP_UNIT_TEST_EXECUTION', 1);
|
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-06-02 19:22:55 +00:00
|
|
|
/**
|
|
|
|
* ThemePostsController class
|
2008-06-11 15:46:31 +00:00
|
|
|
*
|
2008-10-30 17:30:26 +00:00
|
|
|
* @package cake
|
|
|
|
* @subpackage cake.tests.cases.libs.view
|
2008-06-02 19:22:55 +00:00
|
|
|
*/
|
2008-05-30 11:40:08 +00:00
|
|
|
class ThemePostsController extends Controller {
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-06-02 19:22:55 +00:00
|
|
|
/**
|
|
|
|
* name property
|
2008-06-11 15:46:31 +00:00
|
|
|
*
|
2008-06-02 19:22:55 +00:00
|
|
|
* @var string 'ThemePosts'
|
|
|
|
* @access public
|
|
|
|
*/
|
2008-05-30 11:40:08 +00:00
|
|
|
var $name = 'ThemePosts';
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-06-02 19:22:55 +00:00
|
|
|
/**
|
|
|
|
* index method
|
2008-06-11 15:46:31 +00:00
|
|
|
*
|
2008-06-02 19:22:55 +00:00
|
|
|
* @access public
|
|
|
|
* @return void
|
|
|
|
*/
|
2008-05-30 11:40:08 +00:00
|
|
|
function index() {
|
|
|
|
$this->set('testData', 'Some test data');
|
|
|
|
$test2 = 'more data';
|
|
|
|
$test3 = 'even more data';
|
|
|
|
$this->set(compact('test2', 'test3'));
|
|
|
|
}
|
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-06-02 19:22:55 +00:00
|
|
|
/**
|
|
|
|
* ThemeViewTestErrorHandler class
|
2008-06-11 15:46:31 +00:00
|
|
|
*
|
2008-10-30 17:30:26 +00:00
|
|
|
* @package cake
|
|
|
|
* @subpackage cake.tests.cases.libs.view
|
2008-06-02 19:22:55 +00:00
|
|
|
*/
|
2008-05-30 11:40:08 +00:00
|
|
|
class ThemeViewTestErrorHandler extends ErrorHandler {
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-06-02 19:22:55 +00:00
|
|
|
/**
|
|
|
|
* stop method
|
2008-06-11 15:46:31 +00:00
|
|
|
*
|
2008-06-02 19:22:55 +00:00
|
|
|
* @access public
|
|
|
|
* @return void
|
|
|
|
*/
|
2008-06-04 19:04:58 +00:00
|
|
|
function _stop() {
|
2008-05-30 11:40:08 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-06-02 19:22:55 +00:00
|
|
|
/**
|
|
|
|
* TestThemeView class
|
2008-06-11 15:46:31 +00:00
|
|
|
*
|
2008-10-30 17:30:26 +00:00
|
|
|
* @package cake
|
|
|
|
* @subpackage cake.tests.cases.libs.view
|
2008-06-02 19:22:55 +00:00
|
|
|
*/
|
2008-05-30 11:40:08 +00:00
|
|
|
class TestThemeView extends ThemeView {
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-06-02 19:22:55 +00:00
|
|
|
/**
|
|
|
|
* renderElement method
|
2008-06-11 15:46:31 +00:00
|
|
|
*
|
|
|
|
* @param mixed $name
|
|
|
|
* @param array $params
|
2008-06-02 19:22:55 +00:00
|
|
|
* @access public
|
|
|
|
* @return void
|
|
|
|
*/
|
2008-05-30 11:40:08 +00:00
|
|
|
function renderElement($name, $params = array()) {
|
|
|
|
return $name;
|
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-06-02 19:22:55 +00:00
|
|
|
/**
|
|
|
|
* getViewFileName method
|
2008-06-11 15:46:31 +00:00
|
|
|
*
|
|
|
|
* @param mixed $name
|
2008-06-02 19:22:55 +00:00
|
|
|
* @access public
|
|
|
|
* @return void
|
|
|
|
*/
|
2008-05-30 11:40:08 +00:00
|
|
|
function getViewFileName($name = null) {
|
|
|
|
return $this->_getViewFileName($name);
|
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-06-02 19:22:55 +00:00
|
|
|
/**
|
|
|
|
* getLayoutFileName method
|
2008-06-11 15:46:31 +00:00
|
|
|
*
|
|
|
|
* @param mixed $name
|
2008-06-02 19:22:55 +00:00
|
|
|
* @access public
|
|
|
|
* @return void
|
|
|
|
*/
|
2008-05-30 11:40:08 +00:00
|
|
|
function getLayoutFileName($name = null) {
|
|
|
|
return $this->_getLayoutFileName($name);
|
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-06-02 19:22:55 +00:00
|
|
|
/**
|
|
|
|
* cakeError method
|
2008-06-11 15:46:31 +00:00
|
|
|
*
|
|
|
|
* @param mixed $method
|
|
|
|
* @param mixed $messages
|
2008-06-02 19:22:55 +00:00
|
|
|
* @access public
|
|
|
|
* @return void
|
|
|
|
*/
|
2008-05-30 11:40:08 +00:00
|
|
|
function cakeError($method, $messages) {
|
2008-06-11 15:46:31 +00:00
|
|
|
$error =& new ThemeViewTestErrorHandler($method, $messages);
|
2008-05-30 11:40:08 +00:00
|
|
|
return $error;
|
|
|
|
}
|
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-05-30 11:40:08 +00:00
|
|
|
/**
|
2009-03-19 21:10:13 +00:00
|
|
|
* ThemeViewTest class
|
2008-05-30 11:40:08 +00:00
|
|
|
*
|
2009-03-19 21:10:13 +00:00
|
|
|
* @package cake
|
2008-10-30 17:30:26 +00:00
|
|
|
* @subpackage cake.tests.cases.libs
|
2008-05-30 11:40:08 +00:00
|
|
|
*/
|
2008-07-21 02:40:58 +00:00
|
|
|
class ThemeViewTest extends CakeTestCase {
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-06-02 19:22:55 +00:00
|
|
|
/**
|
|
|
|
* setUp method
|
2008-06-11 15:46:31 +00:00
|
|
|
*
|
2008-06-02 19:22:55 +00:00
|
|
|
* @access public
|
|
|
|
* @return void
|
|
|
|
*/
|
2008-05-30 11:40:08 +00:00
|
|
|
function setUp() {
|
|
|
|
Router::reload();
|
|
|
|
$this->Controller = new Controller();
|
|
|
|
$this->PostsController = new ThemePostsController();
|
|
|
|
$this->PostsController->viewPath = 'posts';
|
|
|
|
$this->PostsController->index();
|
|
|
|
$this->ThemeView = new ThemeView($this->PostsController);
|
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2009-03-19 21:10:13 +00:00
|
|
|
/**
|
|
|
|
* tearDown method
|
|
|
|
*
|
|
|
|
* @access public
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
function tearDown() {
|
|
|
|
unset($this->ThemeView);
|
|
|
|
unset($this->PostsController);
|
|
|
|
unset($this->Controller);
|
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2009-07-20 16:59:16 +00:00
|
|
|
/**
|
|
|
|
* startTest
|
|
|
|
*
|
|
|
|
* @access public
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
function startTest() {
|
|
|
|
App::build(array(
|
|
|
|
'plugins' => array(TEST_CAKE_CORE_INCLUDE_PATH . 'tests' . DS . 'test_app' . DS . 'plugins' . DS),
|
|
|
|
'views' => array(TEST_CAKE_CORE_INCLUDE_PATH . 'tests' . DS . 'test_app' . DS . 'views'. DS)
|
|
|
|
));
|
2009-07-24 19:18:37 +00:00
|
|
|
}
|
|
|
|
|
2009-06-11 16:13:16 +00:00
|
|
|
/**
|
|
|
|
* endTest
|
|
|
|
*
|
|
|
|
* @access public
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
function endTest() {
|
|
|
|
App::build();
|
2009-07-24 19:18:37 +00:00
|
|
|
}
|
|
|
|
|
2008-06-02 19:22:55 +00:00
|
|
|
/**
|
|
|
|
* testPluginGetTemplate method
|
2008-06-11 15:46:31 +00:00
|
|
|
*
|
2008-06-02 19:22:55 +00:00
|
|
|
* @access public
|
|
|
|
* @return void
|
|
|
|
*/
|
2008-05-30 11:40:08 +00:00
|
|
|
function testPluginGetTemplate() {
|
|
|
|
$this->Controller->plugin = 'test_plugin';
|
|
|
|
$this->Controller->name = 'TestPlugin';
|
2008-08-01 16:23:16 +00:00
|
|
|
$this->Controller->viewPath = 'tests';
|
2008-05-30 11:40:08 +00:00
|
|
|
$this->Controller->action = 'index';
|
|
|
|
$this->Controller->theme = 'test_plugin_theme';
|
|
|
|
|
|
|
|
$ThemeView = new TestThemeView($this->Controller);
|
2008-08-01 16:23:16 +00:00
|
|
|
$expected = TEST_CAKE_CORE_INCLUDE_PATH . 'tests' . DS . 'test_app' . DS . 'plugins' . DS .'test_plugin' . DS . 'views' . DS . 'themed' . DS . 'test_plugin_theme' . DS .'tests' . DS .'index.ctp';
|
2008-05-30 11:40:08 +00:00
|
|
|
$result = $ThemeView->getViewFileName('index');
|
|
|
|
$this->assertEqual($result, $expected);
|
|
|
|
|
|
|
|
$expected = TEST_CAKE_CORE_INCLUDE_PATH . 'tests' . DS . 'test_app' . DS . 'plugins' . DS .'test_plugin' . DS . 'views' . DS . 'themed' . DS . 'test_plugin_theme' . DS . 'layouts' . DS .'default.ctp';
|
|
|
|
$result = $ThemeView->getLayoutFileName();
|
|
|
|
$this->assertEqual($result, $expected);
|
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-06-02 19:22:55 +00:00
|
|
|
/**
|
|
|
|
* testGetTemplate method
|
2008-06-11 15:46:31 +00:00
|
|
|
*
|
2008-06-02 19:22:55 +00:00
|
|
|
* @access public
|
|
|
|
* @return void
|
|
|
|
*/
|
2008-05-30 11:40:08 +00:00
|
|
|
function testGetTemplate() {
|
|
|
|
$this->Controller->plugin = null;
|
|
|
|
$this->Controller->name = 'Pages';
|
|
|
|
$this->Controller->viewPath = 'pages';
|
|
|
|
$this->Controller->action = 'display';
|
|
|
|
$this->Controller->params['pass'] = array('home');
|
|
|
|
|
|
|
|
$ThemeView = new TestThemeView($this->Controller);
|
|
|
|
$ThemeView->theme = 'test_theme';
|
|
|
|
$expected = TEST_CAKE_CORE_INCLUDE_PATH . 'tests' . DS . 'test_app' . DS . 'views' . DS .'pages' . DS .'home.ctp';
|
|
|
|
$result = $ThemeView->getViewFileName('home');
|
|
|
|
$this->assertEqual($result, $expected);
|
|
|
|
|
|
|
|
$expected = TEST_CAKE_CORE_INCLUDE_PATH . 'tests' . DS . 'test_app' . DS . 'views' . DS . 'themed' . DS . 'test_theme' . DS . 'posts' . DS .'index.ctp';
|
|
|
|
$result = $ThemeView->getViewFileName('/posts/index');
|
|
|
|
$this->assertEqual($result, $expected);
|
|
|
|
|
|
|
|
$expected = TEST_CAKE_CORE_INCLUDE_PATH . 'tests' . DS . 'test_app' . DS . 'views' . DS . 'themed' . DS . 'test_theme' . DS . 'layouts' . DS .'default.ctp';
|
|
|
|
$result = $ThemeView->getLayoutFileName();
|
|
|
|
$this->assertEqual($result, $expected);
|
|
|
|
|
|
|
|
$ThemeView->layoutPath = 'rss';
|
|
|
|
$expected = TEST_CAKE_CORE_INCLUDE_PATH . 'tests' . DS . 'test_app' . DS . 'views' . DS . 'layouts' . DS . 'rss' . DS . 'default.ctp';
|
|
|
|
$result = $ThemeView->getLayoutFileName();
|
|
|
|
$this->assertEqual($result, $expected);
|
|
|
|
|
|
|
|
$ThemeView->layoutPath = 'email' . DS . 'html';
|
2008-07-30 13:57:24 +00:00
|
|
|
$expected = TEST_CAKE_CORE_INCLUDE_PATH . 'tests' . DS . 'test_app' . DS . 'views' . DS . 'layouts' . DS . 'email' . DS . 'html' . DS . 'default.ctp';
|
2008-05-30 11:40:08 +00:00
|
|
|
$result = $ThemeView->getLayoutFileName();
|
|
|
|
$this->assertEqual($result, $expected);
|
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-06-05 15:20:45 +00:00
|
|
|
/**
|
|
|
|
* testMissingView method
|
2008-06-11 15:46:31 +00:00
|
|
|
*
|
2008-06-05 15:20:45 +00:00
|
|
|
* @access public
|
|
|
|
* @return void
|
|
|
|
*/
|
2008-05-30 11:40:08 +00:00
|
|
|
function testMissingView() {
|
|
|
|
$this->Controller->plugin = null;
|
|
|
|
$this->Controller->name = 'Pages';
|
|
|
|
$this->Controller->viewPath = 'pages';
|
|
|
|
$this->Controller->action = 'display';
|
|
|
|
$this->Controller->theme = 'my_theme';
|
|
|
|
|
|
|
|
$this->Controller->params['pass'] = array('home');
|
|
|
|
|
|
|
|
restore_error_handler();
|
|
|
|
$View = new TestThemeView($this->Controller);
|
|
|
|
ob_start();
|
|
|
|
$result = $View->getViewFileName('does_not_exist');
|
|
|
|
$expected = str_replace(array("\t", "\r\n", "\n"), "", ob_get_clean());
|
|
|
|
set_error_handler('simpleTestErrorHandler');
|
|
|
|
$this->assertPattern("/PagesController::/", $expected);
|
2008-06-20 19:30:29 +00:00
|
|
|
$this->assertPattern("/views(\/|\\\)themed(\/|\\\)my_theme(\/|\\\)pages(\/|\\\)does_not_exist.ctp/", $expected);
|
2008-05-30 11:40:08 +00:00
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-06-05 15:20:45 +00:00
|
|
|
/**
|
|
|
|
* testMissingLayout method
|
2008-06-11 15:46:31 +00:00
|
|
|
*
|
2008-06-05 15:20:45 +00:00
|
|
|
* @access public
|
|
|
|
* @return void
|
|
|
|
*/
|
2008-05-30 11:40:08 +00:00
|
|
|
function testMissingLayout() {
|
|
|
|
$this->Controller->plugin = null;
|
|
|
|
$this->Controller->name = 'Posts';
|
|
|
|
$this->Controller->viewPath = 'posts';
|
|
|
|
$this->Controller->layout = 'whatever';
|
|
|
|
$this->Controller->theme = 'my_theme';
|
|
|
|
|
|
|
|
restore_error_handler();
|
|
|
|
$View = new TestThemeView($this->Controller);
|
|
|
|
ob_start();
|
|
|
|
$result = $View->getLayoutFileName();
|
|
|
|
$expected = str_replace(array("\t", "\r\n", "\n"), "", ob_get_clean());
|
|
|
|
set_error_handler('simpleTestErrorHandler');
|
|
|
|
$this->assertPattern("/Missing Layout/", $expected);
|
2008-06-20 19:30:29 +00:00
|
|
|
$this->assertPattern("/views(\/|\\\)themed(\/|\\\)my_theme(\/|\\\)layouts(\/|\\\)whatever.ctp/", $expected);
|
2008-05-30 11:40:08 +00:00
|
|
|
}
|
|
|
|
}
|
2008-06-27 08:17:02 +00:00
|
|
|
?>
|