2008-05-30 11:40:08 +00:00
|
|
|
<?php
|
|
|
|
/**
|
2009-03-19 21:10:13 +00:00
|
|
|
* ThemeViewTest file
|
2008-05-30 11:40:08 +00:00
|
|
|
*
|
2010-10-03 16:31:21 +00:00
|
|
|
* PHP 5
|
2008-05-30 11:40:08 +00:00
|
|
|
*
|
2012-04-27 02:49:18 +00:00
|
|
|
* CakePHP(tm) Tests <http://book.cakephp.org/2.0/en/development/testing.html>
|
2012-03-13 02:46:07 +00:00
|
|
|
* Copyright 2005-2012, Cake Software Foundation, Inc. (http://cakefoundation.org)
|
2008-05-30 11:40:08 +00:00
|
|
|
*
|
2010-10-03 16:31:21 +00:00
|
|
|
* Licensed under The MIT License
|
|
|
|
* Redistributions of files must retain the above copyright notice
|
2008-05-30 11:40:08 +00:00
|
|
|
*
|
2012-03-13 02:46:07 +00:00
|
|
|
* @copyright Copyright 2005-2012, Cake Software Foundation, Inc. (http://cakefoundation.org)
|
2012-04-27 02:49:18 +00:00
|
|
|
* @link http://book.cakephp.org/2.0/en/development/testing.html CakePHP(tm) Tests
|
2011-07-26 06:16:14 +00:00
|
|
|
* @package Cake.Test.Case.View
|
2008-10-30 17:30:26 +00:00
|
|
|
* @since CakePHP(tm) v 1.2.0.4206
|
2010-10-03 16:27:27 +00:00
|
|
|
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
|
2008-05-30 11:40:08 +00:00
|
|
|
*/
|
2010-12-10 06:23:27 +00:00
|
|
|
App::uses('View', 'View');
|
|
|
|
App::uses('ThemeView', 'View');
|
2010-12-09 05:55:24 +00:00
|
|
|
App::uses('Controller', 'Controller');
|
2009-03-19 21:10:13 +00:00
|
|
|
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-06-02 19:22:55 +00:00
|
|
|
/**
|
2012-01-22 21:16:41 +00:00
|
|
|
* ThemePosts2Controller class
|
2008-06-11 15:46:31 +00:00
|
|
|
*
|
2011-07-26 06:16:14 +00:00
|
|
|
* @package Cake.Test.Case.View
|
2008-06-02 19:22:55 +00:00
|
|
|
*/
|
2012-01-22 21:16:41 +00:00
|
|
|
class ThemePosts2Controller 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'
|
|
|
|
*/
|
2010-04-04 07:14:00 +00:00
|
|
|
public $name = 'ThemePosts';
|
2011-04-17 10:35:21 +00:00
|
|
|
|
2010-09-15 03:13:00 +00:00
|
|
|
public $theme = null;
|
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
|
|
|
* @return void
|
|
|
|
*/
|
2011-05-30 20:02:32 +00:00
|
|
|
public function index() {
|
2008-05-30 11:40:08 +00:00
|
|
|
$this->set('testData', 'Some test data');
|
|
|
|
$test2 = 'more data';
|
|
|
|
$test3 = 'even more data';
|
|
|
|
$this->set(compact('test2', 'test3'));
|
|
|
|
}
|
2012-03-16 02:50:05 +00:00
|
|
|
|
2008-05-30 11:40:08 +00:00
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-06-02 19:22:55 +00:00
|
|
|
/**
|
2012-01-22 21:16:41 +00:00
|
|
|
* TestTheme2View class
|
2008-06-11 15:46:31 +00:00
|
|
|
*
|
2011-07-26 06:16:14 +00:00
|
|
|
* @package Cake.Test.Case.View
|
2008-06-02 19:22:55 +00:00
|
|
|
*/
|
2012-01-22 21:16:41 +00:00
|
|
|
class TestTheme2View 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
|
|
|
* @return void
|
|
|
|
*/
|
2011-05-30 20:02:32 +00:00
|
|
|
public function renderElement($name, $params = array()) {
|
2008-05-30 11:40:08 +00:00
|
|
|
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
|
|
|
* @return void
|
|
|
|
*/
|
2011-05-30 20:02:32 +00:00
|
|
|
public function getViewFileName($name = null) {
|
2008-05-30 11:40:08 +00:00
|
|
|
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
|
|
|
* @return void
|
|
|
|
*/
|
2011-05-30 20:02:32 +00:00
|
|
|
public function getLayoutFileName($name = null) {
|
2008-05-30 11:40:08 +00:00
|
|
|
return $this->_getLayoutFileName($name);
|
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-05-30 11:40:08 +00:00
|
|
|
}
|
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
|
|
|
*
|
2011-07-26 06:16:14 +00:00
|
|
|
* @package Cake.Test.Case.View
|
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
|
|
|
* @return void
|
|
|
|
*/
|
2011-05-30 20:02:32 +00:00
|
|
|
public function setUp() {
|
2011-08-31 23:38:08 +00:00
|
|
|
parent::setUp();
|
2010-09-15 03:13:00 +00:00
|
|
|
$request = new CakeRequest('posts/index');
|
|
|
|
$this->Controller = new Controller($request);
|
2012-01-22 21:16:41 +00:00
|
|
|
$this->PostsController = new ThemePosts2Controller($request);
|
2008-05-30 11:40:08 +00:00
|
|
|
$this->PostsController->viewPath = 'posts';
|
|
|
|
$this->PostsController->index();
|
2010-06-01 02:47:45 +00:00
|
|
|
$this->ThemeView = new ThemeView($this->PostsController);
|
|
|
|
App::build(array(
|
2012-02-18 12:31:29 +00:00
|
|
|
'Plugin' => array(CAKE . 'Test' . DS . 'test_app' . DS . 'Plugin' . DS),
|
2012-03-16 02:50:05 +00:00
|
|
|
'View' => array(CAKE . 'Test' . DS . 'test_app' . DS . 'View' . DS)
|
2010-06-01 02:47:45 +00:00
|
|
|
));
|
2011-08-31 23:38:08 +00:00
|
|
|
App::objects('plugins', null, false);
|
2012-02-17 03:59:24 +00:00
|
|
|
CakePlugin::load(array('TestPlugin'));
|
2008-05-30 11:40:08 +00:00
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2009-03-19 21:10:13 +00:00
|
|
|
/**
|
|
|
|
* tearDown method
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
2011-05-30 20:02:32 +00:00
|
|
|
public function tearDown() {
|
2011-08-31 23:38:08 +00:00
|
|
|
parent::tearDown();
|
2009-03-19 21:10:13 +00:00
|
|
|
unset($this->ThemeView);
|
|
|
|
unset($this->PostsController);
|
|
|
|
unset($this->Controller);
|
2011-05-06 05:53:01 +00:00
|
|
|
CakePlugin::unload();
|
2009-11-30 14:19:25 +00:00
|
|
|
}
|
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
|
|
|
* @return void
|
|
|
|
*/
|
2011-05-30 20:02:32 +00:00
|
|
|
public function testPluginThemedGetTemplate() {
|
2011-05-06 05:53:01 +00:00
|
|
|
$this->Controller->plugin = 'TestPlugin';
|
2008-05-30 11:40:08 +00:00
|
|
|
$this->Controller->name = 'TestPlugin';
|
2011-05-13 07:49:00 +00:00
|
|
|
$this->Controller->viewPath = 'Tests';
|
2008-05-30 11:40:08 +00:00
|
|
|
$this->Controller->action = 'index';
|
2011-05-15 04:38:01 +00:00
|
|
|
$this->Controller->theme = 'TestTheme';
|
2008-05-30 11:40:08 +00:00
|
|
|
|
2012-01-22 21:16:41 +00:00
|
|
|
$ThemeView = new TestTheme2View($this->Controller);
|
2012-03-16 02:50:05 +00:00
|
|
|
$expected = CAKE . 'Test' . DS . 'test_app' . DS . 'View' . DS . 'Themed' . DS . 'TestTheme' . DS . 'Plugin' . DS . 'TestPlugin' . DS . 'Tests' . DS . 'index.ctp';
|
2008-05-30 11:40:08 +00:00
|
|
|
$result = $ThemeView->getViewFileName('index');
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertEquals($expected, $result);
|
2008-05-30 11:40:08 +00:00
|
|
|
|
2012-03-16 02:50:05 +00:00
|
|
|
$expected = CAKE . 'Test' . DS . 'test_app' . DS . 'View' . DS . 'Themed' . DS . 'TestTheme' . DS . 'Plugin' . DS . 'TestPlugin' . DS . 'Layouts' . DS . 'plugin_default.ctp';
|
2009-11-26 20:52:38 +00:00
|
|
|
$result = $ThemeView->getLayoutFileName('plugin_default');
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertEquals($expected, $result);
|
2010-02-12 03:57:24 +00:00
|
|
|
|
2012-03-16 02:50:05 +00:00
|
|
|
$expected = CAKE . 'Test' . DS . 'test_app' . DS . 'View' . DS . 'Themed' . DS . 'TestTheme' . DS . 'Layouts' . DS . 'default.ctp';
|
2009-11-26 20:52:38 +00:00
|
|
|
$result = $ThemeView->getLayoutFileName('default');
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertEquals($expected, $result);
|
2008-05-30 11:40:08 +00:00
|
|
|
}
|
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
|
|
|
* @return void
|
|
|
|
*/
|
2011-05-30 20:02:32 +00:00
|
|
|
public function testGetTemplate() {
|
2008-05-30 11:40:08 +00:00
|
|
|
$this->Controller->plugin = null;
|
|
|
|
$this->Controller->name = 'Pages';
|
2011-05-13 07:49:00 +00:00
|
|
|
$this->Controller->viewPath = 'Pages';
|
2008-05-30 11:40:08 +00:00
|
|
|
$this->Controller->action = 'display';
|
|
|
|
$this->Controller->params['pass'] = array('home');
|
|
|
|
|
2012-01-22 21:16:41 +00:00
|
|
|
$ThemeView = new TestTheme2View($this->Controller);
|
2011-05-15 04:38:01 +00:00
|
|
|
$ThemeView->theme = 'TestTheme';
|
2012-03-16 02:50:05 +00:00
|
|
|
$expected = CAKE . 'Test' . DS . 'test_app' . DS . 'View' . DS . 'Pages' . DS . 'home.ctp';
|
2008-05-30 11:40:08 +00:00
|
|
|
$result = $ThemeView->getViewFileName('home');
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertEquals($expected, $result);
|
2008-05-30 11:40:08 +00:00
|
|
|
|
2012-03-16 02:50:05 +00:00
|
|
|
$expected = CAKE . 'Test' . DS . 'test_app' . DS . 'View' . DS . 'Themed' . DS . 'TestTheme' . DS . 'Posts' . DS . 'index.ctp';
|
2011-05-13 07:49:00 +00:00
|
|
|
$result = $ThemeView->getViewFileName('/Posts/index');
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertEquals($expected, $result);
|
2008-05-30 11:40:08 +00:00
|
|
|
|
2012-03-16 02:50:05 +00:00
|
|
|
$expected = CAKE . 'Test' . DS . 'test_app' . DS . 'View' . DS . 'Themed' . DS . 'TestTheme' . DS . 'Layouts' . DS . 'default.ctp';
|
2008-05-30 11:40:08 +00:00
|
|
|
$result = $ThemeView->getLayoutFileName();
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertEquals($expected, $result);
|
2008-05-30 11:40:08 +00:00
|
|
|
|
|
|
|
$ThemeView->layoutPath = 'rss';
|
2011-04-17 10:35:21 +00:00
|
|
|
$expected = CAKE . 'Test' . DS . 'test_app' . DS . 'View' . DS . 'Layouts' . DS . 'rss' . DS . 'default.ctp';
|
2008-05-30 11:40:08 +00:00
|
|
|
$result = $ThemeView->getLayoutFileName();
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertEquals($expected, $result);
|
2008-05-30 11:40:08 +00:00
|
|
|
|
2011-05-16 22:23:58 +00:00
|
|
|
$ThemeView->layoutPath = 'Emails' . DS . 'html';
|
|
|
|
$expected = CAKE . 'Test' . DS . 'test_app' . DS . 'View' . DS . 'Layouts' . DS . 'Emails' . DS . 'html' . DS . 'default.ctp';
|
2008-05-30 11:40:08 +00:00
|
|
|
$result = $ThemeView->getLayoutFileName();
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertEquals($expected, $result);
|
2008-05-30 11:40:08 +00:00
|
|
|
}
|
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
|
|
|
*
|
2010-07-15 03:16:05 +00:00
|
|
|
* @expectedException MissingViewException
|
2008-06-05 15:20:45 +00:00
|
|
|
* @return void
|
|
|
|
*/
|
2011-05-30 20:02:32 +00:00
|
|
|
public function testMissingView() {
|
2008-05-30 11:40:08 +00:00
|
|
|
$this->Controller->plugin = null;
|
|
|
|
$this->Controller->name = 'Pages';
|
2011-05-13 07:49:00 +00:00
|
|
|
$this->Controller->viewPath = 'Pages';
|
2008-05-30 11:40:08 +00:00
|
|
|
$this->Controller->action = 'display';
|
|
|
|
$this->Controller->theme = 'my_theme';
|
|
|
|
|
|
|
|
$this->Controller->params['pass'] = array('home');
|
|
|
|
|
2012-01-22 21:16:41 +00:00
|
|
|
$View = new TestTheme2View($this->Controller);
|
2008-05-30 11:40:08 +00:00
|
|
|
ob_start();
|
|
|
|
$result = $View->getViewFileName('does_not_exist');
|
2012-02-17 02:51:56 +00:00
|
|
|
$expected = ob_get_clean();
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertRegExp("/PagesController::/", $expected);
|
|
|
|
$this->assertRegExp("/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
|
2010-07-15 03:16:05 +00:00
|
|
|
*
|
|
|
|
* @expectedException MissingLayoutException
|
2008-06-05 15:20:45 +00:00
|
|
|
* @return void
|
|
|
|
*/
|
2011-05-30 20:02:32 +00:00
|
|
|
public function testMissingLayout() {
|
2008-05-30 11:40:08 +00:00
|
|
|
$this->Controller->plugin = null;
|
|
|
|
$this->Controller->name = 'Posts';
|
|
|
|
$this->Controller->viewPath = 'posts';
|
|
|
|
$this->Controller->layout = 'whatever';
|
|
|
|
$this->Controller->theme = 'my_theme';
|
|
|
|
|
2012-01-22 21:16:41 +00:00
|
|
|
$View = new TestTheme2View($this->Controller);
|
2008-05-30 11:40:08 +00:00
|
|
|
ob_start();
|
|
|
|
$result = $View->getLayoutFileName();
|
2012-02-17 02:51:56 +00:00
|
|
|
$expected = ob_get_clean();
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertRegExp("/Missing Layout/", $expected);
|
|
|
|
$this->assertRegExp("/views(\/|\\\)themed(\/|\\\)my_theme(\/|\\\)layouts(\/|\\\)whatever.ctp/", $expected);
|
2008-05-30 11:40:08 +00:00
|
|
|
}
|
2010-02-12 03:57:24 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* test memory leaks that existed in _paths at one point.
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
2011-05-30 20:02:32 +00:00
|
|
|
public function testMemoryLeakInPaths() {
|
2010-02-12 03:57:24 +00:00
|
|
|
$this->Controller->plugin = null;
|
|
|
|
$this->Controller->name = 'Posts';
|
|
|
|
$this->Controller->viewPath = 'posts';
|
|
|
|
$this->Controller->layout = 'whatever';
|
2011-05-15 04:38:01 +00:00
|
|
|
$this->Controller->theme = 'TestTheme';
|
2010-02-12 03:57:24 +00:00
|
|
|
|
2010-06-01 02:47:45 +00:00
|
|
|
$View = new ThemeView($this->Controller);
|
2010-02-12 03:57:24 +00:00
|
|
|
$View->element('test_element');
|
|
|
|
|
|
|
|
$start = memory_get_usage();
|
|
|
|
for ($i = 0; $i < 10; $i++) {
|
|
|
|
$View->element('test_element');
|
|
|
|
}
|
|
|
|
$end = memory_get_usage();
|
2011-10-05 17:55:54 +00:00
|
|
|
$this->assertLessThanOrEqual($start + 5000, $end);
|
2010-02-12 03:57:24 +00:00
|
|
|
}
|
2008-05-30 11:40:08 +00:00
|
|
|
}
|