⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 view.test.php

📁 Cake Framwork , Excellent
💻 PHP
📖 第 1 页 / 共 2 页
字号:
<?php/* SVN FILE: $Id: view.test.php 7118 2008-06-04 20:49:29Z gwoo $ *//** * Short description for file. * * Long description for file * * PHP versions 4 and 5 * * CakePHP(tm) Tests <https://trac.cakephp.org/wiki/Developement/TestSuite> * Copyright 2005-2008, Cake Software Foundation, Inc. *								1785 E. Sahara Avenue, Suite 490-204 *								Las Vegas, Nevada 89104 * *  Licensed under The Open Group Test Suite License *  Redistributions of files must retain the above copyright notice. * * @filesource * @copyright		Copyright 2005-2008, Cake Software Foundation, Inc. * @link				https://trac.cakephp.org/wiki/Developement/TestSuite CakePHP(tm) Tests * @package			cake.tests * @subpackage		cake.tests.cases.libs * @since			CakePHP(tm) v 1.2.0.4206 * @version			$Revision: 7118 $ * @modifiedby		$LastChangedBy: gwoo $ * @lastmodified	$Date: 2008-06-04 13:49:29 -0700 (Wed, 04 Jun 2008) $ * @license			http://www.opensource.org/licenses/opengroup.php The Open Group Test Suite License */App::import('Core', array('View', 'Controller', 'Error'));if (!defined('CAKEPHP_UNIT_TEST_EXECUTION')) {	define('CAKEPHP_UNIT_TEST_EXECUTION', 1);}/** * ViewPostsController class *  * @package              cake * @subpackage           cake.tests.cases.libs.view */class ViewPostsController extends Controller {/** * name property *  * @var string 'Posts' * @access public */	var $name = 'Posts';/** * uses property *  * @var mixed null * @access public */	var $uses = null;/** * index method *  * @access public * @return void */	function index() {		$this->set('testData', 'Some test data');		$test2 = 'more data';		$test3 = 'even more data';		$this->set(compact('test2', 'test3'));	}}/** * ViewTestErrorHandler class *  * @package              cake * @subpackage           cake.tests.cases.libs.view */class ViewTestErrorHandler extends ErrorHandler {/** * stop method *  * @access public * @return void */	function _stop() {		return;	}}/** * TestView class *  * @package              cake * @subpackage           cake.tests.cases.libs.view */class TestView extends View {/** * renderElement method *  * @param mixed $name  * @param array $params  * @access public * @return void */	function renderElement($name, $params = array()) {		return $name;	}/** * getViewFileName method *  * @param mixed $name  * @access public * @return void */	function getViewFileName($name = null) {		return $this->_getViewFileName($name);	}/** * getLayoutFileName method *  * @param mixed $name  * @access public * @return void */	function getLayoutFileName($name = null) {		return $this->_getLayoutFileName($name);	}/** * loadHelpers method *  * @param mixed $loaded  * @param mixed $helpers  * @param mixed $parent  * @access public * @return void */	function loadHelpers(&$loaded, $helpers, $parent = null) {		return $this->_loadHelpers($loaded, $helpers, $parent);	}/** * cakeError method *  * @param mixed $method  * @param mixed $messages  * @access public * @return void */	function cakeError($method, $messages) {		$error =& new ViewTestErrorHandler($method, $messages);		return $error;	}}/** * TestAfterHelper class *  * @package              cake * @subpackage           cake.tests.cases.libs.view */class TestAfterHelper extends Helper {/** * property property *  * @var string '' * @access public */	var $property = '';/** * beforeLayout method *  * @access public * @return void */	function beforeLayout() {		$this->property = 'Valuation';	}/** * afterLayout method *  * @access public * @return void */	function afterLayout() {		$View =& ClassRegistry::getObject('afterView');		$View->output .= 'modified in the afterlife';	}}/** * Short description for class. * * @package		cake.tests * @subpackage	cake.tests.cases.libs */class ViewTest extends CakeTestCase {/** * setUp method *  * @access public * @return void */	function setUp() {		Router::reload();		$this->Controller = new Controller();		$this->PostsController = new ViewPostsController();		$this->PostsController->viewPath = 'posts';		$this->PostsController->index();		$this->View = new View($this->PostsController);	}/** * testPluginGetTemplate method *  * @access public * @return void */	function testPluginGetTemplate() {		$this->Controller->plugin = 'test_plugin';		$this->Controller->name = 'TestPlugin';		$this->Controller->viewPath = 'test_plugin';		$this->Controller->action = 'index';		$View = new TestView($this->Controller);		Configure::write('pluginPaths', array(TEST_CAKE_CORE_INCLUDE_PATH . 'tests' . DS . 'test_app' . DS . 'plugins' . DS));		Configure::write('viewPaths', array(TEST_CAKE_CORE_INCLUDE_PATH . 'tests' . DS . 'test_app' . DS . 'views'. DS));		$expected = TEST_CAKE_CORE_INCLUDE_PATH . 'tests' . DS . 'test_app' . DS . 'plugins' . DS .'test_plugin' . DS . 'views' . DS .'test_plugin' . DS .'index.ctp';		$result = $View->getViewFileName('index');		$this->assertEqual($result, $expected);		$expected = TEST_CAKE_CORE_INCLUDE_PATH . 'tests' . DS . 'test_app' . DS . 'plugins' . DS .'test_plugin' . DS . 'views' . DS . 'layouts' . DS .'default.ctp';		$result = $View->getLayoutFileName();		$this->assertEqual($result, $expected);	}/** * testGetTemplate method *  * @access public * @return void */	function testGetTemplate() {		$this->Controller->plugin = null;		$this->Controller->name = 'Pages';		$this->Controller->viewPath = 'pages';		$this->Controller->action = 'display';		$this->Controller->params['pass'] = array('home');		$View = new TestView($this->Controller);		Configure::write('pluginPaths', array(TEST_CAKE_CORE_INCLUDE_PATH . 'tests' . DS . 'test_app' . DS . 'plugins' . DS));		Configure::write('viewPaths', array(TEST_CAKE_CORE_INCLUDE_PATH . 'tests' . DS . 'test_app' . DS . 'views'. DS, TEST_CAKE_CORE_INCLUDE_PATH . 'libs' . DS . 'view' . DS));		$expected = TEST_CAKE_CORE_INCLUDE_PATH . 'tests' . DS . 'test_app' . DS . 'views' . DS .'pages' . DS .'home.ctp';		$result = $View->getViewFileName('home');		$this->assertEqual($result, $expected);		$expected = TEST_CAKE_CORE_INCLUDE_PATH . 'tests' . DS . 'test_app' . DS . 'views' . DS .'posts' . DS .'index.ctp';		$result = $View->getViewFileName('/posts/index');		$this->assertEqual($result, $expected);		$expected = TEST_CAKE_CORE_INCLUDE_PATH . 'tests' . DS . 'test_app' . DS . 'views' . DS . 'layouts' . DS .'default.ctp';		$result = $View->getLayoutFileName();		$this->assertEqual($result, $expected);		$View->layoutPath = 'rss';		$expected = TEST_CAKE_CORE_INCLUDE_PATH . 'tests' . DS . 'test_app' . DS . 'views' . DS . 'layouts' . DS . 'rss' . DS . 'default.ctp';		$result = $View->getLayoutFileName();		$this->assertEqual($result, $expected);		$View->layoutPath = 'email' . DS . 'html';		$expected = TEST_CAKE_CORE_INCLUDE_PATH . 'libs' . DS . 'view' . DS . 'layouts' . DS . 'email' . DS . 'html' . DS . 'default.ctp';		$result = $View->getLayoutFileName();		$this->assertEqual($result, $expected);	}/** * testMissingView method *  * @access public * @return void */	function testMissingView() {		$this->Controller->plugin = null;		$this->Controller->name = 'Pages';		$this->Controller->viewPath = 'pages';		$this->Controller->action = 'display';		$this->Controller->params['pass'] = array('home');		$View = new TestView($this->Controller);		ob_start();		$result = $View->getViewFileName('does_not_exist');		$expected = str_replace(array("\t", "\r\n", "\n"), "", ob_get_clean());		$this->assertPattern("/PagesController::/", $expected);		$this->assertPattern("/pages\/does_not_exist.ctp/", $expected);	}/** * testMissingLayout method *  * @access public * @return void */	function testMissingLayout() {		$this->Controller->plugin = null;		$this->Controller->name = 'Posts';		$this->Controller->viewPath = 'posts';		$this->Controller->layout = 'whatever';		$View = new TestView($this->Controller);		ob_start();		$result = $View->getLayoutFileName();		$expected = str_replace(array("\t", "\r\n", "\n"), "", ob_get_clean());		$this->assertPattern("/Missing Layout/", $expected);		$this->assertPattern("/layouts\/whatever.ctp/", $expected);	}/** * testViewVars method *  * @access public * @return void */

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -