* 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.controller * @since CakePHP(tm) v 1.2.0.5436 * @version $Revision$ * @modifiedby $LastChangedBy$ * @lastmodified $Date$ * @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 */ var $name = 'ScaffoldMock'; /** * scaffold property * * @var mixed * @access public */ var $scaffold; } /** * ScaffoldMock class * * @package cake * @subpackage cake.tests.cases.libs.controller */ class ScaffoldMock extends CakeTestModel { /** * useTable property * * @var string 'posts' * @access public */ var $useTable = 'articles'; /** * belongsTo property * * @var array * @access public */ var $belongsTo = array( 'User' => array( 'className' => 'ScaffoldUser', 'foreignKey' => 'user_id', ) ); /** * hasMany property * * @var array * @access public */ var $hasMany = array( 'Comment' => array( 'className' => 'ScaffoldComment', 'foreignKey' => 'article_id', ) ); } /** * ScaffoldAuthor class * * @package cake * @subpackage cake.tests.cases.libs.controller */ class ScaffoldUser extends CakeTestModel { /** * useTable property * * @var string 'posts' * @access public */ var $useTable = 'users'; /** * hasMany property * * @var array * @access public */ var $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 */ var $useTable = 'comments'; /** * belongsTo property * * @var array * @access public */ var $belongsTo = array( 'Article' => array( 'className' => 'ScaffoldMock', 'foreignKey' => 'article_id', ) ); } /** * 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); } } /** * Short description for class. * * @package cake.tests * @subpackage cake.tests.cases.libs.controller */ class ScaffoldViewTest extends CakeTestCase { /** * fixtures property * * @var array * @access public */ var $fixtures = array('core.article', 'core.user', 'core.comment'); /** * setUp method * * @access public * @return void */ function setUp() { $this->Controller =& new ScaffoldMockController(); } /** * testGetViewFilename method * * @access public * @return void */ function testGetViewFilename() { $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('error'); $expected = 'cake' . DS . 'libs' . DS . 'view' . DS . 'errors' . DS . 'scaffold_error.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::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('/