* Copyright 2005-2010, Cake Software Foundation, Inc. (http://cakefoundation.org) * * Licensed under The Open Group Test Suite License * Redistributions of files must retain the above copyright notice. * * @copyright Copyright 2005-2010, Cake Software Foundation, Inc. (http://cakefoundation.org) * @link https://trac.cakephp.org/wiki/Developement/TestSuite CakePHP(tm) Tests * @package cake * @subpackage cake.tests.cases.libs.controller * @since CakePHP(tm) v 1.2.0.5436 * @license http://www.opensource.org/licenses/opengroup.php The Open Group Test Suite License */ App::import('Core', 'Scaffold'); /** * ScaffoldMockController class * * @package cake * @subpackage cake.tests.cases.libs.controller */ class ScaffoldMockController extends Controller { /** * name property * * @var string 'ScaffoldMock' * @access public */ public $name = 'ScaffoldMock'; /** * scaffold property * * @var mixed * @access public */ public $scaffold; } /** * ScaffoldMockControllerWithFields class * * @package cake * @subpackage cake.tests.cases.libs.controller */ class ScaffoldMockControllerWithFields extends Controller { /** * name property * * @var string 'ScaffoldMock' * @access public */ public $name = 'ScaffoldMock'; /** * scaffold property * * @var mixed * @access public */ public $scaffold; /** * function _beforeScaffold * * @param string method */ function _beforeScaffold($method) { $this->set('scaffoldFields', array('title')); return true; } } /** * TestScaffoldMock class * * @package cake * @subpackage cake.tests.cases.libs.controller */ class TestScaffoldMock extends Scaffold { /** * Overload __scaffold * * @param unknown_type $params */ function __scaffold($params) { $this->_params = $params; } /** * Get Params from the Controller. * * @return unknown */ function getParams() { return $this->_params; } } /** * ScaffoldMock class * * @package cake * @subpackage cake.tests.cases.libs.controller */ class ScaffoldMock extends CakeTestModel { /** * useTable property * * @var string 'posts' * @access public */ public $useTable = 'articles'; /** * belongsTo property * * @var array * @access public */ public $belongsTo = array( 'User' => array( 'className' => 'ScaffoldUser', 'foreignKey' => 'user_id', ) ); /** * hasMany property * * @var array * @access public */ public $hasMany = array( 'Comment' => array( 'className' => 'ScaffoldComment', 'foreignKey' => 'article_id', ) ); /** * hasAndBelongsToMany property * * @var string */ public $hasAndBelongsToMany = array( 'ScaffoldTag' => array( 'className' => 'ScaffoldTag', 'foreignKey' => 'something_id', 'associationForeignKey' => 'something_else_id', 'joinTable' => 'join_things' ) ); } /** * ScaffoldUser class * * @package cake * @subpackage cake.tests.cases.libs.controller */ class ScaffoldUser extends CakeTestModel { /** * useTable property * * @var string 'posts' * @access public */ public $useTable = 'users'; /** * hasMany property * * @var array * @access public */ public $hasMany = array( 'Article' => array( 'className' => 'ScaffoldMock', 'foreignKey' => 'article_id', ) ); } /** * ScaffoldComment class * * @package cake * @subpackage cake.tests.cases.libs.controller */ class ScaffoldComment extends CakeTestModel { /** * useTable property * * @var string 'posts' * @access public */ public $useTable = 'comments'; /** * belongsTo property * * @var array * @access public */ public $belongsTo = array( 'Article' => array( 'className' => 'ScaffoldMock', 'foreignKey' => 'article_id', ) ); } /** * ScaffoldTag class * * @package cake * @subpackage cake.tests.cases.libs.controller */ class ScaffoldTag extends CakeTestModel { /** * useTable property * * @var string 'posts' * @access public */ public $useTable = 'tags'; } /** * TestScaffoldView class * * @package cake * @subpackage cake.tests.cases.libs.controller */ class TestScaffoldView extends ScaffoldView { /** * testGetFilename method * * @param mixed $action * @access public * @return void */ function testGetFilename($action) { return $this->_getViewFileName($action); } } /** * ScaffoldViewTest class * * @package cake * @subpackage cake.tests.cases.libs.controller */ class ScaffoldViewTest extends CakeTestCase { /** * fixtures property * * @var array * @access public */ public $fixtures = array('core.article', 'core.user', 'core.comment', 'core.join_thing', 'core.tag'); /** * startTest method * * @access public * @return void */ function startTest() { $this->Controller =& new ScaffoldMockController(); App::build(array( 'views' => array(TEST_CAKE_CORE_INCLUDE_PATH . 'tests' . DS . 'test_app' . DS . 'views' . DS), 'plugins' => array(TEST_CAKE_CORE_INCLUDE_PATH . 'tests' . DS . 'test_app' . DS . 'plugins' . DS) )); } /** * endTest method * * @access public * @return void */ function endTest() { unset($this->Controller); App::build(); } /** * testGetViewFilename method * * @access public * @return void */ function testGetViewFilename() { $_admin = Configure::read('Routing.prefixes'); Configure::write('Routing.prefixes', array('admin')); $this->Controller->action = 'index'; $ScaffoldView =& new TestScaffoldView($this->Controller); $result = $ScaffoldView->testGetFilename('index'); $expected = TEST_CAKE_CORE_INCLUDE_PATH . 'libs' . DS . 'view' . DS . 'scaffolds' . DS . 'index.ctp'; $this->assertEqual($result, $expected); $result = $ScaffoldView->testGetFilename('edit'); $expected = TEST_CAKE_CORE_INCLUDE_PATH . 'libs' . DS . 'view' . DS . 'scaffolds' . DS . 'edit.ctp'; $this->assertEqual($result, $expected); $result = $ScaffoldView->testGetFilename('add'); $expected = TEST_CAKE_CORE_INCLUDE_PATH . 'libs' . DS . 'view' . DS . 'scaffolds' . DS . 'edit.ctp'; $this->assertEqual($result, $expected); $result = $ScaffoldView->testGetFilename('view'); $expected = TEST_CAKE_CORE_INCLUDE_PATH . 'libs' . DS . 'view' . DS . 'scaffolds' . DS . 'view.ctp'; $this->assertEqual($result, $expected); $result = $ScaffoldView->testGetFilename('admin_index'); $expected = TEST_CAKE_CORE_INCLUDE_PATH . 'libs' . DS . 'view' . DS . 'scaffolds' . DS . 'index.ctp'; $this->assertEqual($result, $expected); $result = $ScaffoldView->testGetFilename('admin_view'); $expected = TEST_CAKE_CORE_INCLUDE_PATH . 'libs' . DS . 'view' . DS . 'scaffolds' . DS . 'view.ctp'; $this->assertEqual($result, $expected); $result = $ScaffoldView->testGetFilename('admin_edit'); $expected = TEST_CAKE_CORE_INCLUDE_PATH . 'libs' . DS . 'view' . DS . 'scaffolds' . DS . 'edit.ctp'; $this->assertEqual($result, $expected); $result = $ScaffoldView->testGetFilename('admin_add'); $expected = TEST_CAKE_CORE_INCLUDE_PATH . 'libs' . DS . 'view' . DS . 'scaffolds' . DS . 'edit.ctp'; $this->assertEqual($result, $expected); $result = $ScaffoldView->testGetFilename('error'); $expected = 'cake' . DS . 'libs' . DS . 'view' . DS . 'errors' . DS . 'scaffold_error.ctp'; $this->assertEqual($result, $expected); $Controller =& new ScaffoldMockController(); $Controller->scaffold = 'admin'; $Controller->viewPath = 'posts'; $Controller->action = 'admin_edit'; $ScaffoldView =& new TestScaffoldView($Controller); $result = $ScaffoldView->testGetFilename('admin_edit'); $expected = TEST_CAKE_CORE_INCLUDE_PATH . 'tests' . DS . 'test_app' .DS . 'views' . DS . 'posts' . DS . 'scaffold.edit.ctp'; $this->assertEqual($result, $expected); $result = $ScaffoldView->testGetFilename('edit'); $expected = TEST_CAKE_CORE_INCLUDE_PATH . 'tests' . DS . 'test_app' .DS . 'views' . DS . 'posts' . DS . 'scaffold.edit.ctp'; $this->assertEqual($result, $expected); $Controller =& new ScaffoldMockController(); $Controller->scaffold = 'admin'; $Controller->viewPath = 'tests'; $Controller->plugin = 'test_plugin'; $Controller->action = 'admin_add'; $ScaffoldView =& new TestScaffoldView($Controller); $result = $ScaffoldView->testGetFilename('admin_add'); $expected = TEST_CAKE_CORE_INCLUDE_PATH . 'tests' . DS . 'test_app' . DS . 'plugins' . DS .'test_plugin' . DS . 'views' . DS . 'tests' . DS . 'scaffold.edit.ctp'; $this->assertEqual($result, $expected); $result = $ScaffoldView->testGetFilename('add'); $expected = TEST_CAKE_CORE_INCLUDE_PATH . 'tests' . DS . 'test_app' . DS . 'plugins' . DS .'test_plugin' . DS . 'views' . DS . 'tests' . DS . 'scaffold.edit.ctp'; $this->assertEqual($result, $expected); Configure::write('Routing.prefixes', $_admin); } /** * test getting the view file name for themed scaffolds. * * @return void */ function testGetViewFileNameWithTheme() { $this->Controller->action = 'index'; $this->Controller->viewPath = 'posts'; $this->Controller->theme = 'test_theme'; $ScaffoldView =& new TestScaffoldView($this->Controller); $result = $ScaffoldView->testGetFilename('index'); $expected = TEST_CAKE_CORE_INCLUDE_PATH . 'tests' . DS . 'test_app' . DS . 'views' . DS . 'themed' . DS . 'test_theme' . DS . 'posts' . DS . 'scaffold.index.ctp'; $this->assertEqual($result, $expected); } /** * test default index scaffold generation * * @access public * @return void */ function testIndexScaffold() { $this->Controller->action = 'index'; $this->Controller->here = '/scaffold_mock'; $this->Controller->webroot = '/'; $params = array( 'plugin' => null, 'pass' => array(), 'form' => array(), 'named' => array(), 'url' => array('url' =>'scaffold_mock'), 'controller' => 'scaffold_mock', 'action' => 'index', ); //set router. Router::reload(); Router::setRequestInfo(array($params, array('base' => '/', 'here' => '/scaffold_mock', 'webroot' => '/'))); $this->Controller->params = $params; $this->Controller->controller = 'scaffold_mock'; $this->Controller->base = '/'; $this->Controller->constructClasses(); ob_start(); new Scaffold($this->Controller, $params); $result = ob_get_clean(); $this->assertPattern('#