2008-05-30 11:40:08 +00:00
|
|
|
<?php
|
|
|
|
/**
|
2009-03-19 21:10:13 +00:00
|
|
|
* ViewTest file
|
2008-05-30 11:40:08 +00:00
|
|
|
*
|
2017-06-10 22:15:34 +00:00
|
|
|
* CakePHP(tm) Tests <https://book.cakephp.org/2.0/en/development/testing.html>
|
2017-06-10 22:10:52 +00:00
|
|
|
* Copyright (c) Cake Software Foundation, Inc. (https://cakefoundation.org)
|
2008-05-30 11:40:08 +00:00
|
|
|
*
|
2010-10-03 16:31:21 +00:00
|
|
|
* Licensed under The MIT License
|
2013-02-08 12:22:51 +00:00
|
|
|
* For full copyright and license information, please see the LICENSE.txt
|
2010-10-03 16:31:21 +00:00
|
|
|
* Redistributions of files must retain the above copyright notice
|
2008-05-30 11:40:08 +00:00
|
|
|
*
|
2017-06-10 22:10:52 +00:00
|
|
|
* @copyright Copyright (c) Cake Software Foundation, Inc. (https://cakefoundation.org)
|
2017-06-10 22:15:34 +00:00
|
|
|
* @link https://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
|
2017-06-10 22:23:14 +00:00
|
|
|
* @license https://opensource.org/licenses/mit-license.php MIT License
|
2008-05-30 11:40:08 +00:00
|
|
|
*/
|
2010-12-10 06:23:27 +00:00
|
|
|
|
|
|
|
App::uses('View', 'View');
|
2010-12-11 05:47:55 +00:00
|
|
|
App::uses('Helper', 'View');
|
2010-12-10 06:23:27 +00:00
|
|
|
App::uses('Controller', 'Controller');
|
|
|
|
App::uses('CacheHelper', 'View/Helper');
|
2012-10-01 02:51:19 +00:00
|
|
|
App::uses('HtmlHelper', 'View/Helper');
|
2010-12-10 06:23:27 +00:00
|
|
|
App::uses('ErrorHandler', 'Error');
|
2014-06-26 03:08:59 +00:00
|
|
|
App::uses('CakeEventManager', 'Event');
|
|
|
|
App::uses('CakeEventListener', 'Event');
|
2009-09-15 03:49:20 +00:00
|
|
|
|
2008-06-02 19:22:55 +00:00
|
|
|
/**
|
|
|
|
* ViewPostsController class
|
2008-06-08 15:44:46 +00:00
|
|
|
*
|
2011-07-26 06:16:14 +00:00
|
|
|
* @package Cake.Test.Case.View
|
2008-06-02 19:22:55 +00:00
|
|
|
*/
|
2008-05-30 11:40:08 +00:00
|
|
|
class ViewPostsController extends Controller {
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-06-02 19:22:55 +00:00
|
|
|
/**
|
|
|
|
* name property
|
2008-06-08 15:44:46 +00:00
|
|
|
*
|
2013-06-08 02:29:08 +00:00
|
|
|
* @var string
|
2008-06-02 19:22:55 +00:00
|
|
|
*/
|
2010-04-04 07:14:00 +00:00
|
|
|
public $name = 'Posts';
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-06-02 19:22:55 +00:00
|
|
|
/**
|
|
|
|
* uses property
|
2008-06-08 15:44:46 +00:00
|
|
|
*
|
2014-07-03 13:36:42 +00:00
|
|
|
* @var mixed
|
2008-06-02 19:22:55 +00:00
|
|
|
*/
|
2010-04-04 07:14:00 +00:00
|
|
|
public $uses = null;
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-06-02 19:22:55 +00:00
|
|
|
/**
|
|
|
|
* index method
|
2008-06-08 15:44:46 +00:00
|
|
|
*
|
2008-06-02 19:22:55 +00:00
|
|
|
* @return void
|
|
|
|
*/
|
2011-05-30 20:02:32 +00:00
|
|
|
public function index() {
|
2012-04-07 02:34:16 +00:00
|
|
|
$this->set(array(
|
|
|
|
'testData' => 'Some test data',
|
|
|
|
'test2' => 'more data',
|
|
|
|
'test3' => 'even more data',
|
|
|
|
));
|
2008-05-30 11:40:08 +00:00
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-06-26 05:26:10 +00:00
|
|
|
/**
|
|
|
|
* nocache_tags_with_element method
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
2011-05-30 20:02:32 +00:00
|
|
|
public function nocache_multiple_element() {
|
2008-06-26 05:26:10 +00:00
|
|
|
$this->set('foo', 'this is foo var');
|
|
|
|
$this->set('bar', 'this is bar var');
|
|
|
|
}
|
2012-03-16 02:50:05 +00:00
|
|
|
|
2008-05-30 11:40:08 +00:00
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2012-01-22 20:45:26 +00:00
|
|
|
/**
|
|
|
|
* ThemePostsController class
|
|
|
|
*
|
|
|
|
* @package Cake.Test.Case.View
|
|
|
|
*/
|
|
|
|
class ThemePostsController extends Controller {
|
|
|
|
|
|
|
|
public $theme = null;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* index method
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function index() {
|
|
|
|
$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
|
|
|
|
2012-01-22 20:45:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* TestThemeView class
|
|
|
|
*
|
|
|
|
* @package Cake.Test.Case.View
|
|
|
|
*/
|
|
|
|
class TestThemeView extends View {
|
|
|
|
|
|
|
|
/**
|
|
|
|
* renderElement method
|
|
|
|
*
|
2012-05-13 00:43:31 +00:00
|
|
|
* @param string $name
|
2012-01-22 20:45:26 +00:00
|
|
|
* @param array $params
|
2013-07-19 23:06:27 +00:00
|
|
|
* @return string The given name
|
2012-01-22 20:45:26 +00:00
|
|
|
*/
|
|
|
|
public function renderElement($name, $params = array()) {
|
|
|
|
return $name;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* getViewFileName method
|
|
|
|
*
|
2013-07-19 23:06:27 +00:00
|
|
|
* @param string $name Controller action to find template filename for
|
|
|
|
* @return string Template filename
|
2012-01-22 20:45:26 +00:00
|
|
|
*/
|
|
|
|
public function getViewFileName($name = null) {
|
|
|
|
return $this->_getViewFileName($name);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* getLayoutFileName method
|
|
|
|
*
|
2013-07-19 23:06:27 +00:00
|
|
|
* @param string $name The name of the layout to find.
|
|
|
|
* @return string Filename for layout file (.ctp).
|
2012-01-22 20:45:26 +00:00
|
|
|
*/
|
|
|
|
public function getLayoutFileName($name = null) {
|
|
|
|
return $this->_getLayoutFileName($name);
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2008-06-02 19:22:55 +00:00
|
|
|
/**
|
|
|
|
* TestView class
|
2008-06-08 15:44:46 +00:00
|
|
|
*
|
2011-07-26 06:16:14 +00:00
|
|
|
* @package Cake.Test.Case.View
|
2008-06-02 19:22:55 +00:00
|
|
|
*/
|
2008-05-30 11:40:08 +00:00
|
|
|
class TestView extends View {
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-06-02 19:22:55 +00:00
|
|
|
/**
|
|
|
|
* getViewFileName method
|
2008-06-08 15:44:46 +00:00
|
|
|
*
|
2013-07-19 23:06:27 +00:00
|
|
|
* @param string $name Controller action to find template filename for
|
|
|
|
* @return string Template filename
|
2008-06-02 19:22:55 +00:00
|
|
|
*/
|
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-08 15:44:46 +00:00
|
|
|
*
|
2013-07-19 23:06:27 +00:00
|
|
|
* @param string $name The name of the layout to find.
|
|
|
|
* @return string Filename for layout file (.ctp).
|
2008-06-02 19:22:55 +00:00
|
|
|
*/
|
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
|
|
|
|
2009-08-24 02:43:51 +00:00
|
|
|
/**
|
|
|
|
* paths method
|
|
|
|
*
|
2013-07-19 23:06:27 +00:00
|
|
|
* @param string $plugin Optional plugin name to scan for view files.
|
2014-07-03 13:36:42 +00:00
|
|
|
* @param bool $cached Set to true to force a refresh of view paths.
|
2013-07-19 23:06:27 +00:00
|
|
|
* @return array paths
|
2009-08-24 02:43:51 +00:00
|
|
|
*/
|
2011-05-30 20:02:32 +00:00
|
|
|
public function paths($plugin = null, $cached = true) {
|
2009-08-24 02:43:51 +00:00
|
|
|
return $this->_paths($plugin, $cached);
|
|
|
|
}
|
|
|
|
|
2010-04-05 11:15:17 +00:00
|
|
|
/**
|
|
|
|
* Test only function to return instance scripts.
|
|
|
|
*
|
|
|
|
* @return array Scripts
|
|
|
|
*/
|
2011-05-30 20:02:32 +00:00
|
|
|
public function scripts() {
|
2010-04-05 11:15:17 +00:00
|
|
|
return $this->_scripts;
|
|
|
|
}
|
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
|
|
|
/**
|
2013-09-12 22:09:31 +00:00
|
|
|
* TestBeforeAfterHelper class
|
2008-06-08 15:44:46 +00:00
|
|
|
*
|
2011-07-26 06:16:14 +00:00
|
|
|
* @package Cake.Test.Case.View
|
2008-06-02 19:22:55 +00:00
|
|
|
*/
|
2013-09-12 22:09:31 +00:00
|
|
|
class TestBeforeAfterHelper extends Helper {
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-06-02 19:22:55 +00:00
|
|
|
/**
|
|
|
|
* property property
|
2008-06-08 15:44:46 +00:00
|
|
|
*
|
2013-06-08 02:29:08 +00:00
|
|
|
* @var string
|
2008-06-02 19:22:55 +00:00
|
|
|
*/
|
2010-04-04 07:14:00 +00:00
|
|
|
public $property = '';
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-06-02 19:22:55 +00:00
|
|
|
/**
|
|
|
|
* beforeLayout method
|
2008-06-08 15:44:46 +00:00
|
|
|
*
|
2013-07-19 23:06:27 +00:00
|
|
|
* @param string $viewFile
|
2008-06-02 19:22:55 +00:00
|
|
|
* @return void
|
|
|
|
*/
|
2011-05-30 20:02:32 +00:00
|
|
|
public function beforeLayout($viewFile) {
|
2008-05-30 11:40:08 +00:00
|
|
|
$this->property = 'Valuation';
|
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-06-02 19:22:55 +00:00
|
|
|
/**
|
|
|
|
* afterLayout method
|
2008-06-08 15:44:46 +00:00
|
|
|
*
|
2013-07-19 23:06:27 +00:00
|
|
|
* @param string $layoutFile
|
2008-06-02 19:22:55 +00:00
|
|
|
* @return void
|
|
|
|
*/
|
2011-05-30 20:02:32 +00:00
|
|
|
public function afterLayout($layoutFile) {
|
2010-11-11 04:40:56 +00:00
|
|
|
$this->_View->output .= 'modified in the afterlife';
|
2008-05-30 11:40:08 +00:00
|
|
|
}
|
2012-03-16 02:50:05 +00:00
|
|
|
|
2008-05-30 11:40:08 +00:00
|
|
|
}
|
2009-09-15 03:49:20 +00:00
|
|
|
|
2013-07-27 04:51:30 +00:00
|
|
|
/**
|
2016-08-10 10:22:09 +00:00
|
|
|
* TestObjectWithToString
|
2013-07-27 04:51:30 +00:00
|
|
|
*
|
|
|
|
* An object with the magic method __toString() for testing with view blocks.
|
|
|
|
*/
|
|
|
|
class TestObjectWithToString {
|
|
|
|
|
|
|
|
public function __toString() {
|
|
|
|
return "I'm ObjectWithToString";
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2016-08-10 10:22:09 +00:00
|
|
|
* TestObjectWithoutToString
|
2013-07-27 04:51:30 +00:00
|
|
|
*
|
|
|
|
* An object without the magic method __toString() for testing with view blocks.
|
|
|
|
*/
|
|
|
|
class TestObjectWithoutToString {
|
|
|
|
}
|
2014-06-27 18:03:29 +00:00
|
|
|
|
2014-06-26 03:08:59 +00:00
|
|
|
/**
|
2016-08-10 10:22:09 +00:00
|
|
|
* TestViewEventListener
|
2014-06-26 03:08:59 +00:00
|
|
|
*
|
|
|
|
* An event listener to test cakePHP events
|
|
|
|
*/
|
2014-06-27 15:21:07 +00:00
|
|
|
class TestViewEventListener implements CakeEventListener {
|
2014-06-27 17:28:43 +00:00
|
|
|
|
2014-06-27 18:03:29 +00:00
|
|
|
/**
|
|
|
|
* type of view before rendering has occurred
|
|
|
|
*
|
|
|
|
* @var string
|
|
|
|
*/
|
2014-06-27 15:21:07 +00:00
|
|
|
public $beforeRenderViewType;
|
2014-06-27 17:28:43 +00:00
|
|
|
|
2014-06-27 18:03:29 +00:00
|
|
|
/**
|
|
|
|
* type of view after rendering has occurred
|
|
|
|
*
|
|
|
|
* @var string
|
|
|
|
*/
|
2014-06-27 15:21:07 +00:00
|
|
|
public $afterRenderViewType;
|
2014-06-27 17:28:43 +00:00
|
|
|
|
2014-06-27 18:03:29 +00:00
|
|
|
/**
|
|
|
|
* implementedEvents method
|
|
|
|
*
|
|
|
|
* @return array
|
|
|
|
*/
|
2014-06-26 03:08:59 +00:00
|
|
|
public function implementedEvents() {
|
|
|
|
return array(
|
2014-06-27 17:28:43 +00:00
|
|
|
'View.beforeRender' => 'beforeRender',
|
2014-06-27 18:03:29 +00:00
|
|
|
'View.afterRender' => 'afterRender'
|
|
|
|
);
|
2014-06-26 03:08:59 +00:00
|
|
|
}
|
2014-06-27 17:28:43 +00:00
|
|
|
|
2014-06-27 18:03:29 +00:00
|
|
|
/**
|
|
|
|
* beforeRender method
|
2014-07-03 17:43:55 +00:00
|
|
|
*
|
|
|
|
* @param CakeEvent $event the event being sent
|
2014-06-27 18:03:29 +00:00
|
|
|
* @return void
|
|
|
|
*/
|
2014-06-26 03:08:59 +00:00
|
|
|
public function beforeRender($event) {
|
2014-06-27 18:03:29 +00:00
|
|
|
$this->beforeRenderViewType = $event->subject()->getCurrentType();
|
2014-06-26 03:08:59 +00:00
|
|
|
}
|
2014-06-27 17:28:43 +00:00
|
|
|
|
2014-06-27 18:03:29 +00:00
|
|
|
/**
|
|
|
|
* afterRender method
|
|
|
|
*
|
2014-07-03 17:43:55 +00:00
|
|
|
* @param CakeEvent $event the event being sent
|
2014-06-27 18:03:29 +00:00
|
|
|
* @return void
|
|
|
|
*/
|
2014-06-26 03:08:59 +00:00
|
|
|
public function afterRender($event) {
|
2014-06-27 15:21:07 +00:00
|
|
|
$this->afterRenderViewType = $event->subject()->getCurrentType();
|
2014-06-26 03:08:59 +00:00
|
|
|
}
|
2014-06-27 17:28:43 +00:00
|
|
|
|
2014-06-26 03:08:59 +00:00
|
|
|
}
|
2014-06-27 18:03:29 +00:00
|
|
|
|
2008-05-30 11:40:08 +00:00
|
|
|
/**
|
2009-03-19 21:10:13 +00:00
|
|
|
* ViewTest 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
|
|
|
*/
|
|
|
|
class ViewTest extends CakeTestCase {
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2011-11-13 02:00:42 +00:00
|
|
|
/**
|
|
|
|
* Fixtures used in this test.
|
|
|
|
*
|
|
|
|
* @var array
|
|
|
|
*/
|
|
|
|
public $fixtures = array('core.user', 'core.post');
|
|
|
|
|
2008-06-02 19:22:55 +00:00
|
|
|
/**
|
|
|
|
* setUp method
|
2008-06-08 15:44:46 +00:00
|
|
|
*
|
2008-06-02 19:22:55 +00:00
|
|
|
* @return void
|
|
|
|
*/
|
2022-12-28 07:03:39 +00:00
|
|
|
public function setUp() : void {
|
2010-09-26 01:36:49 +00:00
|
|
|
parent::setUp();
|
2010-09-11 03:55:42 +00:00
|
|
|
|
2010-08-28 04:40:12 +00:00
|
|
|
$request = $this->getMock('CakeRequest');
|
2010-09-11 03:55:42 +00:00
|
|
|
$this->Controller = new Controller($request);
|
2010-08-28 04:40:12 +00:00
|
|
|
$this->PostsController = new ViewPostsController($request);
|
2011-05-15 17:41:34 +00:00
|
|
|
$this->PostsController->viewPath = 'Posts';
|
2008-05-30 11:40:08 +00:00
|
|
|
$this->PostsController->index();
|
|
|
|
$this->View = new View($this->PostsController);
|
2012-01-22 20:45:26 +00:00
|
|
|
|
|
|
|
$themeRequest = new CakeRequest('posts/index');
|
|
|
|
$this->ThemeController = new Controller($themeRequest);
|
|
|
|
$this->ThemePostsController = new ThemePostsController($themeRequest);
|
|
|
|
$this->ThemePostsController->viewPath = 'posts';
|
|
|
|
$this->ThemePostsController->index();
|
|
|
|
$this->ThemeView = new View($this->ThemePostsController);
|
|
|
|
|
2009-06-11 16:13:16 +00:00
|
|
|
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)
|
2012-02-18 12:04:54 +00:00
|
|
|
), App::RESET);
|
2012-01-22 20:45:26 +00:00
|
|
|
App::objects('plugins', null, false);
|
|
|
|
|
2011-11-13 02:29:54 +00:00
|
|
|
CakePlugin::load(array('TestPlugin', 'TestPlugin', 'PluginJs'));
|
2010-09-25 14:50:35 +00:00
|
|
|
Configure::write('debug', 2);
|
2009-07-24 19:18:37 +00:00
|
|
|
}
|
|
|
|
|
2009-06-11 16:13:16 +00:00
|
|
|
/**
|
2010-06-01 02:54:53 +00:00
|
|
|
* tearDown method
|
2009-06-11 16:13:16 +00:00
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
2022-12-28 07:03:39 +00:00
|
|
|
public function tearDown() : void {
|
2010-09-26 01:36:49 +00:00
|
|
|
parent::tearDown();
|
2011-05-06 05:37:59 +00:00
|
|
|
CakePlugin::unload();
|
2010-06-01 02:54:53 +00:00
|
|
|
unset($this->View);
|
|
|
|
unset($this->PostsController);
|
|
|
|
unset($this->Controller);
|
2012-01-22 20:45:26 +00:00
|
|
|
unset($this->ThemeView);
|
|
|
|
unset($this->ThemePostsController);
|
|
|
|
unset($this->ThemeController);
|
|
|
|
}
|
2012-03-16 02:50:05 +00:00
|
|
|
|
2012-01-22 20:45:26 +00:00
|
|
|
/**
|
2013-07-27 04:51:30 +00:00
|
|
|
* Test getViewFileName method
|
2012-01-22 20:45:26 +00:00
|
|
|
*
|
|
|
|
* @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 TestThemeView($this->Controller);
|
2013-01-04 02:06:46 +00:00
|
|
|
$ThemeView->theme = 'test_theme';
|
2012-03-16 02:50:05 +00:00
|
|
|
$expected = CAKE . 'Test' . DS . 'test_app' . DS . 'View' . DS . 'Pages' . DS . 'home.ctp';
|
2012-01-22 20:45:26 +00:00
|
|
|
$result = $ThemeView->getViewFileName('home');
|
|
|
|
$this->assertEquals($expected, $result);
|
|
|
|
|
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';
|
2012-01-22 20:45:26 +00:00
|
|
|
$result = $ThemeView->getViewFileName('/Posts/index');
|
|
|
|
$this->assertEquals($expected, $result);
|
|
|
|
|
2013-01-04 02:06:46 +00:00
|
|
|
$ThemeView->theme = 'TestTheme';
|
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';
|
2012-01-22 20:45:26 +00:00
|
|
|
$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);
|
2009-07-24 19:18:37 +00:00
|
|
|
}
|
|
|
|
|
2015-11-02 03:04:15 +00:00
|
|
|
/**
|
|
|
|
* Test that plugin files with absolute file paths are scoped
|
|
|
|
* to the plugin and do now allow any file path.
|
|
|
|
*
|
|
|
|
* @expectedException MissingViewException
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function testPluginGetTemplateAbsoluteFail() {
|
|
|
|
$this->Controller->viewPath = 'Pages';
|
|
|
|
$this->Controller->action = 'display';
|
|
|
|
$this->Controller->params['pass'] = array('home');
|
|
|
|
|
|
|
|
$view = new TestThemeView($this->Controller);
|
|
|
|
$expected = CAKE . 'Test' . DS . 'test_app' . DS . 'Plugin' . DS . 'Company' . DS . 'TestPluginThree' . DS . 'View' . DS . 'Pages' . DS . 'index.ctp';
|
|
|
|
$result = $view->getViewFileName('Company/TestPluginThree./Pages/index');
|
|
|
|
$this->assertPathEquals($expected, $result);
|
|
|
|
|
|
|
|
$view->getViewFileName('Company/TestPluginThree./etc/passwd');
|
|
|
|
}
|
|
|
|
|
2008-06-02 19:22:55 +00:00
|
|
|
/**
|
2013-07-27 04:51:30 +00:00
|
|
|
* Test getLayoutFileName method on plugin
|
2008-06-08 15:44:46 +00:00
|
|
|
*
|
2008-06-02 19:22:55 +00:00
|
|
|
* @return void
|
|
|
|
*/
|
2011-05-30 20:02:32 +00:00
|
|
|
public function testPluginGetTemplate() {
|
2011-05-06 05:35:33 +00:00
|
|
|
$this->Controller->plugin = 'TestPlugin';
|
2008-05-30 11:40:08 +00:00
|
|
|
$this->Controller->name = 'TestPlugin';
|
2011-05-13 07:23:35 +00:00
|
|
|
$this->Controller->viewPath = 'Tests';
|
2008-05-30 11:40:08 +00:00
|
|
|
$this->Controller->action = 'index';
|
|
|
|
|
|
|
|
$View = new TestView($this->Controller);
|
|
|
|
|
2012-03-16 02:50:05 +00:00
|
|
|
$expected = CakePlugin::path('TestPlugin') . 'View' . DS . 'Tests' . DS . 'index.ctp';
|
2008-05-30 11:40:08 +00:00
|
|
|
$result = $View->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 = CakePlugin::path('TestPlugin') . 'View' . DS . 'Layouts' . DS . 'default.ctp';
|
2009-06-24 22:02:00 +00:00
|
|
|
$result = $View->getLayoutFileName();
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertEquals($expected, $result);
|
2009-06-24 22:02:00 +00:00
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2012-01-22 20:45:26 +00:00
|
|
|
/**
|
2013-07-27 04:51:30 +00:00
|
|
|
* Test getViewFileName method on plugin
|
2012-01-22 20:45:26 +00:00
|
|
|
*
|
|
|
|
* @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 TestThemeView($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';
|
2012-01-22 20:45:26 +00:00
|
|
|
$result = $ThemeView->getViewFileName('index');
|
|
|
|
$this->assertEquals($expected, $result);
|
|
|
|
|
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';
|
2012-01-22 20:45:26 +00:00
|
|
|
$result = $ThemeView->getLayoutFileName('plugin_default');
|
|
|
|
$this->assertEquals($expected, $result);
|
|
|
|
|
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';
|
2012-01-22 20:45:26 +00:00
|
|
|
$result = $ThemeView->getLayoutFileName('default');
|
|
|
|
$this->assertEquals($expected, $result);
|
|
|
|
}
|
|
|
|
|
2009-08-24 02:43:51 +00:00
|
|
|
/**
|
2013-07-27 04:51:30 +00:00
|
|
|
* Test that plugin/$plugin_name is only appended to the paths it should be.
|
2009-08-24 02:43:51 +00:00
|
|
|
*
|
|
|
|
* @return void
|
2009-11-14 12:19:25 +00:00
|
|
|
*/
|
2011-05-30 20:02:32 +00:00
|
|
|
public function testPluginPathGeneration() {
|
2011-05-06 05:35:33 +00:00
|
|
|
$this->Controller->plugin = 'TestPlugin';
|
2009-08-24 02:43:51 +00:00
|
|
|
$this->Controller->name = 'TestPlugin';
|
2011-05-13 07:23:35 +00:00
|
|
|
$this->Controller->viewPath = 'Tests';
|
2009-08-24 02:43:51 +00:00
|
|
|
$this->Controller->action = 'index';
|
|
|
|
|
|
|
|
$View = new TestView($this->Controller);
|
|
|
|
$paths = $View->paths();
|
2012-02-20 20:09:03 +00:00
|
|
|
$expected = array_merge(App::path('View'), App::core('View'), App::core('Console/Templates/skel/View'));
|
2012-03-23 06:37:12 +00:00
|
|
|
$this->assertEquals($expected, $paths);
|
2009-08-24 02:43:51 +00:00
|
|
|
|
2011-05-06 05:35:33 +00:00
|
|
|
$paths = $View->paths('TestPlugin');
|
|
|
|
$pluginPath = CakePlugin::path('TestPlugin');
|
2009-08-24 02:43:51 +00:00
|
|
|
$expected = array(
|
2011-10-13 13:22:10 +00:00
|
|
|
CAKE . 'Test' . DS . 'test_app' . DS . 'View' . DS . 'Plugin' . DS . 'TestPlugin' . DS,
|
2011-05-06 05:35:33 +00:00
|
|
|
$pluginPath . 'View' . DS,
|
2011-04-17 10:35:21 +00:00
|
|
|
CAKE . 'Test' . DS . 'test_app' . DS . 'View' . DS,
|
2012-02-20 20:09:03 +00:00
|
|
|
CAKE . 'View' . DS,
|
|
|
|
CAKE . 'Console' . DS . 'Templates' . DS . 'skel' . DS . 'View' . DS
|
2009-08-24 02:43:51 +00:00
|
|
|
);
|
2012-03-23 06:37:12 +00:00
|
|
|
$this->assertEquals($expected, $paths);
|
2009-08-24 02:43:51 +00:00
|
|
|
}
|
|
|
|
|
2009-06-24 22:02:00 +00:00
|
|
|
/**
|
2013-07-27 04:51:30 +00:00
|
|
|
* Test that CamelCase'd plugins still find their view files.
|
2009-06-24 22:02:00 +00:00
|
|
|
*
|
|
|
|
* @return void
|
2009-11-14 12:19:25 +00:00
|
|
|
*/
|
2011-05-30 20:02:32 +00:00
|
|
|
public function testCamelCasePluginGetTemplate() {
|
2009-06-24 22:02:00 +00:00
|
|
|
$this->Controller->plugin = 'TestPlugin';
|
|
|
|
$this->Controller->name = 'TestPlugin';
|
2011-05-13 07:23:35 +00:00
|
|
|
$this->Controller->viewPath = 'Tests';
|
2009-06-24 22:02:00 +00:00
|
|
|
$this->Controller->action = 'index';
|
|
|
|
|
|
|
|
$View = new TestView($this->Controller);
|
2009-08-14 16:08:33 +00:00
|
|
|
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)
|
2009-08-14 16:08:33 +00:00
|
|
|
));
|
2009-06-24 22:02:00 +00:00
|
|
|
|
2011-05-06 05:35:33 +00:00
|
|
|
$pluginPath = CakePlugin::path('TestPlugin');
|
2012-03-16 02:50:05 +00:00
|
|
|
$expected = CAKE . 'Test' . DS . 'test_app' . DS . 'Plugin' . DS . 'TestPlugin' . DS . 'View' . DS . 'Tests' . DS . 'index.ctp';
|
2008-05-30 11:40:08 +00:00
|
|
|
$result = $View->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 = $pluginPath . 'View' . DS . 'Layouts' . DS . 'default.ctp';
|
2008-05-30 11:40:08 +00:00
|
|
|
$result = $View->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-02 19:22:55 +00:00
|
|
|
/**
|
2013-07-27 04:51:30 +00:00
|
|
|
* Test getViewFileName method
|
2008-06-08 15:44:46 +00:00
|
|
|
*
|
2008-06-02 19:22:55 +00:00
|
|
|
* @return void
|
|
|
|
*/
|
2011-11-13 03:31:34 +00:00
|
|
|
public function testGetViewFileNames() {
|
2008-05-30 11:40:08 +00:00
|
|
|
$this->Controller->plugin = null;
|
|
|
|
$this->Controller->name = 'Pages';
|
2011-05-13 07:45:04 +00:00
|
|
|
$this->Controller->viewPath = 'Pages';
|
2008-05-30 11:40:08 +00:00
|
|
|
$this->Controller->action = 'display';
|
|
|
|
$this->Controller->params['pass'] = array('home');
|
|
|
|
|
|
|
|
$View = new TestView($this->Controller);
|
2009-07-24 19:18:37 +00:00
|
|
|
|
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 = $View->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 . 'Posts' . DS . 'index.ctp';
|
2011-05-13 07:45:04 +00:00
|
|
|
$result = $View->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 . 'Posts' . DS . 'index.ctp';
|
2011-05-13 07:45:04 +00:00
|
|
|
$result = $View->getViewFileName('../Posts/index');
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertEquals($expected, $result);
|
2008-06-08 15:44:46 +00:00
|
|
|
|
2012-03-16 02:50:05 +00:00
|
|
|
$expected = CAKE . 'Test' . DS . 'test_app' . DS . 'View' . DS . 'Pages' . DS . 'page.home.ctp';
|
2011-11-13 03:31:34 +00:00
|
|
|
$result = $View->getViewFileName('page.home');
|
|
|
|
$this->assertEquals($expected, $result, 'Should not ruin files with dots.');
|
2011-11-13 03:23:27 +00:00
|
|
|
|
|
|
|
CakePlugin::load('TestPlugin');
|
2012-03-16 02:50:05 +00:00
|
|
|
$expected = CAKE . 'Test' . DS . 'test_app' . DS . 'View' . DS . 'Pages' . DS . 'home.ctp';
|
2011-11-13 03:23:27 +00:00
|
|
|
$result = $View->getViewFileName('TestPlugin.home');
|
2011-11-13 03:31:34 +00:00
|
|
|
$this->assertEquals($expected, $result, 'Plugin is missing the view, cascade to app.');
|
2011-11-13 03:23:27 +00:00
|
|
|
|
|
|
|
$View->viewPath = 'Tests';
|
2012-03-16 02:50:05 +00:00
|
|
|
$expected = CAKE . 'Test' . DS . 'test_app' . DS . 'Plugin' . DS . 'TestPlugin' . DS . 'View' . DS . 'Tests' . DS . 'index.ctp';
|
2011-11-13 03:23:27 +00:00
|
|
|
$result = $View->getViewFileName('TestPlugin.index');
|
2011-11-13 03:31:34 +00:00
|
|
|
$this->assertEquals($expected, $result);
|
|
|
|
}
|
2011-11-13 03:23:27 +00:00
|
|
|
|
2011-11-13 03:31:34 +00:00
|
|
|
/**
|
|
|
|
* Test getting layout filenames
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function testGetLayoutFileName() {
|
|
|
|
$this->Controller->plugin = null;
|
|
|
|
$this->Controller->name = 'Pages';
|
|
|
|
$this->Controller->viewPath = 'Pages';
|
|
|
|
$this->Controller->action = 'display';
|
|
|
|
|
|
|
|
$View = new TestView($this->Controller);
|
|
|
|
|
2012-03-16 02:50:05 +00:00
|
|
|
$expected = CAKE . 'Test' . DS . 'test_app' . DS . 'View' . DS . 'Layouts' . DS . 'default.ctp';
|
2008-05-30 11:40:08 +00:00
|
|
|
$result = $View->getLayoutFileName();
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertEquals($expected, $result);
|
2008-05-30 11:40:08 +00:00
|
|
|
|
|
|
|
$View->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 = $View->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:22:19 +00:00
|
|
|
$View->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 = $View->getLayoutFileName();
|
2011-11-13 03:31:34 +00:00
|
|
|
$this->assertEquals($expected, $result);
|
|
|
|
}
|
2008-07-30 13:56:45 +00:00
|
|
|
|
2011-11-13 03:31:34 +00:00
|
|
|
/**
|
|
|
|
* Test getting layout filenames for plugins.
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function testGetLayoutFileNamePlugin() {
|
|
|
|
$this->Controller->plugin = null;
|
|
|
|
$this->Controller->name = 'Pages';
|
|
|
|
$this->Controller->viewPath = 'Pages';
|
|
|
|
$this->Controller->action = 'display';
|
|
|
|
|
|
|
|
$View = new TestView($this->Controller);
|
|
|
|
CakePlugin::load('TestPlugin');
|
2008-07-30 13:56:45 +00:00
|
|
|
|
2012-03-16 02:50:05 +00:00
|
|
|
$expected = CAKE . 'Test' . DS . 'test_app' . DS . 'Plugin' . DS . 'TestPlugin' . DS . 'View' . DS . 'Layouts' . DS . 'default.ctp';
|
2011-11-13 03:31:34 +00:00
|
|
|
$result = $View->getLayoutFileName('TestPlugin.default');
|
|
|
|
$this->assertEquals($expected, $result);
|
|
|
|
|
|
|
|
$View->plugin = 'TestPlugin';
|
2012-03-16 02:50:05 +00:00
|
|
|
$expected = CAKE . 'Test' . DS . 'test_app' . DS . 'Plugin' . DS . 'TestPlugin' . DS . 'View' . DS . 'Layouts' . DS . 'default.ctp';
|
2011-11-13 03:31:34 +00:00
|
|
|
$result = $View->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
|
|
|
/**
|
2013-07-27 04:51:30 +00:00
|
|
|
* Test for missing views
|
2008-06-08 15:44:46 +00:00
|
|
|
*
|
2010-07-03 05:00:09 +00:00
|
|
|
* @expectedException MissingViewException
|
2008-06-02 19:22:55 +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-15 17:41:34 +00:00
|
|
|
$this->Controller->viewPath = 'Pages';
|
2008-05-30 11:40:08 +00:00
|
|
|
$this->Controller->action = 'display';
|
|
|
|
$this->Controller->params['pass'] = array('home');
|
|
|
|
|
|
|
|
$View = new TestView($this->Controller);
|
2013-07-19 23:06:27 +00:00
|
|
|
$View->getViewFileName('does_not_exist');
|
2017-03-25 11:18:12 +00:00
|
|
|
}
|
2012-01-22 20:45:26 +00:00
|
|
|
|
2017-03-25 11:18:12 +00:00
|
|
|
/**
|
|
|
|
* Test for missing theme views
|
|
|
|
*
|
|
|
|
* @expectedException MissingViewException
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function testMissingThemeView() {
|
2012-01-22 20:45:26 +00:00
|
|
|
$this->ThemeController->plugin = null;
|
|
|
|
$this->ThemeController->name = 'Pages';
|
|
|
|
$this->ThemeController->viewPath = 'Pages';
|
|
|
|
$this->ThemeController->action = 'display';
|
|
|
|
$this->ThemeController->theme = 'my_theme';
|
|
|
|
|
|
|
|
$this->ThemeController->params['pass'] = array('home');
|
|
|
|
|
|
|
|
$View = new TestThemeView($this->ThemeController);
|
2013-01-04 02:06:46 +00:00
|
|
|
$View->getViewFileName('does_not_exist');
|
2008-05-30 11:40:08 +00:00
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-06-02 19:22:55 +00:00
|
|
|
/**
|
2013-07-27 04:51:30 +00:00
|
|
|
* Test for missing layouts
|
2008-06-08 15:44:46 +00:00
|
|
|
*
|
2010-07-03 05:00:09 +00:00
|
|
|
* @expectedException MissingLayoutException
|
2008-06-02 19:22:55 +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';
|
2011-05-15 17:41:34 +00:00
|
|
|
$this->Controller->viewPath = 'Posts';
|
2008-05-30 11:40:08 +00:00
|
|
|
$this->Controller->layout = 'whatever';
|
|
|
|
|
|
|
|
$View = new TestView($this->Controller);
|
2013-07-19 23:06:27 +00:00
|
|
|
$View->getLayoutFileName();
|
2017-03-25 11:18:12 +00:00
|
|
|
}
|
2012-01-22 20:45:26 +00:00
|
|
|
|
2017-03-25 11:18:12 +00:00
|
|
|
/**
|
|
|
|
* Test for missing theme layouts
|
|
|
|
*
|
|
|
|
* @expectedException MissingLayoutException
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function testMissingThemeLayout() {
|
2012-01-22 20:45:26 +00:00
|
|
|
$this->ThemeController->plugin = null;
|
|
|
|
$this->ThemeController->name = 'Posts';
|
|
|
|
$this->ThemeController->viewPath = 'posts';
|
|
|
|
$this->ThemeController->layout = 'whatever';
|
|
|
|
$this->ThemeController->theme = 'my_theme';
|
|
|
|
|
|
|
|
$View = new TestThemeView($this->ThemeController);
|
2013-07-19 23:06:27 +00:00
|
|
|
$View->getLayoutFileName();
|
2008-05-30 11:40:08 +00:00
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-06-02 19:22:55 +00:00
|
|
|
/**
|
2013-07-27 04:51:30 +00:00
|
|
|
* Test viewVars method
|
2008-06-08 15:44:46 +00:00
|
|
|
*
|
2008-06-02 19:22:55 +00:00
|
|
|
* @return void
|
|
|
|
*/
|
2011-05-30 20:02:32 +00:00
|
|
|
public function testViewVars() {
|
2012-03-23 06:37:12 +00:00
|
|
|
$this->assertEquals(array('testData' => 'Some test data', 'test2' => 'more data', 'test3' => 'even more data'), $this->View->viewVars);
|
2008-05-30 11:40:08 +00:00
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-06-02 19:22:55 +00:00
|
|
|
/**
|
2013-07-27 04:51:30 +00:00
|
|
|
* Test generation of UUIDs method
|
2008-06-08 15:44:46 +00:00
|
|
|
*
|
2008-06-02 19:22:55 +00:00
|
|
|
* @return void
|
|
|
|
*/
|
2011-05-30 20:02:32 +00:00
|
|
|
public function testUUIDGeneration() {
|
2008-05-30 11:40:08 +00:00
|
|
|
$result = $this->View->uuid('form', array('controller' => 'posts', 'action' => 'index'));
|
2012-03-23 06:37:12 +00:00
|
|
|
$this->assertEquals('form5988016017', $result);
|
2008-05-30 11:40:08 +00:00
|
|
|
$result = $this->View->uuid('form', array('controller' => 'posts', 'action' => 'index'));
|
2012-03-23 06:37:12 +00:00
|
|
|
$this->assertEquals('formc3dc6be854', $result);
|
2008-05-30 11:40:08 +00:00
|
|
|
$result = $this->View->uuid('form', array('controller' => 'posts', 'action' => 'index'));
|
2012-03-23 06:37:12 +00:00
|
|
|
$this->assertEquals('form28f92cc87f', $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
|
|
|
/**
|
2013-07-27 04:51:30 +00:00
|
|
|
* Test addInlineScripts method
|
2008-06-08 15:44:46 +00:00
|
|
|
*
|
2008-06-02 19:22:55 +00:00
|
|
|
* @return void
|
|
|
|
*/
|
2011-05-30 20:02:32 +00:00
|
|
|
public function testAddInlineScripts() {
|
2010-04-05 11:15:17 +00:00
|
|
|
$View = new TestView($this->Controller);
|
|
|
|
$View->addScript('prototype.js');
|
|
|
|
$View->addScript('prototype.js');
|
2012-03-23 06:37:12 +00:00
|
|
|
$this->assertEquals(array('prototype.js'), $View->scripts());
|
2008-05-30 11:40:08 +00:00
|
|
|
|
2010-04-05 11:15:17 +00:00
|
|
|
$View->addScript('mainEvent', 'Event.observe(window, "load", function() { doSomething(); }, true);');
|
2012-03-23 06:37:12 +00:00
|
|
|
$this->assertEquals(array('prototype.js', 'mainEvent' => 'Event.observe(window, "load", function() { doSomething(); }, true);'), $View->scripts());
|
2008-05-30 11:40:08 +00:00
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2012-11-30 13:11:45 +00:00
|
|
|
/**
|
2013-07-27 04:51:30 +00:00
|
|
|
* Test elementExists method
|
2012-11-30 13:11:45 +00:00
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function testElementExists() {
|
|
|
|
$result = $this->View->elementExists('test_element');
|
|
|
|
$this->assertTrue($result);
|
|
|
|
|
|
|
|
$result = $this->View->elementExists('TestPlugin.plugin_element');
|
|
|
|
$this->assertTrue($result);
|
|
|
|
|
|
|
|
$result = $this->View->elementExists('non_existent_element');
|
|
|
|
$this->assertFalse($result);
|
|
|
|
|
|
|
|
$result = $this->View->elementExists('TestPlugin.element');
|
|
|
|
$this->assertFalse($result);
|
|
|
|
|
|
|
|
$this->View->plugin = 'TestPlugin';
|
|
|
|
$result = $this->View->elementExists('test_plugin_element');
|
|
|
|
$this->assertTrue($result);
|
|
|
|
}
|
|
|
|
|
2008-06-02 19:22:55 +00:00
|
|
|
/**
|
2013-07-27 04:51:30 +00:00
|
|
|
* Test element method
|
2008-06-08 15:44:46 +00:00
|
|
|
*
|
2008-06-02 19:22:55 +00:00
|
|
|
* @return void
|
|
|
|
*/
|
2011-05-30 20:02:32 +00:00
|
|
|
public function testElement() {
|
2008-05-30 11:40:08 +00:00
|
|
|
$result = $this->View->element('test_element');
|
2012-03-23 06:37:12 +00:00
|
|
|
$this->assertEquals('this is the test element', $result);
|
2011-04-17 01:26:33 +00:00
|
|
|
|
2011-05-06 05:35:33 +00:00
|
|
|
$result = $this->View->element('plugin_element', array(), array('plugin' => 'TestPlugin'));
|
2012-03-23 06:37:12 +00:00
|
|
|
$this->assertEquals('this is the plugin element using params[plugin]', $result);
|
2011-10-13 13:22:10 +00:00
|
|
|
|
2011-07-02 00:17:44 +00:00
|
|
|
$result = $this->View->element('plugin_element', array(), array('plugin' => 'test_plugin'));
|
2012-03-23 06:37:12 +00:00
|
|
|
$this->assertEquals('this is the plugin element using params[plugin]', $result);
|
2011-04-17 01:26:33 +00:00
|
|
|
|
2011-11-13 03:23:27 +00:00
|
|
|
$result = $this->View->element('TestPlugin.plugin_element');
|
2012-03-23 06:37:12 +00:00
|
|
|
$this->assertEquals('this is the plugin element using params[plugin]', $result);
|
2011-11-13 03:23:27 +00:00
|
|
|
|
2011-05-06 05:35:33 +00:00
|
|
|
$this->View->plugin = 'TestPlugin';
|
2009-11-26 05:17:15 +00:00
|
|
|
$result = $this->View->element('test_plugin_element');
|
2012-03-23 06:37:12 +00:00
|
|
|
$this->assertEquals('this is the test set using View::$plugin plugin element', $result);
|
2012-11-30 13:11:45 +00:00
|
|
|
}
|
2008-05-30 11:40:08 +00:00
|
|
|
|
2012-11-30 13:11:45 +00:00
|
|
|
/**
|
2013-07-27 04:51:30 +00:00
|
|
|
* Test elementInexistent method
|
2012-11-30 13:11:45 +00:00
|
|
|
*
|
|
|
|
* @expectedException PHPUnit_Framework_Error_Notice
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function testElementInexistent() {
|
2013-01-23 12:45:50 +00:00
|
|
|
$this->View->element('non_existent_element');
|
2012-11-30 13:11:45 +00:00
|
|
|
}
|
2011-11-13 03:23:27 +00:00
|
|
|
|
2012-11-30 13:11:45 +00:00
|
|
|
/**
|
2013-07-27 04:51:30 +00:00
|
|
|
* Test elementInexistent2 method
|
2012-11-30 13:11:45 +00:00
|
|
|
*
|
|
|
|
* @expectedException PHPUnit_Framework_Error_Notice
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function testElementInexistent2() {
|
2013-01-23 12:45:50 +00:00
|
|
|
$this->View->element('TestPlugin.plugin_element', array(), array('plugin' => 'test_plugin'));
|
2012-11-30 13:11:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2013-07-27 04:51:30 +00:00
|
|
|
* Test elementInexistent3 method
|
2012-11-30 13:11:45 +00:00
|
|
|
*
|
|
|
|
* @expectedException PHPUnit_Framework_Error_Notice
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function testElementInexistent3() {
|
2013-01-23 12:45:50 +00:00
|
|
|
$this->View->element('test_plugin.plugin_element');
|
2008-05-30 11:40:08 +00:00
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2010-11-05 03:45:07 +00:00
|
|
|
/**
|
2013-07-27 04:51:30 +00:00
|
|
|
* Test that elements can have callbacks
|
2014-04-02 01:02:37 +00:00
|
|
|
*
|
|
|
|
* @return void
|
2010-11-05 03:45:07 +00:00
|
|
|
*/
|
2011-05-30 20:02:32 +00:00
|
|
|
public function testElementCallbacks() {
|
2014-03-01 18:01:36 +00:00
|
|
|
$Helper = $this->getMock('Helper', array(), array($this->View), 'ElementCallbackMockHtmlHelper');
|
2010-11-05 03:45:07 +00:00
|
|
|
$this->View->helpers = array('ElementCallbackMockHtml');
|
|
|
|
$this->View->loadHelpers();
|
|
|
|
|
2014-03-01 18:01:36 +00:00
|
|
|
$this->View->Helpers->set('ElementCallbackMockHtml', $Helper);
|
|
|
|
$this->View->ElementCallbackMockHtml = $Helper;
|
|
|
|
|
2010-11-05 03:45:07 +00:00
|
|
|
$this->View->ElementCallbackMockHtml->expects($this->at(0))->method('beforeRender');
|
|
|
|
$this->View->ElementCallbackMockHtml->expects($this->at(1))->method('afterRender');
|
|
|
|
|
2011-04-17 01:26:33 +00:00
|
|
|
$this->View->element('test_element', array(), array('callbacks' => true));
|
2010-11-05 03:45:07 +00:00
|
|
|
}
|
2011-12-06 20:52:48 +00:00
|
|
|
|
2010-12-10 03:06:23 +00:00
|
|
|
/**
|
2013-07-27 04:51:30 +00:00
|
|
|
* Test that additional element viewVars don't get overwritten with helpers.
|
2010-12-10 03:06:23 +00:00
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
2011-05-30 20:02:32 +00:00
|
|
|
public function testElementParamsDontOverwriteHelpers() {
|
2010-12-10 03:06:23 +00:00
|
|
|
$Controller = new ViewPostsController();
|
|
|
|
$Controller->helpers = array('Form');
|
|
|
|
|
|
|
|
$View = new View($Controller);
|
2011-04-17 01:26:33 +00:00
|
|
|
$result = $View->element('type_check', array('form' => 'string'), array('callbacks' => true));
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertEquals('string', $result);
|
2010-12-10 03:06:23 +00:00
|
|
|
|
|
|
|
$View->set('form', 'string');
|
2011-04-17 01:26:33 +00:00
|
|
|
$result = $View->element('type_check', array(), array('callbacks' => true));
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertEquals('string', $result);
|
2010-12-10 03:06:23 +00:00
|
|
|
}
|
|
|
|
|
2008-06-02 19:22:55 +00:00
|
|
|
/**
|
2013-07-27 04:51:30 +00:00
|
|
|
* Test elementCacheHelperNoCache method
|
2008-06-08 15:44:46 +00:00
|
|
|
*
|
2008-06-02 19:22:55 +00:00
|
|
|
* @return void
|
|
|
|
*/
|
2011-05-30 20:02:32 +00:00
|
|
|
public function testElementCacheHelperNoCache() {
|
2008-05-30 11:40:08 +00:00
|
|
|
$Controller = new ViewPostsController();
|
2010-04-24 04:22:21 +00:00
|
|
|
$View = new TestView($Controller);
|
2013-01-23 12:45:50 +00:00
|
|
|
$View->loadHelpers();
|
2008-05-30 11:40:08 +00:00
|
|
|
$result = $View->element('test_element', array('ram' => 'val', 'test' => array('foo', 'bar')));
|
2012-03-23 06:37:12 +00:00
|
|
|
$this->assertEquals('this is the test element', $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
|
|
|
/**
|
2013-07-27 04:51:30 +00:00
|
|
|
* Test elementCache method
|
2008-06-08 15:44:46 +00:00
|
|
|
*
|
2008-06-02 19:22:55 +00:00
|
|
|
* @return void
|
|
|
|
*/
|
2011-05-30 20:02:32 +00:00
|
|
|
public function testElementCache() {
|
2010-11-08 05:05:44 +00:00
|
|
|
Cache::drop('test_view');
|
|
|
|
Cache::config('test_view', array(
|
|
|
|
'engine' => 'File',
|
|
|
|
'duration' => '+1 day',
|
2010-11-10 03:16:45 +00:00
|
|
|
'path' => CACHE . 'views' . DS,
|
|
|
|
'prefix' => ''
|
2010-11-08 05:05:44 +00:00
|
|
|
));
|
2012-02-23 15:20:23 +00:00
|
|
|
Cache::clear(true, 'test_view');
|
2010-11-08 05:05:44 +00:00
|
|
|
|
|
|
|
$View = new TestView($this->PostsController);
|
2010-11-10 03:16:45 +00:00
|
|
|
$View->elementCache = 'test_view';
|
|
|
|
|
2011-04-17 01:26:33 +00:00
|
|
|
$result = $View->element('test_element', array(), array('cache' => true));
|
2010-11-08 05:05:44 +00:00
|
|
|
$expected = 'this is the test element';
|
|
|
|
$this->assertEquals($expected, $result);
|
|
|
|
|
2012-07-07 05:08:39 +00:00
|
|
|
$result = Cache::read('element__test_element_cache_callbacks', 'test_view');
|
2010-11-10 03:16:45 +00:00
|
|
|
$this->assertEquals($expected, $result);
|
2011-04-17 01:26:33 +00:00
|
|
|
|
|
|
|
$result = $View->element('test_element', array('param' => 'one', 'foo' => 'two'), array('cache' => true));
|
2010-11-08 05:05:44 +00:00
|
|
|
$this->assertEquals($expected, $result);
|
|
|
|
|
2012-07-07 05:08:39 +00:00
|
|
|
$result = Cache::read('element__test_element_cache_callbacks_param_foo', 'test_view');
|
2010-11-10 03:16:45 +00:00
|
|
|
$this->assertEquals($expected, $result);
|
2011-04-17 01:26:33 +00:00
|
|
|
|
2013-07-19 23:06:27 +00:00
|
|
|
$View->element('test_element', array(
|
2010-11-10 03:16:45 +00:00
|
|
|
'param' => 'one',
|
|
|
|
'foo' => 'two'
|
2011-04-17 01:26:33 +00:00
|
|
|
), array(
|
|
|
|
'cache' => array('key' => 'custom_key')
|
2010-11-10 03:16:45 +00:00
|
|
|
));
|
|
|
|
$result = Cache::read('element_custom_key', 'test_view');
|
|
|
|
$this->assertEquals($expected, $result);
|
2011-04-17 01:26:33 +00:00
|
|
|
|
2010-11-10 03:31:05 +00:00
|
|
|
$View->elementCache = 'default';
|
2013-07-19 23:06:27 +00:00
|
|
|
$View->element('test_element', array(
|
2010-11-10 03:31:05 +00:00
|
|
|
'param' => 'one',
|
|
|
|
'foo' => 'two'
|
2011-04-17 01:26:33 +00:00
|
|
|
), array(
|
|
|
|
'cache' => array('config' => 'test_view'),
|
2010-11-10 03:31:05 +00:00
|
|
|
));
|
2012-07-07 05:08:39 +00:00
|
|
|
$result = Cache::read('element__test_element_cache_callbacks_param_foo', 'test_view');
|
2010-11-10 03:31:05 +00:00
|
|
|
$this->assertEquals($expected, $result);
|
2008-05-30 11:40:08 +00:00
|
|
|
|
2012-02-23 15:20:23 +00:00
|
|
|
Cache::clear(true, 'test_view');
|
2010-11-10 03:16:45 +00:00
|
|
|
Cache::drop('test_view');
|
2014-07-03 17:43:55 +00:00
|
|
|
}
|
2014-06-26 03:08:59 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Test element events
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
2014-06-27 17:28:43 +00:00
|
|
|
public function testViewEvent() {
|
2014-06-26 03:08:59 +00:00
|
|
|
$View = new View($this->PostsController);
|
2014-06-27 15:21:07 +00:00
|
|
|
$View->autoLayout = false;
|
|
|
|
$listener = new TestViewEventListener();
|
2014-06-26 03:08:59 +00:00
|
|
|
|
|
|
|
$View->getEventManager()->attach($listener);
|
|
|
|
|
2014-06-27 15:21:07 +00:00
|
|
|
$View->render('index');
|
|
|
|
$this->assertEquals(View::TYPE_VIEW, $listener->beforeRenderViewType);
|
|
|
|
$this->assertEquals(View::TYPE_VIEW, $listener->afterRenderViewType);
|
|
|
|
|
|
|
|
$this->assertEquals($View->getCurrentType(), View::TYPE_VIEW);
|
2014-06-27 18:03:29 +00:00
|
|
|
$View->element('test_element', array(), array('callbacks' => true));
|
2014-06-27 15:21:07 +00:00
|
|
|
$this->assertEquals($View->getCurrentType(), View::TYPE_VIEW);
|
|
|
|
|
|
|
|
$this->assertEquals(View::TYPE_ELEMENT, $listener->beforeRenderViewType);
|
|
|
|
$this->assertEquals(View::TYPE_ELEMENT, $listener->afterRenderViewType);
|
2008-05-30 11:40:08 +00:00
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2010-07-03 03:50:41 +00:00
|
|
|
/**
|
2013-07-27 04:51:30 +00:00
|
|
|
* Test __get allowing access to helpers.
|
2010-07-03 03:50:41 +00:00
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
2012-03-20 01:58:56 +00:00
|
|
|
public function testMagicGet() {
|
2010-07-03 03:50:41 +00:00
|
|
|
$View = new View($this->PostsController);
|
|
|
|
$View->loadHelper('Html');
|
2010-12-24 17:54:04 +00:00
|
|
|
$this->assertInstanceOf('HtmlHelper', $View->Html);
|
2010-07-03 03:50:41 +00:00
|
|
|
}
|
|
|
|
|
2011-01-13 01:43:41 +00:00
|
|
|
/**
|
2013-07-27 04:51:30 +00:00
|
|
|
* Test that ctp is used as a fallback file extension for elements
|
2011-01-13 01:43:41 +00:00
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
2011-05-30 20:02:32 +00:00
|
|
|
public function testElementCtpFallback() {
|
2011-01-13 01:43:41 +00:00
|
|
|
$View = new TestView($this->PostsController);
|
|
|
|
$View->ext = '.missing';
|
|
|
|
$element = 'test_element';
|
|
|
|
$expected = 'this is the test element';
|
|
|
|
$result = $View->element($element);
|
|
|
|
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertEquals($expected, $result);
|
2011-01-13 01:43:41 +00:00
|
|
|
}
|
|
|
|
|
2008-06-02 19:22:55 +00:00
|
|
|
/**
|
2013-07-27 04:51:30 +00:00
|
|
|
* Test loadHelpers method
|
2008-06-08 15:44:46 +00:00
|
|
|
*
|
2008-06-02 19:22:55 +00:00
|
|
|
* @return void
|
|
|
|
*/
|
2011-05-30 20:02:32 +00:00
|
|
|
public function testLoadHelpers() {
|
2010-07-03 03:50:41 +00:00
|
|
|
$View = new View($this->PostsController);
|
2008-05-30 11:40:08 +00:00
|
|
|
|
2010-07-03 03:50:41 +00:00
|
|
|
$View->helpers = array('Html', 'Form');
|
|
|
|
$View->loadHelpers();
|
2008-05-30 11:40:08 +00:00
|
|
|
|
2010-12-24 17:54:04 +00:00
|
|
|
$this->assertInstanceOf('HtmlHelper', $View->Html, 'Object type is wrong.');
|
|
|
|
$this->assertInstanceOf('FormHelper', $View->Form, 'Object type is wrong.');
|
2008-05-30 11:40:08 +00:00
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2012-03-28 04:13:41 +00:00
|
|
|
/**
|
2013-07-27 04:51:30 +00:00
|
|
|
* Test lazy loading helpers
|
2012-03-28 04:13:41 +00:00
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function testLazyLoadHelpers() {
|
|
|
|
$View = new View($this->PostsController);
|
|
|
|
|
|
|
|
$View->helpers = array();
|
|
|
|
$this->assertInstanceOf('HtmlHelper', $View->Html, 'Object type is wrong.');
|
|
|
|
$this->assertInstanceOf('FormHelper', $View->Form, 'Object type is wrong.');
|
|
|
|
}
|
|
|
|
|
2008-12-21 22:14:48 +00:00
|
|
|
/**
|
2013-07-27 04:51:30 +00:00
|
|
|
* Test the correct triggering of helper callbacks
|
2008-12-21 22:14:48 +00:00
|
|
|
*
|
|
|
|
* @return void
|
2009-11-14 12:19:25 +00:00
|
|
|
*/
|
2011-05-30 20:02:32 +00:00
|
|
|
public function testHelperCallbackTriggering() {
|
2010-07-03 03:50:41 +00:00
|
|
|
$View = new View($this->PostsController);
|
2011-12-13 02:43:41 +00:00
|
|
|
$View->helpers = array();
|
2010-07-03 04:49:00 +00:00
|
|
|
$View->Helpers = $this->getMock('HelperCollection', array('trigger'), array($View));
|
|
|
|
|
|
|
|
$View->Helpers->expects($this->at(0))->method('trigger')
|
2011-12-25 23:30:19 +00:00
|
|
|
->with(
|
|
|
|
$this->logicalAnd(
|
|
|
|
$this->isInstanceOf('CakeEvent'),
|
|
|
|
$this->attributeEqualTo('_name', 'View.beforeRender'),
|
|
|
|
$this->attributeEqualTo('_subject', $View)
|
|
|
|
)
|
|
|
|
);
|
2010-07-03 04:49:00 +00:00
|
|
|
$View->Helpers->expects($this->at(1))->method('trigger')
|
2011-12-25 23:30:19 +00:00
|
|
|
->with(
|
|
|
|
$this->logicalAnd(
|
|
|
|
$this->isInstanceOf('CakeEvent'),
|
|
|
|
$this->attributeEqualTo('_name', 'View.beforeRenderFile'),
|
|
|
|
$this->attributeEqualTo('_subject', $View)
|
|
|
|
)
|
|
|
|
);
|
|
|
|
|
2011-10-08 18:47:25 +00:00
|
|
|
$View->Helpers->expects($this->at(2))->method('trigger')
|
2011-12-25 23:30:19 +00:00
|
|
|
->with(
|
|
|
|
$this->logicalAnd(
|
|
|
|
$this->isInstanceOf('CakeEvent'),
|
|
|
|
$this->attributeEqualTo('_name', 'View.afterRenderFile'),
|
|
|
|
$this->attributeEqualTo('_subject', $View)
|
|
|
|
)
|
|
|
|
);
|
2011-10-08 18:47:25 +00:00
|
|
|
$View->Helpers->expects($this->at(3))->method('trigger')
|
2011-12-25 23:30:19 +00:00
|
|
|
->with(
|
|
|
|
$this->logicalAnd(
|
|
|
|
$this->isInstanceOf('CakeEvent'),
|
|
|
|
$this->attributeEqualTo('_name', 'View.afterRender'),
|
|
|
|
$this->attributeEqualTo('_subject', $View)
|
|
|
|
)
|
|
|
|
);
|
2012-01-12 10:48:51 +00:00
|
|
|
|
2011-10-08 18:47:25 +00:00
|
|
|
$View->Helpers->expects($this->at(4))->method('trigger')
|
2011-12-25 23:30:19 +00:00
|
|
|
->with(
|
|
|
|
$this->logicalAnd(
|
|
|
|
$this->isInstanceOf('CakeEvent'),
|
|
|
|
$this->attributeEqualTo('_name', 'View.beforeLayout'),
|
|
|
|
$this->attributeEqualTo('_subject', $View)
|
|
|
|
)
|
|
|
|
);
|
|
|
|
|
2011-10-08 18:47:25 +00:00
|
|
|
$View->Helpers->expects($this->at(5))->method('trigger')
|
2011-12-25 23:30:19 +00:00
|
|
|
->with(
|
|
|
|
$this->logicalAnd(
|
|
|
|
$this->isInstanceOf('CakeEvent'),
|
|
|
|
$this->attributeEqualTo('_name', 'View.beforeRenderFile'),
|
|
|
|
$this->attributeEqualTo('_subject', $View)
|
|
|
|
)
|
|
|
|
);
|
|
|
|
|
2011-10-08 18:47:25 +00:00
|
|
|
$View->Helpers->expects($this->at(6))->method('trigger')
|
2011-12-25 23:30:19 +00:00
|
|
|
->with(
|
|
|
|
$this->logicalAnd(
|
|
|
|
$this->isInstanceOf('CakeEvent'),
|
|
|
|
$this->attributeEqualTo('_name', 'View.afterRenderFile'),
|
|
|
|
$this->attributeEqualTo('_subject', $View)
|
|
|
|
)
|
|
|
|
);
|
|
|
|
|
2011-10-08 18:47:25 +00:00
|
|
|
$View->Helpers->expects($this->at(7))->method('trigger')
|
2011-12-25 23:30:19 +00:00
|
|
|
->with(
|
|
|
|
$this->logicalAnd(
|
|
|
|
$this->isInstanceOf('CakeEvent'),
|
|
|
|
$this->attributeEqualTo('_name', 'View.afterLayout'),
|
|
|
|
$this->attributeEqualTo('_subject', $View)
|
|
|
|
)
|
|
|
|
);
|
2010-07-03 04:49:00 +00:00
|
|
|
|
2008-12-21 22:14:48 +00:00
|
|
|
$View->render('index');
|
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-06-02 19:22:55 +00:00
|
|
|
/**
|
2013-07-27 04:51:30 +00:00
|
|
|
* Test beforeLayout method
|
2008-06-08 15:44:46 +00:00
|
|
|
*
|
2008-06-02 19:22:55 +00:00
|
|
|
* @return void
|
|
|
|
*/
|
2011-05-30 20:02:32 +00:00
|
|
|
public function testBeforeLayout() {
|
2013-09-12 22:09:31 +00:00
|
|
|
$this->PostsController->helpers = array('Session', 'TestBeforeAfter', 'Html');
|
2010-04-24 04:22:21 +00:00
|
|
|
$View = new View($this->PostsController);
|
2010-07-03 04:49:00 +00:00
|
|
|
$View->render('index');
|
2013-09-12 22:09:31 +00:00
|
|
|
$this->assertEquals('Valuation', $View->Helpers->TestBeforeAfter->property);
|
2008-05-30 11:40:08 +00:00
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-06-02 19:22:55 +00:00
|
|
|
/**
|
2013-07-27 04:51:30 +00:00
|
|
|
* Test afterLayout method
|
2008-06-08 15:44:46 +00:00
|
|
|
*
|
2008-06-02 19:22:55 +00:00
|
|
|
* @return void
|
|
|
|
*/
|
2011-05-30 20:02:32 +00:00
|
|
|
public function testAfterLayout() {
|
2013-09-12 22:09:31 +00:00
|
|
|
$this->PostsController->helpers = array('Session', 'TestBeforeAfter', 'Html');
|
2008-05-30 11:40:08 +00:00
|
|
|
$this->PostsController->set('variable', 'values');
|
|
|
|
|
2010-04-24 04:22:21 +00:00
|
|
|
$View = new View($this->PostsController);
|
2008-05-30 11:40:08 +00:00
|
|
|
ClassRegistry::addObject('afterView', $View);
|
|
|
|
|
|
|
|
$content = 'This is my view output';
|
|
|
|
$result = $View->renderLayout($content, 'default');
|
2022-12-30 08:28:11 +00:00
|
|
|
$this->assertMatchesRegularExpression('/modified in the afterlife/', $result);
|
|
|
|
$this->assertMatchesRegularExpression('/This is my view output/', $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
|
|
|
/**
|
2013-07-27 04:51:30 +00:00
|
|
|
* Test renderLoadHelper method
|
2008-06-08 15:44:46 +00:00
|
|
|
*
|
2008-06-05 15:20:45 +00:00
|
|
|
* @return void
|
|
|
|
*/
|
2011-05-30 20:02:32 +00:00
|
|
|
public function testRenderLoadHelper() {
|
2010-04-24 04:22:21 +00:00
|
|
|
$this->PostsController->helpers = array('Session', 'Html', 'Form', 'Number');
|
|
|
|
$View = new TestView($this->PostsController);
|
2008-05-30 11:40:08 +00:00
|
|
|
|
2010-11-05 02:29:41 +00:00
|
|
|
$result = $View->render('index', false);
|
2012-03-23 06:37:12 +00:00
|
|
|
$this->assertEquals('posts index', $result);
|
2008-05-30 11:40:08 +00:00
|
|
|
|
2012-11-16 11:14:28 +00:00
|
|
|
$attached = $View->Helpers->loaded();
|
2012-03-23 06:37:12 +00:00
|
|
|
$this->assertEquals(array('Session', 'Html', 'Form', 'Number'), $attached);
|
2008-05-30 11:40:08 +00:00
|
|
|
|
2010-04-24 04:22:21 +00:00
|
|
|
$this->PostsController->helpers = array('Html', 'Form', 'Number', 'TestPlugin.PluggedHelper');
|
|
|
|
$View = new TestView($this->PostsController);
|
2008-05-30 11:40:08 +00:00
|
|
|
|
2010-11-05 02:29:41 +00:00
|
|
|
$result = $View->render('index', false);
|
2012-03-23 06:37:12 +00:00
|
|
|
$this->assertEquals('posts index', $result);
|
2008-05-30 11:40:08 +00:00
|
|
|
|
2012-11-16 11:14:28 +00:00
|
|
|
$attached = $View->Helpers->loaded();
|
2010-07-03 04:49:00 +00:00
|
|
|
$expected = array('Html', 'Form', 'Number', 'PluggedHelper');
|
|
|
|
$this->assertEquals($expected, $attached, 'Attached helpers are wrong.');
|
2008-05-30 11:40:08 +00:00
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-06-05 15:20:45 +00:00
|
|
|
/**
|
2013-07-27 04:51:30 +00:00
|
|
|
* Test render method
|
2008-06-08 15:44:46 +00:00
|
|
|
*
|
2008-06-05 15:20:45 +00:00
|
|
|
* @return void
|
|
|
|
*/
|
2011-05-30 20:02:32 +00:00
|
|
|
public function testRender() {
|
2010-04-24 04:22:21 +00:00
|
|
|
$View = new TestView($this->PostsController);
|
2012-02-17 02:51:56 +00:00
|
|
|
$result = $View->render('index');
|
2008-05-30 11:40:08 +00:00
|
|
|
|
2022-12-30 08:28:11 +00:00
|
|
|
$this->assertMatchesRegularExpression("/<meta http-equiv=\"Content-Type\" content=\"text\/html; charset=utf-8\" \/>\s*<title>/", $result);
|
|
|
|
$this->assertMatchesRegularExpression("/<div id=\"content\">\s*posts index\s*<\/div>/", $result);
|
|
|
|
$this->assertMatchesRegularExpression("/<div id=\"content\">\s*posts index\s*<\/div>/", $result);
|
2011-04-17 01:26:33 +00:00
|
|
|
|
2010-11-01 03:15:34 +00:00
|
|
|
$this->assertTrue(isset($View->viewVars['content_for_layout']), 'content_for_layout should be a view var');
|
|
|
|
$this->assertTrue(isset($View->viewVars['scripts_for_layout']), 'scripts_for_layout should be a view var');
|
2008-05-30 11:40:08 +00:00
|
|
|
|
|
|
|
$this->PostsController->set('url', 'flash');
|
|
|
|
$this->PostsController->set('message', 'yo what up');
|
|
|
|
$this->PostsController->set('pause', 3);
|
2014-09-18 08:50:35 +00:00
|
|
|
$this->PostsController->set('pageTitle', 'yo what up');
|
2008-05-30 11:40:08 +00:00
|
|
|
|
2010-04-24 04:22:21 +00:00
|
|
|
$View = new TestView($this->PostsController);
|
2012-02-17 02:51:56 +00:00
|
|
|
$result = $View->render(false, 'flash');
|
2008-05-30 11:40:08 +00:00
|
|
|
|
2022-12-30 08:28:11 +00:00
|
|
|
$this->assertMatchesRegularExpression("/<title>yo what up<\/title>/", $result);
|
|
|
|
$this->assertMatchesRegularExpression("/<p><a href=\"flash\">yo what up<\/a><\/p>/", $result);
|
2008-05-30 11:40:08 +00:00
|
|
|
|
2014-02-05 21:11:36 +00:00
|
|
|
$this->assertNull($View->render(false, 'flash'));
|
2008-05-30 11:40:08 +00:00
|
|
|
|
2010-01-14 04:55:09 +00:00
|
|
|
$this->PostsController->helpers = array('Session', 'Cache', 'Html');
|
2008-05-30 11:40:08 +00:00
|
|
|
$this->PostsController->constructClasses();
|
|
|
|
$this->PostsController->cacheAction = array('index' => 3600);
|
2010-09-11 22:56:35 +00:00
|
|
|
$this->PostsController->request->params['action'] = 'index';
|
2008-05-30 11:40:08 +00:00
|
|
|
Configure::write('Cache.check', true);
|
|
|
|
|
2010-04-24 04:22:21 +00:00
|
|
|
$View = new TestView($this->PostsController);
|
2012-02-17 02:51:56 +00:00
|
|
|
$result = $View->render('index');
|
2008-05-30 11:40:08 +00:00
|
|
|
|
2022-12-30 08:28:11 +00:00
|
|
|
$this->assertMatchesRegularExpression("/<meta http-equiv=\"Content-Type\" content=\"text\/html; charset=utf-8\" \/>\s*<title>/", $result);
|
|
|
|
$this->assertMatchesRegularExpression("/<div id=\"content\">\s*posts index\s*<\/div>/", $result);
|
|
|
|
$this->assertMatchesRegularExpression("/<div id=\"content\">\s*posts index\s*<\/div>/", $result);
|
2008-05-30 11:40:08 +00:00
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2011-03-08 02:50:53 +00:00
|
|
|
/**
|
2013-07-27 04:51:30 +00:00
|
|
|
* Test that View::$view works
|
2011-03-08 02:50:53 +00:00
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
2011-05-30 20:02:32 +00:00
|
|
|
public function testRenderUsingViewProperty() {
|
2011-03-08 02:50:53 +00:00
|
|
|
$this->PostsController->view = 'cache_form';
|
|
|
|
$View = new TestView($this->PostsController);
|
2011-04-17 01:26:33 +00:00
|
|
|
|
2011-03-08 02:50:53 +00:00
|
|
|
$this->assertEquals('cache_form', $View->view);
|
|
|
|
$result = $View->render();
|
2022-12-30 08:28:11 +00:00
|
|
|
$this->assertMatchesRegularExpression('/Add User/', $result);
|
2011-03-08 02:50:53 +00:00
|
|
|
}
|
|
|
|
|
2012-04-14 14:24:12 +00:00
|
|
|
/**
|
|
|
|
* Test render()ing a file in a subdir from a custom viewPath
|
|
|
|
* in a plugin.
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
2012-04-14 14:49:11 +00:00
|
|
|
public function testGetViewFileNameSubdirWithPluginAndViewPath() {
|
2012-04-14 14:24:12 +00:00
|
|
|
$this->PostsController->plugin = 'TestPlugin';
|
|
|
|
$this->PostsController->viewPath = 'Elements';
|
|
|
|
$this->PostsController->name = 'Posts';
|
|
|
|
$View = new TestView($this->PostsController);
|
2012-04-14 14:49:11 +00:00
|
|
|
|
2012-04-14 14:24:12 +00:00
|
|
|
$expected = CAKE . 'Test' . DS . 'test_app' . DS . 'Plugin' . DS . 'TestPlugin' .
|
|
|
|
DS . 'View' . DS . 'Elements' . DS . 'sub_dir' . DS . 'sub_element.ctp';
|
|
|
|
$this->assertEquals($expected, $View->getViewFileName('sub_dir/sub_element'));
|
|
|
|
}
|
|
|
|
|
2009-12-03 14:55:49 +00:00
|
|
|
/**
|
2013-07-27 04:51:30 +00:00
|
|
|
* Test that view vars can replace the local helper variables
|
2009-12-03 14:55:49 +00:00
|
|
|
* and not overwrite the $this->Helper references
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
2011-05-30 20:02:32 +00:00
|
|
|
public function testViewVarOverwritingLocalHelperVar() {
|
2010-04-24 04:22:21 +00:00
|
|
|
$Controller = new ViewPostsController();
|
2010-01-14 04:55:09 +00:00
|
|
|
$Controller->helpers = array('Session', 'Html');
|
2009-12-03 14:55:49 +00:00
|
|
|
$Controller->set('html', 'I am some test html');
|
2010-04-24 04:22:21 +00:00
|
|
|
$View = new View($Controller);
|
2009-12-03 14:55:49 +00:00
|
|
|
$result = $View->render('helper_overwrite', false);
|
|
|
|
|
2022-12-30 08:28:11 +00:00
|
|
|
$this->assertMatchesRegularExpression('/I am some test html/', $result);
|
|
|
|
$this->assertMatchesRegularExpression('/Test link/', $result);
|
2009-12-03 14:55:49 +00:00
|
|
|
}
|
|
|
|
|
2008-06-08 15:44:46 +00:00
|
|
|
/**
|
2013-07-27 04:51:30 +00:00
|
|
|
* Test getViewFileName method
|
2008-06-08 15:44:46 +00:00
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
2011-05-30 20:02:32 +00:00
|
|
|
public function testViewFileName() {
|
2010-04-24 04:22:21 +00:00
|
|
|
$View = new TestView($this->PostsController);
|
2008-06-08 15:44:46 +00:00
|
|
|
|
|
|
|
$result = $View->getViewFileName('index');
|
2022-12-30 08:28:11 +00:00
|
|
|
$this->assertMatchesRegularExpression('/Posts(\/|\\\)index.ctp/', $result);
|
2008-06-08 15:44:46 +00:00
|
|
|
|
2011-11-13 03:23:27 +00:00
|
|
|
$result = $View->getViewFileName('TestPlugin.index');
|
2022-12-30 08:28:11 +00:00
|
|
|
$this->assertMatchesRegularExpression('/Posts(\/|\\\)index.ctp/', $result);
|
2011-11-13 03:23:27 +00:00
|
|
|
|
2011-05-15 04:38:01 +00:00
|
|
|
$result = $View->getViewFileName('/Pages/home');
|
2022-12-30 08:28:11 +00:00
|
|
|
$this->assertMatchesRegularExpression('/Pages(\/|\\\)home.ctp/', $result);
|
2008-06-08 15:44:46 +00:00
|
|
|
|
2011-05-15 04:38:01 +00:00
|
|
|
$result = $View->getViewFileName('../Elements/test_element');
|
2022-12-30 08:28:11 +00:00
|
|
|
$this->assertMatchesRegularExpression('/Elements(\/|\\\)test_element.ctp/', $result);
|
2008-06-08 15:44:46 +00:00
|
|
|
|
2011-05-15 04:38:01 +00:00
|
|
|
$result = $View->getViewFileName('../Themed/TestTheme/Posts/index');
|
2022-12-30 08:28:11 +00:00
|
|
|
$this->assertMatchesRegularExpression('/Themed(\/|\\\)TestTheme(\/|\\\)Posts(\/|\\\)index.ctp/', $result);
|
2008-06-08 15:44:46 +00:00
|
|
|
|
2012-03-16 02:50:05 +00:00
|
|
|
$expected = CAKE . 'Test' . DS . 'test_app' . DS . 'View' . DS . 'Posts' . DS . 'index.ctp';
|
2011-05-13 07:45:04 +00:00
|
|
|
$result = $View->getViewFileName('../Posts/index');
|
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-26 05:26:10 +00:00
|
|
|
/**
|
2013-07-27 04:51:30 +00:00
|
|
|
* Test renderCache method
|
2008-06-26 05:26:10 +00:00
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
2011-05-30 20:02:32 +00:00
|
|
|
public function testRenderCache() {
|
2011-05-31 00:49:46 +00:00
|
|
|
$this->skipIf(!is_writable(CACHE . 'views' . DS), 'CACHE/views dir is not writable, cannot test renderCache.');
|
|
|
|
|
2008-05-30 11:40:08 +00:00
|
|
|
$view = 'test_view';
|
2010-04-24 04:22:21 +00:00
|
|
|
$View = new View($this->PostsController);
|
2010-08-27 03:24:09 +00:00
|
|
|
$path = CACHE . 'views' . DS . 'view_cache_' . $view;
|
2008-05-30 11:40:08 +00:00
|
|
|
|
2010-08-27 03:24:09 +00:00
|
|
|
$cacheText = '<!--cachetime:' . time() . '-->some cacheText';
|
2008-05-30 11:40:08 +00:00
|
|
|
$f = fopen($path, 'w+');
|
|
|
|
fwrite($f, $cacheText);
|
|
|
|
fclose($f);
|
|
|
|
|
|
|
|
$result = $View->renderCache($path, '+1 second');
|
|
|
|
$this->assertFalse($result);
|
2011-05-28 21:08:22 +00:00
|
|
|
if (file_exists($path)) {
|
|
|
|
unlink($path);
|
|
|
|
}
|
2008-05-30 11:40:08 +00:00
|
|
|
|
2010-08-27 03:24:09 +00:00
|
|
|
$cacheText = '<!--cachetime:' . (time() + 10) . '-->some cacheText';
|
2008-05-30 11:40:08 +00:00
|
|
|
$f = fopen($path, 'w+');
|
|
|
|
fwrite($f, $cacheText);
|
|
|
|
fclose($f);
|
2012-04-15 17:22:34 +00:00
|
|
|
$result = $View->renderCache($path, '+1 second');
|
2009-09-15 03:53:04 +00:00
|
|
|
|
2022-12-30 08:28:11 +00:00
|
|
|
$this->assertMatchesRegularExpression('/^some cacheText/', $result);
|
2009-09-15 03:53:04 +00:00
|
|
|
|
2012-11-14 09:00:15 +00:00
|
|
|
if (file_exists($path)) {
|
|
|
|
unlink($path);
|
|
|
|
}
|
2008-05-30 11:40:08 +00:00
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2010-09-29 03:03:56 +00:00
|
|
|
/**
|
|
|
|
* Test that render() will remove the cake:nocache tags when only the cachehelper is present.
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
2011-05-30 20:02:32 +00:00
|
|
|
public function testRenderStrippingNoCacheTagsOnlyCacheHelper() {
|
2010-09-29 03:03:56 +00:00
|
|
|
Configure::write('Cache.check', false);
|
2010-11-13 04:05:44 +00:00
|
|
|
$View = new View($this->PostsController);
|
2010-09-29 03:03:56 +00:00
|
|
|
$View->set(array('superman' => 'clark', 'variable' => 'var'));
|
|
|
|
$View->helpers = array('Html', 'Form', 'Cache');
|
|
|
|
$View->layout = 'cache_layout';
|
|
|
|
$result = $View->render('index');
|
2022-12-30 08:32:45 +00:00
|
|
|
$this->assertDoesNotMatchRegularExpression('/cake:nocache/', $result);
|
2010-09-29 03:03:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Test that render() will remove the cake:nocache tags when only the Cache.check is true.
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
2011-05-30 20:02:32 +00:00
|
|
|
public function testRenderStrippingNoCacheTagsOnlyCacheCheck() {
|
2010-09-29 03:03:56 +00:00
|
|
|
Configure::write('Cache.check', true);
|
2010-11-13 04:05:44 +00:00
|
|
|
$View = new View($this->PostsController);
|
2010-09-29 03:03:56 +00:00
|
|
|
$View->set(array('superman' => 'clark', 'variable' => 'var'));
|
|
|
|
$View->helpers = array('Html', 'Form');
|
|
|
|
$View->layout = 'cache_layout';
|
|
|
|
$result = $View->render('index');
|
2022-12-30 08:32:45 +00:00
|
|
|
$this->assertDoesNotMatchRegularExpression('/cake:nocache/', $result);
|
2010-09-29 03:03:56 +00:00
|
|
|
}
|
|
|
|
|
2008-06-05 15:20:45 +00:00
|
|
|
/**
|
|
|
|
* testSet method
|
2008-06-08 15:44:46 +00:00
|
|
|
*
|
2008-06-05 15:20:45 +00:00
|
|
|
* @return void
|
|
|
|
*/
|
2011-05-30 20:02:32 +00:00
|
|
|
public function testSet() {
|
2010-04-24 04:22:21 +00:00
|
|
|
$View = new TestView($this->PostsController);
|
2008-05-30 11:40:08 +00:00
|
|
|
$View->viewVars = array();
|
|
|
|
$View->set('somekey', 'someValue');
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertSame($View->viewVars, array('somekey' => 'someValue'));
|
|
|
|
$this->assertSame($View->getVars(), array('somekey'));
|
2008-05-30 11:40:08 +00:00
|
|
|
|
|
|
|
$View->viewVars = array();
|
|
|
|
$keys = array('key1', 'key2');
|
|
|
|
$values = array('value1', 'value2');
|
|
|
|
$View->set($keys, $values);
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertSame($View->viewVars, array('key1' => 'value1', 'key2' => 'value2'));
|
|
|
|
$this->assertSame($View->getVars(), array('key1', 'key2'));
|
|
|
|
$this->assertSame($View->getVar('key1'), 'value1');
|
2008-05-30 11:40:08 +00:00
|
|
|
$this->assertNull($View->getVar('key3'));
|
|
|
|
|
|
|
|
$View->set(array('key3' => 'value3'));
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertSame($View->getVar('key3'), 'value3');
|
2011-04-17 01:26:33 +00:00
|
|
|
|
2010-09-18 04:13:03 +00:00
|
|
|
$View->viewVars = array();
|
|
|
|
$View->set(array(3 => 'three', 4 => 'four'));
|
|
|
|
$View->set(array(1 => 'one', 2 => 'two'));
|
|
|
|
$expected = array(3 => 'three', 4 => 'four', 1 => 'one', 2 => 'two');
|
2012-03-23 06:37:12 +00:00
|
|
|
$this->assertEquals($expected, $View->viewVars);
|
2008-05-30 11:40:08 +00:00
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-06-05 15:20:45 +00:00
|
|
|
/**
|
|
|
|
* testBadExt method
|
2008-06-08 15:44:46 +00:00
|
|
|
*
|
2010-07-03 05:00:09 +00:00
|
|
|
* @expectedException MissingViewException
|
2008-06-05 15:20:45 +00:00
|
|
|
* @return void
|
|
|
|
*/
|
2011-05-30 20:02:32 +00:00
|
|
|
public function testBadExt() {
|
2008-05-30 11:40:08 +00:00
|
|
|
$this->PostsController->action = 'something';
|
|
|
|
$this->PostsController->ext = '.whatever';
|
2010-07-03 05:00:09 +00:00
|
|
|
|
2008-05-30 11:40:08 +00:00
|
|
|
$View = new TestView($this->PostsController);
|
|
|
|
$View->render('this_is_missing');
|
|
|
|
}
|
2011-03-25 10:57:25 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* testAltExt method
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
2011-05-30 20:02:32 +00:00
|
|
|
public function testAltExt() {
|
2011-03-25 10:57:25 +00:00
|
|
|
$this->PostsController->ext = '.alt';
|
|
|
|
$View = new TestView($this->PostsController);
|
|
|
|
$result = $View->render('alt_ext', false);
|
2012-03-23 06:37:12 +00:00
|
|
|
$this->assertEquals('alt ext', $result);
|
2011-03-25 10:57:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* testAltBadExt method
|
|
|
|
*
|
|
|
|
* @expectedException MissingViewException
|
|
|
|
* @return void
|
|
|
|
*/
|
2011-05-30 20:02:32 +00:00
|
|
|
public function testAltBadExt() {
|
2011-03-25 10:57:25 +00:00
|
|
|
$View = new TestView($this->PostsController);
|
|
|
|
$View->render('alt_ext');
|
|
|
|
}
|
2011-08-16 02:05:55 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Test creating a block with capturing output.
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function testBlockCapture() {
|
|
|
|
$this->View->start('test');
|
|
|
|
echo 'Block content';
|
|
|
|
$this->View->end();
|
|
|
|
|
2011-09-22 02:32:39 +00:00
|
|
|
$result = $this->View->fetch('test');
|
2011-08-16 02:05:55 +00:00
|
|
|
$this->assertEquals('Block content', $result);
|
|
|
|
}
|
|
|
|
|
2012-10-30 09:01:58 +00:00
|
|
|
/**
|
|
|
|
* Test block with startIfEmpty
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function testBlockCaptureStartIfEmpty() {
|
|
|
|
$this->View->startIfEmpty('test');
|
|
|
|
echo "Block content 1";
|
|
|
|
$this->View->end();
|
|
|
|
|
|
|
|
$this->View->startIfEmpty('test');
|
|
|
|
echo "Block content 2";
|
|
|
|
$this->View->end();
|
|
|
|
|
|
|
|
$result = $this->View->fetch('test');
|
|
|
|
$this->assertEquals('Block content 1', $result);
|
|
|
|
}
|
|
|
|
|
2012-11-18 15:30:47 +00:00
|
|
|
/**
|
|
|
|
* Test block with startIfEmpty
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function testBlockCaptureStartStartIfEmpty() {
|
|
|
|
$this->View->start('test');
|
|
|
|
echo "Block content 1";
|
|
|
|
$this->View->end();
|
|
|
|
|
|
|
|
$this->View->startIfEmpty('test');
|
|
|
|
echo "Block content 2";
|
|
|
|
$this->View->end();
|
|
|
|
|
|
|
|
$result = $this->View->fetch('test');
|
|
|
|
$this->assertEquals('Block content 1', $result);
|
|
|
|
}
|
|
|
|
|
2011-08-16 02:05:55 +00:00
|
|
|
/**
|
|
|
|
* Test appending to a block with capturing output.
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function testBlockCaptureAppend() {
|
|
|
|
$this->View->start('test');
|
|
|
|
echo 'Block';
|
|
|
|
$this->View->end();
|
|
|
|
|
|
|
|
$this->View->append('test');
|
|
|
|
echo ' content';
|
|
|
|
$this->View->end();
|
|
|
|
|
2011-09-22 02:32:39 +00:00
|
|
|
$result = $this->View->fetch('test');
|
2011-08-16 02:05:55 +00:00
|
|
|
$this->assertEquals('Block content', $result);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Test setting a block's content.
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function testBlockSet() {
|
2011-09-22 02:32:39 +00:00
|
|
|
$this->View->assign('test', 'Block content');
|
|
|
|
$result = $this->View->fetch('test');
|
2011-08-16 02:05:55 +00:00
|
|
|
$this->assertEquals('Block content', $result);
|
|
|
|
}
|
|
|
|
|
2013-07-19 23:06:27 +00:00
|
|
|
/**
|
|
|
|
* Test resetting a block's content.
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function testBlockReset() {
|
|
|
|
$this->View->assign('test', '');
|
|
|
|
$result = $this->View->fetch('test', 'This should not be returned');
|
|
|
|
$this->assertSame('', $result);
|
|
|
|
}
|
|
|
|
|
2014-12-11 14:44:11 +00:00
|
|
|
/**
|
|
|
|
* Test checking a block's existance.
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function testBlockExist() {
|
|
|
|
$this->assertFalse($this->View->exists('test'));
|
|
|
|
$this->View->assign('test', 'Block content');
|
|
|
|
$this->assertTrue($this->View->exists('test'));
|
|
|
|
}
|
|
|
|
|
2013-07-27 04:51:30 +00:00
|
|
|
/**
|
|
|
|
* Test setting a block's content to null
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function testBlockSetNull() {
|
|
|
|
$this->View->assign('testWithNull', null);
|
|
|
|
$result = $this->View->fetch('testWithNull');
|
|
|
|
$this->assertSame('', $result);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Test setting a block's content to an object with __toString magic method
|
2013-08-31 11:30:05 +00:00
|
|
|
*
|
2013-07-27 04:51:30 +00:00
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function testBlockSetObjectWithToString() {
|
|
|
|
$objectWithToString = new TestObjectWithToString();
|
|
|
|
$this->View->assign('testWithObjectWithToString', $objectWithToString);
|
|
|
|
$result = $this->View->fetch('testWithObjectWithToString');
|
|
|
|
$this->assertSame("I'm ObjectWithToString", $result);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Test setting a block's content to an object without __toString magic method
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function testBlockSetObjectWithoutToString() {
|
2019-12-05 10:52:16 +00:00
|
|
|
$this->_checkException(
|
|
|
|
'Object of class TestObjectWithoutToString could not be converted to string'
|
|
|
|
);
|
|
|
|
|
2013-07-27 04:51:30 +00:00
|
|
|
$objectWithToString = new TestObjectWithoutToString();
|
|
|
|
$this->View->assign('testWithObjectWithoutToString', $objectWithToString);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Test setting a block's content to a decimal
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function testBlockSetDecimal() {
|
|
|
|
$this->View->assign('testWithDecimal', 1.23456789);
|
|
|
|
$result = $this->View->fetch('testWithDecimal');
|
2013-09-25 18:58:29 +00:00
|
|
|
$this->assertEquals('1.23456789', $result);
|
2013-07-27 04:51:30 +00:00
|
|
|
}
|
|
|
|
|
2011-08-16 02:05:55 +00:00
|
|
|
/**
|
2013-08-30 19:36:18 +00:00
|
|
|
* Data provider for block related tests.
|
2011-08-16 02:05:55 +00:00
|
|
|
*
|
2013-08-30 19:36:18 +00:00
|
|
|
* @return array
|
2011-08-16 02:05:55 +00:00
|
|
|
*/
|
2013-08-30 19:36:18 +00:00
|
|
|
public static function blockValueProvider() {
|
|
|
|
return array(
|
|
|
|
'string' => array('A string value'),
|
|
|
|
'decimal' => array(1.23456),
|
|
|
|
'object with __toString' => array(new TestObjectWithToString()),
|
|
|
|
);
|
2011-08-16 02:05:55 +00:00
|
|
|
}
|
|
|
|
|
2012-09-30 12:48:32 +00:00
|
|
|
/**
|
2013-08-30 19:36:18 +00:00
|
|
|
* Test appending to a block with append.
|
2013-07-27 04:51:30 +00:00
|
|
|
*
|
2013-08-30 19:36:18 +00:00
|
|
|
* @dataProvider blockValueProvider
|
2013-07-27 04:51:30 +00:00
|
|
|
* @return void
|
|
|
|
*/
|
2013-08-30 19:36:18 +00:00
|
|
|
public function testBlockAppend($value) {
|
|
|
|
$this->View->assign('testBlock', 'Block');
|
|
|
|
$this->View->append('testBlock', $value);
|
2013-07-27 04:51:30 +00:00
|
|
|
|
2013-08-30 19:36:18 +00:00
|
|
|
$result = $this->View->fetch('testBlock');
|
|
|
|
$this->assertSame('Block' . $value, $result);
|
2013-07-27 04:51:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Test appending an object without __toString magic method to a block with append.
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function testBlockAppendObjectWithoutToString() {
|
2019-12-05 10:52:16 +00:00
|
|
|
$this->_checkException(
|
|
|
|
'Object of class TestObjectWithoutToString could not be converted to string'
|
|
|
|
);
|
|
|
|
|
2013-08-30 19:36:18 +00:00
|
|
|
$object = new TestObjectWithoutToString();
|
|
|
|
$this->View->assign('testBlock', 'Block ');
|
|
|
|
$this->View->append('testBlock', $object);
|
2013-07-27 04:51:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Test prepending to a block with prepend.
|
2013-08-31 11:30:05 +00:00
|
|
|
*
|
2013-08-30 19:36:18 +00:00
|
|
|
* @dataProvider blockValueProvider
|
2012-09-30 12:48:32 +00:00
|
|
|
* @return void
|
|
|
|
*/
|
2013-08-30 19:36:18 +00:00
|
|
|
public function testBlockPrepend($value) {
|
2012-09-30 12:48:32 +00:00
|
|
|
$this->View->assign('test', 'Block');
|
2013-08-30 19:36:18 +00:00
|
|
|
$this->View->prepend('test', $value);
|
2012-09-30 12:48:32 +00:00
|
|
|
|
|
|
|
$result = $this->View->fetch('test');
|
2013-08-30 19:36:18 +00:00
|
|
|
$this->assertEquals($value . 'Block', $result);
|
2012-09-30 12:48:32 +00:00
|
|
|
}
|
2013-08-31 11:30:05 +00:00
|
|
|
|
2011-08-16 02:05:55 +00:00
|
|
|
/**
|
2013-07-27 04:51:30 +00:00
|
|
|
* Test prepending an object without __toString magic method to a block with prepend.
|
2011-08-17 01:10:23 +00:00
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
2013-07-27 04:51:30 +00:00
|
|
|
public function testBlockPrependObjectWithoutToString() {
|
2019-12-05 10:52:16 +00:00
|
|
|
$this->_checkException(
|
|
|
|
'Object of class TestObjectWithoutToString could not be converted to string'
|
|
|
|
);
|
|
|
|
|
2013-08-30 19:36:18 +00:00
|
|
|
$object = new TestObjectWithoutToString();
|
|
|
|
$this->View->assign('test', 'Block ');
|
|
|
|
$this->View->prepend('test', $object);
|
2013-07-27 04:51:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* You should be able to append to undefined blocks.
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function testBlockAppendUndefined() {
|
|
|
|
$this->View->append('test', 'Unknown');
|
|
|
|
$result = $this->View->fetch('test');
|
|
|
|
$this->assertEquals('Unknown', $result);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* You should be able to prepend to undefined blocks.
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function testBlockPrependUndefined() {
|
|
|
|
$this->View->prepend('test', 'Unknown');
|
|
|
|
$result = $this->View->fetch('test');
|
|
|
|
$this->assertEquals('Unknown', $result);
|
2011-08-16 02:05:55 +00:00
|
|
|
}
|
2011-08-17 01:23:09 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Test getting block names
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function testBlocks() {
|
|
|
|
$this->View->append('test', 'one');
|
2011-09-22 02:32:39 +00:00
|
|
|
$this->View->assign('test1', 'one');
|
2011-08-17 01:23:09 +00:00
|
|
|
|
|
|
|
$this->assertEquals(array('test', 'test1'), $this->View->blocks());
|
|
|
|
}
|
2011-09-23 01:07:21 +00:00
|
|
|
|
2011-12-13 03:08:03 +00:00
|
|
|
/**
|
|
|
|
* Test that blocks can be nested.
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function testNestedBlocks() {
|
|
|
|
$this->View->start('first');
|
|
|
|
echo 'In first ';
|
|
|
|
$this->View->start('second');
|
|
|
|
echo 'In second';
|
|
|
|
$this->View->end();
|
|
|
|
echo 'In first';
|
|
|
|
$this->View->end();
|
|
|
|
|
|
|
|
$this->assertEquals('In first In first', $this->View->fetch('first'));
|
|
|
|
$this->assertEquals('In second', $this->View->fetch('second'));
|
|
|
|
}
|
|
|
|
|
2013-10-25 19:43:53 +00:00
|
|
|
/**
|
|
|
|
* Test that starting the same block twice throws an exception
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function testStartBlocksTwice() {
|
2017-03-25 11:18:12 +00:00
|
|
|
try {
|
|
|
|
$this->View->start('first');
|
|
|
|
$this->View->start('first');
|
|
|
|
$this->fail('No exception');
|
|
|
|
} catch (CakeException $e) {
|
|
|
|
ob_end_clean();
|
|
|
|
$this->assertTrue(true);
|
|
|
|
}
|
2013-10-25 19:43:53 +00:00
|
|
|
}
|
|
|
|
|
2011-12-13 02:43:41 +00:00
|
|
|
/**
|
|
|
|
* Test that an exception gets thrown when you leave a block open at the end
|
|
|
|
* of a view.
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function testExceptionOnOpenBlock() {
|
2017-03-25 11:18:12 +00:00
|
|
|
try {
|
|
|
|
$this->View->render('open_block');
|
|
|
|
$this->fail('No exception');
|
|
|
|
} catch (CakeException $e) {
|
|
|
|
ob_end_clean();
|
2022-12-30 08:53:58 +00:00
|
|
|
$this->assertStringContainsString('The "no_close" block was left open', $e->getMessage());
|
2017-03-25 11:18:12 +00:00
|
|
|
}
|
2011-12-13 02:43:41 +00:00
|
|
|
}
|
|
|
|
|
2011-09-23 01:07:21 +00:00
|
|
|
/**
|
|
|
|
* Test nested extended views.
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function testExtendNested() {
|
|
|
|
$this->View->layout = false;
|
|
|
|
$content = $this->View->render('nested_extends');
|
|
|
|
$expected = <<<TEXT
|
|
|
|
This is the second parent.
|
|
|
|
This is the first parent.
|
|
|
|
This is the first template.
|
|
|
|
Sidebar Content.
|
2011-09-26 01:52:11 +00:00
|
|
|
TEXT;
|
|
|
|
$this->assertEquals($expected, $content);
|
|
|
|
}
|
|
|
|
|
2011-12-24 04:56:48 +00:00
|
|
|
/**
|
|
|
|
* Make sure that extending the current view with itself causes an exception
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function testExtendSelf() {
|
2017-03-25 11:18:12 +00:00
|
|
|
try {
|
|
|
|
$this->View->layout = false;
|
|
|
|
$this->View->render('extend_self');
|
|
|
|
$this->fail('No exception');
|
|
|
|
} catch (LogicException $e) {
|
|
|
|
ob_end_clean();
|
2022-12-30 08:53:58 +00:00
|
|
|
$this->assertStringContainsString('cannot have views extend themselves', $e->getMessage());
|
2017-03-25 11:18:12 +00:00
|
|
|
}
|
2011-12-24 04:56:48 +00:00
|
|
|
}
|
|
|
|
|
2011-12-24 05:03:51 +00:00
|
|
|
/**
|
|
|
|
* Make sure that extending in a loop causes an exception
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function testExtendLoop() {
|
2017-03-25 11:18:12 +00:00
|
|
|
try {
|
|
|
|
$this->View->layout = false;
|
|
|
|
$this->View->render('extend_loop');
|
|
|
|
$this->fail('No exception');
|
|
|
|
} catch (LogicException $e) {
|
|
|
|
ob_end_clean();
|
2022-12-30 08:53:58 +00:00
|
|
|
$this->assertStringContainsString('cannot have views extend in a loop', $e->getMessage());
|
2017-03-25 11:18:12 +00:00
|
|
|
}
|
2011-12-24 05:03:51 +00:00
|
|
|
}
|
|
|
|
|
2011-09-26 01:52:11 +00:00
|
|
|
/**
|
|
|
|
* Test extend() in an element and a view.
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function testExtendElement() {
|
|
|
|
$this->View->layout = false;
|
|
|
|
$content = $this->View->render('extend_element');
|
|
|
|
$expected = <<<TEXT
|
|
|
|
Parent View.
|
|
|
|
View content.
|
|
|
|
Parent Element.
|
|
|
|
Element content.
|
2011-09-23 01:07:21 +00:00
|
|
|
|
|
|
|
TEXT;
|
|
|
|
$this->assertEquals($expected, $content);
|
|
|
|
}
|
2012-01-10 02:47:57 +00:00
|
|
|
|
2012-01-25 11:43:55 +00:00
|
|
|
/**
|
|
|
|
* Extending an element which doesn't exist should throw a missing view exception
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function testExtendMissingElement() {
|
2017-03-25 11:18:12 +00:00
|
|
|
try {
|
|
|
|
$this->View->layout = false;
|
|
|
|
$this->View->render('extend_missing_element');
|
|
|
|
$this->fail('No exception');
|
|
|
|
} catch (LogicException $e) {
|
|
|
|
ob_end_clean();
|
|
|
|
ob_end_clean();
|
2022-12-30 08:53:58 +00:00
|
|
|
$this->assertStringContainsString('element', $e->getMessage());
|
2017-03-25 11:18:12 +00:00
|
|
|
}
|
2012-01-25 11:43:55 +00:00
|
|
|
}
|
|
|
|
|
2012-10-01 02:44:27 +00:00
|
|
|
/**
|
|
|
|
* Test extend() preceeded by an element()
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function testExtendWithElementBeforeExtend() {
|
|
|
|
$this->View->layout = false;
|
|
|
|
$result = $this->View->render('extend_with_element');
|
|
|
|
$expected = <<<TEXT
|
|
|
|
Parent View.
|
|
|
|
this is the test elementThe view
|
|
|
|
|
|
|
|
TEXT;
|
|
|
|
$this->assertEquals($expected, $result);
|
|
|
|
}
|
|
|
|
|
2012-01-12 10:48:51 +00:00
|
|
|
/**
|
|
|
|
* Test that setting arbitrary properties still works.
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function testPropertySettingMagicGet() {
|
|
|
|
$this->assertFalse(isset($this->View->action));
|
|
|
|
$this->View->request->params['action'] = 'login';
|
|
|
|
$this->assertEquals('login', $this->View->action);
|
|
|
|
$this->assertTrue(isset($this->View->action));
|
|
|
|
$this->assertTrue(!empty($this->View->action));
|
|
|
|
}
|
2012-01-22 20:45:26 +00:00
|
|
|
|
|
|
|
/**
|
2013-07-27 04:51:30 +00:00
|
|
|
* Test memory leaks that existed in _paths at one point.
|
2012-01-22 20:45:26 +00:00
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function testMemoryLeakInPaths() {
|
|
|
|
$this->ThemeController->plugin = null;
|
|
|
|
$this->ThemeController->name = 'Posts';
|
|
|
|
$this->ThemeController->viewPath = 'posts';
|
|
|
|
$this->ThemeController->layout = 'whatever';
|
|
|
|
$this->ThemeController->theme = 'TestTheme';
|
|
|
|
|
|
|
|
$View = new View($this->ThemeController);
|
|
|
|
$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);
|
|
|
|
}
|
2012-09-13 22:35:11 +00:00
|
|
|
|
|
|
|
/**
|
2013-09-11 14:22:50 +00:00
|
|
|
* Tests that a view block uses default value when not assigned and uses assigned value when it is
|
2012-09-13 22:35:11 +00:00
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function testBlockDefaultValue() {
|
|
|
|
$default = 'Default';
|
|
|
|
$result = $this->View->fetch('title', $default);
|
2012-09-18 07:46:06 +00:00
|
|
|
$this->assertEquals($default, $result);
|
2012-09-13 22:35:11 +00:00
|
|
|
|
|
|
|
$expected = 'My Title';
|
|
|
|
$this->View->assign('title', $expected);
|
|
|
|
$result = $this->View->fetch('title', $default);
|
2012-09-18 07:46:06 +00:00
|
|
|
$this->assertEquals($expected, $result);
|
2012-09-13 22:35:11 +00:00
|
|
|
}
|
2013-09-11 14:22:50 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Tests that a view variable uses default value when not assigned and uses assigned value when it is
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function testViewVarDefaultValue() {
|
|
|
|
$default = 'Default';
|
|
|
|
$result = $this->View->get('title', $default);
|
|
|
|
$this->assertEquals($default, $result);
|
|
|
|
|
|
|
|
$expected = 'Back to the Future';
|
|
|
|
$this->View->set('title', $expected);
|
|
|
|
$result = $this->View->get('title', $default);
|
|
|
|
$this->assertEquals($expected, $result);
|
|
|
|
}
|
2019-12-05 10:52:16 +00:00
|
|
|
|
|
|
|
protected function _checkException($message) {
|
|
|
|
if (version_compare(PHP_VERSION, '7.4', '>=')) {
|
|
|
|
$this->setExpectedException('Error', $message);
|
|
|
|
} else {
|
|
|
|
$this->setExpectedException('PHPUnit_Framework_Error', $message);
|
|
|
|
}
|
|
|
|
}
|
2008-05-30 11:40:08 +00:00
|
|
|
}
|