123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265 |
- <?php
- /**
- * ThemeViewTest file
- *
- * PHP 5
- *
- * CakePHP(tm) Tests <http://book.cakephp.org/2.0/en/development/testing.html>
- * Copyright 2005-2012, Cake Software Foundation, Inc. (http://cakefoundation.org)
- *
- * Licensed under The MIT License
- * Redistributions of files must retain the above copyright notice
- *
- * @copyright Copyright 2005-2012, Cake Software Foundation, Inc. (http://cakefoundation.org)
- * @link http://book.cakephp.org/2.0/en/development/testing.html CakePHP(tm) Tests
- * @package Cake.Test.Case.View
- * @since CakePHP(tm) v 1.2.0.4206
- * @license MIT License (http://www.opensource.org/licenses/mit-license.php)
- */
- App::uses('View', 'View');
- App::uses('ThemeView', 'View');
- App::uses('Controller', 'Controller');
- /**
- * ThemePosts2Controller class
- *
- * @package Cake.Test.Case.View
- */
- class ThemePosts2Controller extends Controller {
- /**
- * name property
- *
- * @var string 'ThemePosts'
- */
- public $name = 'ThemePosts';
- public $theme = null;
- /**
- * index method
- *
- * @return void
- */
- public function index() {
- $this->set(array(
- 'testData' => 'Some test data',
- 'test2' => 'more data',
- 'test3' => 'even more data',
- ));
- }
- }
- /**
- * TestTheme2View class
- *
- * @package Cake.Test.Case.View
- */
- class TestTheme2View extends ThemeView {
- /**
- * renderElement method
- *
- * @param string $name
- * @param array $params
- * @return void
- */
- public function renderElement($name, $params = array()) {
- return $name;
- }
- /**
- * getViewFileName method
- *
- * @param string $name
- * @return void
- */
- public function getViewFileName($name = null) {
- return $this->_getViewFileName($name);
- }
- /**
- * getLayoutFileName method
- *
- * @param string $name
- * @return void
- */
- public function getLayoutFileName($name = null) {
- return $this->_getLayoutFileName($name);
- }
- }
- /**
- * ThemeViewTest class
- *
- * @package Cake.Test.Case.View
- */
- class ThemeViewTest extends CakeTestCase {
- /**
- * setUp method
- *
- * @return void
- */
- public function setUp() {
- parent::setUp();
- $request = new CakeRequest('posts/index');
- $this->Controller = new Controller($request);
- $this->PostsController = new ThemePosts2Controller($request);
- $this->PostsController->viewPath = 'posts';
- $this->PostsController->index();
- $this->ThemeView = new ThemeView($this->PostsController);
- App::build(array(
- 'Plugin' => array(CAKE . 'Test' . DS . 'test_app' . DS . 'Plugin' . DS),
- 'View' => array(CAKE . 'Test' . DS . 'test_app' . DS . 'View' . DS)
- ));
- App::objects('plugins', null, false);
- CakePlugin::load(array('TestPlugin'));
- }
- /**
- * tearDown method
- *
- * @return void
- */
- public function tearDown() {
- parent::tearDown();
- unset($this->ThemeView);
- unset($this->PostsController);
- unset($this->Controller);
- CakePlugin::unload();
- }
- /**
- * testPluginGetTemplate method
- *
- * @return void
- */
- public function testPluginThemedGetTemplate() {
- $this->Controller->plugin = 'TestPlugin';
- $this->Controller->name = 'TestPlugin';
- $this->Controller->viewPath = 'Tests';
- $this->Controller->action = 'index';
- $this->Controller->theme = 'TestTheme';
- $ThemeView = new TestTheme2View($this->Controller);
- $expected = CAKE . 'Test' . DS . 'test_app' . DS . 'View' . DS . 'Themed' . DS . 'TestTheme' . DS . 'Plugin' . DS . 'TestPlugin' . DS . 'Tests' . DS . 'index.ctp';
- $result = $ThemeView->getViewFileName('index');
- $this->assertEquals($expected, $result);
- $expected = CAKE . 'Test' . DS . 'test_app' . DS . 'View' . DS . 'Themed' . DS . 'TestTheme' . DS . 'Plugin' . DS . 'TestPlugin' . DS . 'Layouts' . DS . 'plugin_default.ctp';
- $result = $ThemeView->getLayoutFileName('plugin_default');
- $this->assertEquals($expected, $result);
- $expected = CAKE . 'Test' . DS . 'test_app' . DS . 'View' . DS . 'Themed' . DS . 'TestTheme' . DS . 'Layouts' . DS . 'default.ctp';
- $result = $ThemeView->getLayoutFileName('default');
- $this->assertEquals($expected, $result);
- }
- /**
- * testGetTemplate method
- *
- * @return void
- */
- public 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 TestTheme2View($this->Controller);
- $ThemeView->theme = 'TestTheme';
- $expected = CAKE . 'Test' . DS . 'test_app' . DS . 'View' . DS . 'Pages' . DS . 'home.ctp';
- $result = $ThemeView->getViewFileName('home');
- $this->assertEquals($expected, $result);
- $expected = CAKE . 'Test' . DS . 'test_app' . DS . 'View' . DS . 'Themed' . DS . 'TestTheme' . DS . 'Posts' . DS . 'index.ctp';
- $result = $ThemeView->getViewFileName('/Posts/index');
- $this->assertEquals($expected, $result);
- $expected = CAKE . 'Test' . DS . 'test_app' . DS . 'View' . DS . 'Themed' . DS . 'TestTheme' . DS . 'Layouts' . DS . 'default.ctp';
- $result = $ThemeView->getLayoutFileName();
- $this->assertEquals($expected, $result);
- $ThemeView->layoutPath = 'rss';
- $expected = CAKE . 'Test' . DS . 'test_app' . DS . 'View' . DS . 'Layouts' . DS . 'rss' . DS . 'default.ctp';
- $result = $ThemeView->getLayoutFileName();
- $this->assertEquals($expected, $result);
- $ThemeView->layoutPath = 'Emails' . DS . 'html';
- $expected = CAKE . 'Test' . DS . 'test_app' . DS . 'View' . DS . 'Layouts' . DS . 'Emails' . DS . 'html' . DS . 'default.ctp';
- $result = $ThemeView->getLayoutFileName();
- $this->assertEquals($expected, $result);
- }
- /**
- * testMissingView method
- *
- * @expectedException MissingViewException
- * @return void
- */
- public 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');
- $View = new TestTheme2View($this->Controller);
- ob_start();
- $View->getViewFileName('does_not_exist');
- $expected = ob_get_clean();
- $this->assertRegExp("/PagesController::/", $expected);
- $this->assertRegExp("/views(\/|\\\)themed(\/|\\\)my_theme(\/|\\\)pages(\/|\\\)does_not_exist.ctp/", $expected);
- }
- /**
- * testMissingLayout method
- *
- * @expectedException MissingLayoutException
- * @return void
- */
- public function testMissingLayout() {
- $this->Controller->plugin = null;
- $this->Controller->name = 'Posts';
- $this->Controller->viewPath = 'posts';
- $this->Controller->layout = 'whatever';
- $this->Controller->theme = 'my_theme';
- $View = new TestTheme2View($this->Controller);
- ob_start();
- $View->getLayoutFileName();
- $expected = ob_get_clean();
- $this->assertRegExp("/Missing Layout/", $expected);
- $this->assertRegExp("/views(\/|\\\)themed(\/|\\\)my_theme(\/|\\\)layouts(\/|\\\)whatever.ctp/", $expected);
- }
- /**
- * test memory leaks that existed in _paths at one point.
- *
- * @return void
- */
- public function testMemoryLeakInPaths() {
- $this->Controller->plugin = null;
- $this->Controller->name = 'Posts';
- $this->Controller->viewPath = 'posts';
- $this->Controller->layout = 'whatever';
- $this->Controller->theme = 'TestTheme';
- $View = new ThemeView($this->Controller);
- $View->element('test_element');
- $start = memory_get_usage();
- for ($i = 0; $i < 10; $i++) {
- $View->element('test_element');
- }
- $end = memory_get_usage();
- $this->assertLessThanOrEqual($start + 5000, $end);
- }
- }
|