2008-05-30 11:40:08 +00:00
|
|
|
<?php
|
|
|
|
/**
|
2009-03-18 17:55:58 +00:00
|
|
|
* ScaffoldTest file
|
2008-05-30 11:40:08 +00:00
|
|
|
*
|
2010-10-03 16:31:21 +00:00
|
|
|
* PHP 5
|
2008-05-30 11:40:08 +00:00
|
|
|
*
|
2010-05-19 01:15:13 +00:00
|
|
|
* CakePHP(tm) Tests <http://book.cakephp.org/view/1196/Testing>
|
2010-01-26 19:18:20 +00:00
|
|
|
* Copyright 2005-2010, Cake Software Foundation, Inc. (http://cakefoundation.org)
|
2008-05-30 11:40:08 +00:00
|
|
|
*
|
2010-10-03 16:31:21 +00:00
|
|
|
* Licensed under The MIT License
|
|
|
|
* Redistributions of files must retain the above copyright notice
|
2008-05-30 11:40:08 +00:00
|
|
|
*
|
2010-01-26 19:18:20 +00:00
|
|
|
* @copyright Copyright 2005-2010, Cake Software Foundation, Inc. (http://cakefoundation.org)
|
2010-05-19 01:15:13 +00:00
|
|
|
* @link http://book.cakephp.org/view/1196/Testing CakePHP(tm) Tests
|
2010-12-24 18:57:20 +00:00
|
|
|
* @package cake.tests.cases.libs.controller
|
2008-10-30 17:30:26 +00:00
|
|
|
* @since CakePHP(tm) v 1.2.0.5436
|
2010-10-03 16:27:27 +00:00
|
|
|
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
|
2008-05-30 11:40:08 +00:00
|
|
|
*/
|
2011-02-23 03:17:07 +00:00
|
|
|
|
2010-12-09 05:55:24 +00:00
|
|
|
App::uses('Controller', 'Controller');
|
2011-02-23 03:17:07 +00:00
|
|
|
App::uses('Scaffold', 'Controller');
|
|
|
|
App::uses('ScaffoldView', 'View');
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-06-02 19:22:55 +00:00
|
|
|
/**
|
|
|
|
* ScaffoldMockController class
|
2008-10-02 00:18:47 +00:00
|
|
|
*
|
2010-12-24 18:57:20 +00:00
|
|
|
* @package cake.tests.cases.libs.controller
|
2008-06-02 19:22:55 +00:00
|
|
|
*/
|
2008-05-30 11:40:08 +00:00
|
|
|
class ScaffoldMockController extends Controller {
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-06-02 19:22:55 +00:00
|
|
|
/**
|
|
|
|
* name property
|
2008-10-02 00:18:47 +00:00
|
|
|
*
|
2008-06-02 19:22:55 +00:00
|
|
|
* @var string 'ScaffoldMock'
|
|
|
|
* @access public
|
|
|
|
*/
|
2010-04-04 07:14:00 +00:00
|
|
|
public $name = 'ScaffoldMock';
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-06-02 19:22:55 +00:00
|
|
|
/**
|
|
|
|
* scaffold property
|
2008-10-02 00:18:47 +00:00
|
|
|
*
|
|
|
|
* @var mixed
|
2008-06-02 19:22:55 +00:00
|
|
|
* @access public
|
|
|
|
*/
|
2010-04-04 07:14:00 +00:00
|
|
|
public $scaffold;
|
2008-05-30 11:40:08 +00:00
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2009-07-03 00:14:36 +00:00
|
|
|
/**
|
|
|
|
* ScaffoldMockControllerWithFields class
|
|
|
|
*
|
2010-12-24 18:57:20 +00:00
|
|
|
* @package cake.tests.cases.libs.controller
|
2009-07-03 00:14:36 +00:00
|
|
|
*/
|
|
|
|
class ScaffoldMockControllerWithFields extends Controller {
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2009-07-03 00:14:36 +00:00
|
|
|
/**
|
|
|
|
* name property
|
|
|
|
*
|
|
|
|
* @var string 'ScaffoldMock'
|
|
|
|
* @access public
|
|
|
|
*/
|
2010-04-04 07:14:00 +00:00
|
|
|
public $name = 'ScaffoldMock';
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2009-07-03 00:14:36 +00:00
|
|
|
/**
|
|
|
|
* scaffold property
|
|
|
|
*
|
|
|
|
* @var mixed
|
|
|
|
* @access public
|
|
|
|
*/
|
2010-04-04 07:14:00 +00:00
|
|
|
public $scaffold;
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2009-07-03 00:14:36 +00:00
|
|
|
/**
|
|
|
|
* function _beforeScaffold
|
|
|
|
*
|
|
|
|
* @param string method
|
|
|
|
*/
|
|
|
|
function _beforeScaffold($method) {
|
|
|
|
$this->set('scaffoldFields', array('title'));
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-09-27 03:48:23 +00:00
|
|
|
/**
|
2009-03-18 17:55:58 +00:00
|
|
|
* TestScaffoldMock class
|
2008-09-27 03:48:23 +00:00
|
|
|
*
|
2010-12-24 18:57:20 +00:00
|
|
|
* @package cake.tests.cases.libs.controller
|
2008-09-27 03:48:23 +00:00
|
|
|
*/
|
|
|
|
class TestScaffoldMock extends Scaffold {
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-09-27 03:48:23 +00:00
|
|
|
/**
|
|
|
|
* Overload __scaffold
|
|
|
|
*
|
|
|
|
* @param unknown_type $params
|
|
|
|
*/
|
2010-12-20 04:03:37 +00:00
|
|
|
function _scaffold($params) {
|
|
|
|
$this->_params = $params;
|
2008-09-27 03:48:23 +00:00
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-09-27 03:48:23 +00:00
|
|
|
/**
|
|
|
|
* Get Params from the Controller.
|
|
|
|
*
|
|
|
|
* @return unknown
|
|
|
|
*/
|
|
|
|
function getParams() {
|
|
|
|
return $this->_params;
|
|
|
|
}
|
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-06-02 19:22:55 +00:00
|
|
|
/**
|
|
|
|
* ScaffoldMock class
|
2008-10-02 00:18:47 +00:00
|
|
|
*
|
2010-12-24 18:57:20 +00:00
|
|
|
* @package cake.tests.cases.libs.controller
|
2008-06-02 19:22:55 +00:00
|
|
|
*/
|
2008-05-30 11:40:08 +00:00
|
|
|
class ScaffoldMock extends CakeTestModel {
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-06-02 19:22:55 +00:00
|
|
|
/**
|
|
|
|
* useTable property
|
2008-10-02 00:18:47 +00:00
|
|
|
*
|
2008-06-02 19:22:55 +00:00
|
|
|
* @var string 'posts'
|
|
|
|
* @access public
|
|
|
|
*/
|
2010-04-04 07:14:00 +00:00
|
|
|
public $useTable = 'articles';
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-06-10 02:12:32 +00:00
|
|
|
/**
|
|
|
|
* belongsTo property
|
2008-10-02 00:18:47 +00:00
|
|
|
*
|
|
|
|
* @var array
|
2008-06-10 02:12:32 +00:00
|
|
|
* @access public
|
2008-10-02 00:18:47 +00:00
|
|
|
*/
|
2010-04-04 07:14:00 +00:00
|
|
|
public $belongsTo = array(
|
2008-06-10 02:12:32 +00:00
|
|
|
'User' => array(
|
|
|
|
'className' => 'ScaffoldUser',
|
|
|
|
'foreignKey' => 'user_id',
|
|
|
|
)
|
|
|
|
);
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-06-10 02:12:32 +00:00
|
|
|
/**
|
|
|
|
* hasMany property
|
2008-10-02 00:18:47 +00:00
|
|
|
*
|
|
|
|
* @var array
|
2008-06-10 02:12:32 +00:00
|
|
|
* @access public
|
|
|
|
*/
|
2010-04-04 07:14:00 +00:00
|
|
|
public $hasMany = array(
|
2008-06-10 02:12:32 +00:00
|
|
|
'Comment' => array(
|
|
|
|
'className' => 'ScaffoldComment',
|
|
|
|
'foreignKey' => 'article_id',
|
|
|
|
)
|
|
|
|
);
|
2009-08-26 03:34:19 +00:00
|
|
|
/**
|
|
|
|
* hasAndBelongsToMany property
|
|
|
|
*
|
|
|
|
* @var string
|
2009-11-14 12:19:25 +00:00
|
|
|
*/
|
2010-04-04 07:14:00 +00:00
|
|
|
public $hasAndBelongsToMany = array(
|
2009-08-26 03:34:19 +00:00
|
|
|
'ScaffoldTag' => array(
|
|
|
|
'className' => 'ScaffoldTag',
|
2010-01-19 16:05:29 +00:00
|
|
|
'foreignKey' => 'something_id',
|
|
|
|
'associationForeignKey' => 'something_else_id',
|
|
|
|
'joinTable' => 'join_things'
|
2009-08-26 03:34:19 +00:00
|
|
|
)
|
|
|
|
);
|
2008-06-10 02:12:32 +00:00
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-06-10 02:12:32 +00:00
|
|
|
/**
|
2009-03-18 17:55:58 +00:00
|
|
|
* ScaffoldUser class
|
2008-10-02 00:18:47 +00:00
|
|
|
*
|
2010-12-24 18:57:20 +00:00
|
|
|
* @package cake.tests.cases.libs.controller
|
2008-06-10 02:12:32 +00:00
|
|
|
*/
|
|
|
|
class ScaffoldUser extends CakeTestModel {
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-06-10 02:12:32 +00:00
|
|
|
/**
|
|
|
|
* useTable property
|
2008-10-02 00:18:47 +00:00
|
|
|
*
|
2008-06-10 02:12:32 +00:00
|
|
|
* @var string 'posts'
|
|
|
|
* @access public
|
|
|
|
*/
|
2010-04-04 07:14:00 +00:00
|
|
|
public $useTable = 'users';
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-06-10 02:12:32 +00:00
|
|
|
/**
|
|
|
|
* hasMany property
|
2008-10-02 00:18:47 +00:00
|
|
|
*
|
|
|
|
* @var array
|
2008-06-10 02:12:32 +00:00
|
|
|
* @access public
|
|
|
|
*/
|
2010-04-04 07:14:00 +00:00
|
|
|
public $hasMany = array(
|
2008-06-10 02:12:32 +00:00
|
|
|
'Article' => array(
|
|
|
|
'className' => 'ScaffoldMock',
|
|
|
|
'foreignKey' => 'article_id',
|
|
|
|
)
|
|
|
|
);
|
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-06-10 02:12:32 +00:00
|
|
|
/**
|
|
|
|
* ScaffoldComment class
|
2008-10-02 00:18:47 +00:00
|
|
|
*
|
2010-12-24 18:57:20 +00:00
|
|
|
* @package cake.tests.cases.libs.controller
|
2008-06-10 02:12:32 +00:00
|
|
|
*/
|
|
|
|
class ScaffoldComment extends CakeTestModel {
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-06-10 02:12:32 +00:00
|
|
|
/**
|
|
|
|
* useTable property
|
2008-10-02 00:18:47 +00:00
|
|
|
*
|
2008-06-10 02:12:32 +00:00
|
|
|
* @var string 'posts'
|
|
|
|
* @access public
|
|
|
|
*/
|
2010-04-04 07:14:00 +00:00
|
|
|
public $useTable = 'comments';
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-06-10 02:12:32 +00:00
|
|
|
/**
|
|
|
|
* belongsTo property
|
2008-10-02 00:18:47 +00:00
|
|
|
*
|
|
|
|
* @var array
|
2008-06-10 02:12:32 +00:00
|
|
|
* @access public
|
|
|
|
*/
|
2010-04-04 07:14:00 +00:00
|
|
|
public $belongsTo = array(
|
2008-06-10 02:12:32 +00:00
|
|
|
'Article' => array(
|
|
|
|
'className' => 'ScaffoldMock',
|
|
|
|
'foreignKey' => 'article_id',
|
|
|
|
)
|
|
|
|
);
|
2008-05-30 11:40:08 +00:00
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2009-08-26 03:34:19 +00:00
|
|
|
/**
|
|
|
|
* ScaffoldTag class
|
|
|
|
*
|
2010-12-24 18:57:20 +00:00
|
|
|
* @package cake.tests.cases.libs.controller
|
2009-08-26 03:34:19 +00:00
|
|
|
*/
|
|
|
|
class ScaffoldTag extends CakeTestModel {
|
|
|
|
/**
|
|
|
|
* useTable property
|
|
|
|
*
|
|
|
|
* @var string 'posts'
|
|
|
|
* @access public
|
|
|
|
*/
|
2010-04-04 07:14:00 +00:00
|
|
|
public $useTable = 'tags';
|
2009-08-26 03:34:19 +00:00
|
|
|
}
|
2008-06-02 19:22:55 +00:00
|
|
|
/**
|
|
|
|
* TestScaffoldView class
|
2008-10-02 00:18:47 +00:00
|
|
|
*
|
2010-12-24 18:57:20 +00:00
|
|
|
* @package cake.tests.cases.libs.controller
|
2008-06-02 19:22:55 +00:00
|
|
|
*/
|
2008-05-30 11:40:08 +00:00
|
|
|
class TestScaffoldView extends ScaffoldView {
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-06-02 19:22:55 +00:00
|
|
|
/**
|
|
|
|
* testGetFilename method
|
2008-10-02 00:18:47 +00:00
|
|
|
*
|
|
|
|
* @param mixed $action
|
2008-06-02 19:22:55 +00:00
|
|
|
* @access public
|
|
|
|
* @return void
|
|
|
|
*/
|
2008-05-30 11:40:08 +00:00
|
|
|
function testGetFilename($action) {
|
|
|
|
return $this->_getViewFileName($action);
|
|
|
|
}
|
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-05-30 11:40:08 +00:00
|
|
|
/**
|
2009-03-18 17:55:58 +00:00
|
|
|
* ScaffoldViewTest class
|
2008-05-30 11:40:08 +00:00
|
|
|
*
|
2010-12-24 18:57:20 +00:00
|
|
|
* @package cake.tests.cases.libs.controller
|
2008-05-30 11:40:08 +00:00
|
|
|
*/
|
|
|
|
class ScaffoldViewTest extends CakeTestCase {
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-06-05 15:20:45 +00:00
|
|
|
/**
|
|
|
|
* fixtures property
|
2008-10-02 00:18:47 +00:00
|
|
|
*
|
2008-06-05 15:20:45 +00:00
|
|
|
* @var array
|
|
|
|
* @access public
|
|
|
|
*/
|
2010-04-04 07:14:00 +00:00
|
|
|
public $fixtures = array('core.article', 'core.user', 'core.comment', 'core.join_thing', 'core.tag');
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-06-05 15:20:45 +00:00
|
|
|
/**
|
2010-09-26 01:36:49 +00:00
|
|
|
* setUp method
|
2008-10-02 00:18:47 +00:00
|
|
|
*
|
2008-06-05 15:20:45 +00:00
|
|
|
* @access public
|
|
|
|
* @return void
|
|
|
|
*/
|
2010-09-26 01:36:49 +00:00
|
|
|
function setUp() {
|
|
|
|
parent::setUp();
|
2010-05-18 03:11:47 +00:00
|
|
|
$this->request = new CakeRequest(null, false);
|
|
|
|
$this->Controller = new ScaffoldMockController($this->request);
|
2010-09-19 04:38:00 +00:00
|
|
|
$this->Controller->response = $this->getMock('CakeResponse', array('_sendHeader'));
|
2009-07-20 16:59:16 +00:00
|
|
|
|
|
|
|
App::build(array(
|
2011-04-17 10:35:21 +00:00
|
|
|
'View' => array(CAKE . 'Test' . DS . 'test_app' . DS . 'View' . DS),
|
|
|
|
'plugins' => array(CAKE . 'Test' . DS . 'test_app' . DS . 'Plugin' . DS)
|
2009-07-20 16:59:16 +00:00
|
|
|
));
|
2008-05-30 11:40:08 +00:00
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2009-03-18 17:55:58 +00:00
|
|
|
/**
|
2010-09-26 01:36:49 +00:00
|
|
|
* teardown method
|
2009-03-18 17:55:58 +00:00
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
2010-09-26 01:36:49 +00:00
|
|
|
function tearDown() {
|
|
|
|
parent::tearDown();
|
2010-09-26 01:50:28 +00:00
|
|
|
unset($this->Controller, $this->request);
|
2009-03-18 17:55:58 +00:00
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-06-05 15:20:45 +00:00
|
|
|
/**
|
|
|
|
* testGetViewFilename method
|
2008-10-02 00:18:47 +00:00
|
|
|
*
|
2008-06-05 15:20:45 +00:00
|
|
|
* @access public
|
|
|
|
* @return void
|
|
|
|
*/
|
2008-05-30 11:40:08 +00:00
|
|
|
function testGetViewFilename() {
|
2009-10-31 20:06:20 +00:00
|
|
|
$_admin = Configure::read('Routing.prefixes');
|
|
|
|
Configure::write('Routing.prefixes', array('admin'));
|
2008-10-02 00:18:47 +00:00
|
|
|
|
2010-05-18 03:11:47 +00:00
|
|
|
$this->Controller->request->params['action'] = 'index';
|
|
|
|
$ScaffoldView = new TestScaffoldView($this->Controller);
|
2008-05-30 11:40:08 +00:00
|
|
|
$result = $ScaffoldView->testGetFilename('index');
|
2011-04-17 10:35:21 +00:00
|
|
|
$expected = CAKE . 'View' . DS . 'scaffolds' . DS . 'index.ctp';
|
2008-05-30 11:40:08 +00:00
|
|
|
$this->assertEqual($result, $expected);
|
|
|
|
|
2008-09-27 03:48:23 +00:00
|
|
|
$result = $ScaffoldView->testGetFilename('edit');
|
2011-04-17 10:35:21 +00:00
|
|
|
$expected = CAKE . 'View' . DS . 'scaffolds' . DS . 'form.ctp';
|
2008-09-27 03:48:23 +00:00
|
|
|
$this->assertEqual($result, $expected);
|
|
|
|
|
|
|
|
$result = $ScaffoldView->testGetFilename('add');
|
2011-04-17 10:35:21 +00:00
|
|
|
$expected = CAKE . 'View' . DS . 'scaffolds' . DS . 'form.ctp';
|
2008-09-27 03:48:23 +00:00
|
|
|
$this->assertEqual($result, $expected);
|
|
|
|
|
|
|
|
$result = $ScaffoldView->testGetFilename('view');
|
2011-04-17 10:35:21 +00:00
|
|
|
$expected = CAKE . 'View' . DS . 'scaffolds' . DS . 'view.ctp';
|
2008-09-27 03:48:23 +00:00
|
|
|
$this->assertEqual($result, $expected);
|
|
|
|
|
|
|
|
$result = $ScaffoldView->testGetFilename('admin_index');
|
2011-04-17 10:35:21 +00:00
|
|
|
$expected = CAKE . 'View' . DS . 'scaffolds' . DS . 'index.ctp';
|
2008-09-27 03:48:23 +00:00
|
|
|
$this->assertEqual($result, $expected);
|
|
|
|
|
|
|
|
$result = $ScaffoldView->testGetFilename('admin_view');
|
2011-04-17 10:35:21 +00:00
|
|
|
$expected = CAKE . 'View' . DS . 'scaffolds' . DS . 'view.ctp';
|
2008-09-27 03:48:23 +00:00
|
|
|
$this->assertEqual($result, $expected);
|
|
|
|
|
|
|
|
$result = $ScaffoldView->testGetFilename('admin_edit');
|
2011-04-17 10:35:21 +00:00
|
|
|
$expected =CAKE . 'View' . DS . 'scaffolds' . DS . 'form.ctp';
|
2008-09-27 03:48:23 +00:00
|
|
|
$this->assertEqual($result, $expected);
|
|
|
|
|
|
|
|
$result = $ScaffoldView->testGetFilename('admin_add');
|
2011-04-17 10:35:21 +00:00
|
|
|
$expected = CAKE . 'View' . DS . 'scaffolds' . DS . 'form.ctp';
|
2008-09-27 03:48:23 +00:00
|
|
|
$this->assertEqual($result, $expected);
|
|
|
|
|
2008-05-30 11:40:08 +00:00
|
|
|
$result = $ScaffoldView->testGetFilename('error');
|
2011-04-17 10:35:21 +00:00
|
|
|
$expected = CAKE . 'View' . DS . 'errors' . DS . 'scaffold_error.ctp';
|
2008-05-30 11:40:08 +00:00
|
|
|
$this->assertEqual($result, $expected);
|
2008-09-27 03:48:23 +00:00
|
|
|
|
2010-05-18 03:11:47 +00:00
|
|
|
$Controller = new ScaffoldMockController($this->request);
|
2008-09-27 03:48:23 +00:00
|
|
|
$Controller->scaffold = 'admin';
|
|
|
|
$Controller->viewPath = 'posts';
|
2010-05-18 03:11:47 +00:00
|
|
|
$Controller->request['action'] = 'admin_edit';
|
|
|
|
|
|
|
|
$ScaffoldView = new TestScaffoldView($Controller);
|
2008-09-27 03:48:23 +00:00
|
|
|
$result = $ScaffoldView->testGetFilename('admin_edit');
|
2011-04-17 10:35:21 +00:00
|
|
|
$expected = CAKE . 'Test' . DS . 'test_app' .DS . 'View' . DS . 'Posts' . DS . 'scaffold.form.ctp';
|
2008-09-27 03:48:23 +00:00
|
|
|
$this->assertEqual($result, $expected);
|
2008-10-02 00:18:47 +00:00
|
|
|
|
2008-09-27 03:48:23 +00:00
|
|
|
$result = $ScaffoldView->testGetFilename('edit');
|
2011-04-17 10:35:21 +00:00
|
|
|
$expected = CAKE . 'Test' . DS . 'test_app' .DS . 'View' . DS . 'Posts' . DS . 'scaffold.form.ctp';
|
2008-09-27 03:48:23 +00:00
|
|
|
$this->assertEqual($result, $expected);
|
|
|
|
|
2010-05-18 03:11:47 +00:00
|
|
|
$Controller = new ScaffoldMockController($this->request);
|
2008-09-27 03:48:23 +00:00
|
|
|
$Controller->scaffold = 'admin';
|
|
|
|
$Controller->viewPath = 'tests';
|
2010-05-18 03:11:47 +00:00
|
|
|
$Controller->request->addParams(array(
|
|
|
|
'plugin' => 'test_plugin',
|
|
|
|
'action' => 'admin_add',
|
|
|
|
'admin' => true
|
|
|
|
));
|
2008-09-27 03:48:23 +00:00
|
|
|
$Controller->plugin = 'test_plugin';
|
2010-05-18 03:11:47 +00:00
|
|
|
|
|
|
|
$ScaffoldView = new TestScaffoldView($Controller);
|
2008-09-27 03:48:23 +00:00
|
|
|
$result = $ScaffoldView->testGetFilename('admin_add');
|
2011-04-17 10:35:21 +00:00
|
|
|
$expected = CAKE . 'Test' . DS . 'test_app' . DS . 'Plugin'
|
2011-04-10 19:32:19 +00:00
|
|
|
. DS .'test_plugin' . DS . 'View' . DS . 'tests' . DS . 'scaffold.form.ctp';
|
2008-09-27 03:48:23 +00:00
|
|
|
$this->assertEqual($result, $expected);
|
2008-10-02 00:18:47 +00:00
|
|
|
|
2008-09-27 03:48:23 +00:00
|
|
|
$result = $ScaffoldView->testGetFilename('add');
|
2011-04-17 10:35:21 +00:00
|
|
|
$expected = CAKE . 'Test' . DS . 'test_app' . DS . 'Plugin'
|
2011-04-10 19:32:19 +00:00
|
|
|
. DS .'test_plugin' . DS . 'View' . DS . 'tests' . DS . 'scaffold.form.ctp';
|
2008-09-27 03:48:23 +00:00
|
|
|
$this->assertEqual($result, $expected);
|
2008-10-02 00:18:47 +00:00
|
|
|
|
2009-10-31 20:06:20 +00:00
|
|
|
Configure::write('Routing.prefixes', $_admin);
|
2008-05-30 11:40:08 +00:00
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2010-01-28 16:11:19 +00:00
|
|
|
/**
|
|
|
|
* test getting the view file name for themed scaffolds.
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
function testGetViewFileNameWithTheme() {
|
2010-05-18 03:11:47 +00:00
|
|
|
$this->Controller->request['action'] = 'index';
|
2010-01-28 16:11:19 +00:00
|
|
|
$this->Controller->viewPath = 'posts';
|
|
|
|
$this->Controller->theme = 'test_theme';
|
2010-05-18 03:11:47 +00:00
|
|
|
$ScaffoldView = new TestScaffoldView($this->Controller);
|
2010-01-28 16:11:19 +00:00
|
|
|
|
|
|
|
$result = $ScaffoldView->testGetFilename('index');
|
2011-04-17 10:35:21 +00:00
|
|
|
$expected = CAKE . 'Test' . DS . 'test_app' . DS . 'View' . DS
|
2010-01-28 16:11:19 +00:00
|
|
|
. 'themed' . DS . 'test_theme' . DS . 'posts' . DS . 'scaffold.index.ctp';
|
|
|
|
$this->assertEqual($result, $expected);
|
|
|
|
}
|
|
|
|
|
2008-06-09 02:56:36 +00:00
|
|
|
/**
|
|
|
|
* test default index scaffold generation
|
|
|
|
*
|
|
|
|
* @access public
|
|
|
|
* @return void
|
2009-11-14 12:19:25 +00:00
|
|
|
*/
|
2008-06-09 02:56:36 +00:00
|
|
|
function testIndexScaffold() {
|
|
|
|
$params = array(
|
|
|
|
'plugin' => null,
|
|
|
|
'pass' => array(),
|
|
|
|
'form' => array(),
|
|
|
|
'named' => array(),
|
|
|
|
'url' => array('url' =>'scaffold_mock'),
|
|
|
|
'controller' => 'scaffold_mock',
|
|
|
|
'action' => 'index',
|
|
|
|
);
|
2010-05-18 03:11:47 +00:00
|
|
|
$this->Controller->request->addParams($params);
|
|
|
|
$this->Controller->request->webroot = '/';
|
|
|
|
$this->Controller->request->base = '';
|
|
|
|
$this->Controller->request->here = '/scaffold_mock/index';
|
|
|
|
|
2008-06-09 02:56:36 +00:00
|
|
|
//set router.
|
2008-09-27 03:48:23 +00:00
|
|
|
Router::reload();
|
2010-05-18 03:11:47 +00:00
|
|
|
Router::setRequestInfo($this->Controller->request);
|
|
|
|
|
2008-06-09 02:56:36 +00:00
|
|
|
$this->Controller->constructClasses();
|
|
|
|
ob_start();
|
2010-05-18 03:11:47 +00:00
|
|
|
new Scaffold($this->Controller, $this->Controller->request);
|
2008-06-09 02:56:36 +00:00
|
|
|
$result = ob_get_clean();
|
2008-10-02 00:18:47 +00:00
|
|
|
|
2009-05-13 01:00:38 +00:00
|
|
|
$this->assertPattern('#<h2>Scaffold Mock</h2>#', $result);
|
2008-09-27 03:48:23 +00:00
|
|
|
$this->assertPattern('#<table cellpadding="0" cellspacing="0">#', $result);
|
2009-12-20 01:22:16 +00:00
|
|
|
|
2008-09-27 03:48:23 +00:00
|
|
|
$this->assertPattern('#<a href="/scaffold_users/view/1">1</a>#', $result); //belongsTo links
|
2009-12-20 01:22:16 +00:00
|
|
|
$this->assertPattern('#<li><a href="/scaffold_mock/add">New Scaffold Mock</a></li>#', $result);
|
|
|
|
$this->assertPattern('#<li><a href="/scaffold_users">List Scaffold Users</a></li>#', $result);
|
|
|
|
$this->assertPattern('#<li><a href="/scaffold_comments/add">New Comment</a></li>#', $result);
|
2008-06-09 02:56:36 +00:00
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-06-09 02:56:36 +00:00
|
|
|
/**
|
|
|
|
* test default view scaffold generation
|
|
|
|
*
|
|
|
|
* @access public
|
|
|
|
* @return void
|
2009-11-14 12:19:25 +00:00
|
|
|
*/
|
2008-06-09 02:56:36 +00:00
|
|
|
function testViewScaffold() {
|
2010-05-18 03:11:47 +00:00
|
|
|
$this->Controller->request->base = '';
|
|
|
|
$this->Controller->request->here = '/scaffold_mock';
|
|
|
|
$this->Controller->request->webroot = '/';
|
2008-06-09 02:56:36 +00:00
|
|
|
$params = array(
|
|
|
|
'plugin' => null,
|
|
|
|
'pass' => array(1),
|
|
|
|
'form' => array(),
|
|
|
|
'named' => array(),
|
2010-05-18 03:11:47 +00:00
|
|
|
'url' => array('url' => 'scaffold_mock/view/1'),
|
2008-06-09 02:56:36 +00:00
|
|
|
'controller' => 'scaffold_mock',
|
|
|
|
'action' => 'view',
|
|
|
|
);
|
2010-05-18 03:11:47 +00:00
|
|
|
$this->Controller->request->addParams($params);
|
2011-04-17 10:35:21 +00:00
|
|
|
|
2008-06-09 02:56:36 +00:00
|
|
|
//set router.
|
|
|
|
Router::reload();
|
2010-05-18 03:11:47 +00:00
|
|
|
Router::setRequestInfo($this->Controller->request);
|
2008-06-09 02:56:36 +00:00
|
|
|
$this->Controller->constructClasses();
|
2008-10-02 00:18:47 +00:00
|
|
|
|
2008-06-09 02:56:36 +00:00
|
|
|
ob_start();
|
2010-05-18 03:11:47 +00:00
|
|
|
new Scaffold($this->Controller, $this->Controller->request);
|
2008-06-09 02:56:36 +00:00
|
|
|
$result = ob_get_clean();
|
|
|
|
|
2009-05-13 01:00:38 +00:00
|
|
|
$this->assertPattern('/<h2>View Scaffold Mock<\/h2>/', $result);
|
2008-06-09 02:56:36 +00:00
|
|
|
$this->assertPattern('/<dl>/', $result);
|
|
|
|
//TODO: add specific tests for fields.
|
2008-06-10 02:12:32 +00:00
|
|
|
$this->assertPattern('/<a href="\/scaffold_users\/view\/1">1<\/a>/', $result); //belongsTo links
|
2009-05-13 01:00:38 +00:00
|
|
|
$this->assertPattern('/<li><a href="\/scaffold_mock\/edit\/1">Edit Scaffold Mock<\/a>\s<\/li>/', $result);
|
|
|
|
$this->assertPattern('/<li><a href="\/scaffold_mock\/delete\/1"[^>]*>Delete Scaffold Mock<\/a>\s*<\/li>/', $result);
|
2008-06-10 02:12:32 +00:00
|
|
|
//check related table
|
2008-10-02 00:18:47 +00:00
|
|
|
$this->assertPattern('/<div class="related">\s*<h3>Related Scaffold Comments<\/h3>\s*<table cellpadding="0" cellspacing="0">/', $result);
|
2009-12-20 01:22:16 +00:00
|
|
|
$this->assertPattern('/<li><a href="\/scaffold_comments\/add">New Comment<\/a><\/li>/', $result);
|
2010-01-19 16:05:29 +00:00
|
|
|
$this->assertNoPattern('/<th>JoinThing<\/th>/', $result);
|
2008-10-02 00:18:47 +00:00
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-06-09 02:56:36 +00:00
|
|
|
/**
|
|
|
|
* test default view scaffold generation
|
|
|
|
*
|
|
|
|
* @access public
|
|
|
|
* @return void
|
2009-11-14 12:19:25 +00:00
|
|
|
*/
|
2008-06-09 02:56:36 +00:00
|
|
|
function testEditScaffold() {
|
2010-05-18 03:11:47 +00:00
|
|
|
$this->Controller->request->base = '';
|
|
|
|
$this->Controller->request->webroot = '/';
|
2011-03-09 12:31:11 +00:00
|
|
|
$this->Controller->request->here = '/scaffold_mock/edit/1';
|
2010-05-18 03:11:47 +00:00
|
|
|
|
2008-06-09 02:56:36 +00:00
|
|
|
$params = array(
|
|
|
|
'plugin' => null,
|
|
|
|
'pass' => array(1),
|
|
|
|
'form' => array(),
|
|
|
|
'named' => array(),
|
|
|
|
'url' => array('url' =>'scaffold_mock'),
|
|
|
|
'controller' => 'scaffold_mock',
|
|
|
|
'action' => 'edit',
|
|
|
|
);
|
2010-05-18 03:11:47 +00:00
|
|
|
$this->Controller->request->addParams($params);
|
|
|
|
|
2008-06-09 02:56:36 +00:00
|
|
|
//set router.
|
|
|
|
Router::reload();
|
2010-05-18 03:11:47 +00:00
|
|
|
Router::setRequestInfo($this->Controller->request);
|
2008-06-09 02:56:36 +00:00
|
|
|
$this->Controller->constructClasses();
|
|
|
|
ob_start();
|
2010-05-18 03:11:47 +00:00
|
|
|
new Scaffold($this->Controller, $this->Controller->request);
|
2008-06-09 02:56:36 +00:00
|
|
|
$result = ob_get_clean();
|
2008-10-02 00:18:47 +00:00
|
|
|
|
2010-08-28 03:59:29 +00:00
|
|
|
$this->assertContains('<form id="ScaffoldMockEditForm" method="post" action="/scaffold_mock/edit/1"', $result);
|
|
|
|
$this->assertContains('<legend>Edit Scaffold Mock</legend>', $result);
|
|
|
|
|
|
|
|
$this->assertContains('input type="hidden" name="data[ScaffoldMock][id]" value="1" id="ScaffoldMockId"', $result);
|
|
|
|
$this->assertContains('select name="data[ScaffoldMock][user_id]" id="ScaffoldMockUserId"', $result);
|
|
|
|
$this->assertContains('input name="data[ScaffoldMock][title]" maxlength="255" type="text" value="First Article" id="ScaffoldMockTitle"', $result);
|
|
|
|
$this->assertContains('input name="data[ScaffoldMock][published]" maxlength="1" type="text" value="Y" id="ScaffoldMockPublished"', $result);
|
|
|
|
$this->assertContains('textarea name="data[ScaffoldMock][body]" cols="30" rows="6" id="ScaffoldMockBody"', $result);
|
2010-12-12 18:13:00 +00:00
|
|
|
$this->assertPattern('/<a href="\#" onclick="if[^>]*>Delete<\/a><\/li>/', $result);
|
2008-09-27 03:48:23 +00:00
|
|
|
}
|
2009-10-31 20:06:20 +00:00
|
|
|
|
2008-06-09 02:56:36 +00:00
|
|
|
/**
|
|
|
|
* Test Admin Index Scaffolding.
|
|
|
|
*
|
|
|
|
* @access public
|
|
|
|
* @return void
|
2009-11-14 12:19:25 +00:00
|
|
|
*/
|
2008-06-09 02:56:36 +00:00
|
|
|
function testAdminIndexScaffold() {
|
2009-10-31 20:06:20 +00:00
|
|
|
$_backAdmin = Configure::read('Routing.prefixes');
|
2008-10-02 00:18:47 +00:00
|
|
|
|
2009-10-31 20:06:20 +00:00
|
|
|
Configure::write('Routing.prefixes', array('admin'));
|
2008-06-09 02:56:36 +00:00
|
|
|
$params = array(
|
|
|
|
'plugin' => null,
|
|
|
|
'pass' => array(),
|
|
|
|
'form' => array(),
|
|
|
|
'named' => array(),
|
|
|
|
'prefix' => 'admin',
|
|
|
|
'url' => array('url' =>'admin/scaffold_mock'),
|
|
|
|
'controller' => 'scaffold_mock',
|
|
|
|
'action' => 'admin_index',
|
|
|
|
'admin' => 1,
|
|
|
|
);
|
2010-05-18 03:11:47 +00:00
|
|
|
$this->Controller->request->base = '';
|
|
|
|
$this->Controller->request->webroot = '/';
|
|
|
|
$this->Controller->request->here = '/admin/scaffold_mock';
|
|
|
|
$this->Controller->request->addParams($params);
|
|
|
|
|
2008-06-09 02:56:36 +00:00
|
|
|
//reset, and set router.
|
|
|
|
Router::reload();
|
2010-05-18 03:11:47 +00:00
|
|
|
Router::setRequestInfo($this->Controller->request);
|
|
|
|
|
2008-06-09 02:56:36 +00:00
|
|
|
$this->Controller->scaffold = 'admin';
|
|
|
|
$this->Controller->constructClasses();
|
2008-10-02 00:18:47 +00:00
|
|
|
|
2008-06-09 02:56:36 +00:00
|
|
|
ob_start();
|
2010-05-18 03:11:47 +00:00
|
|
|
$Scaffold = new Scaffold($this->Controller, $this->Controller->request);
|
2008-06-09 02:56:36 +00:00
|
|
|
$result = ob_get_clean();
|
2008-10-02 00:18:47 +00:00
|
|
|
|
2009-05-13 01:00:38 +00:00
|
|
|
$this->assertPattern('/<h2>Scaffold Mock<\/h2>/', $result);
|
2008-06-09 02:56:36 +00:00
|
|
|
$this->assertPattern('/<table cellpadding="0" cellspacing="0">/', $result);
|
|
|
|
//TODO: add testing for table generation
|
2009-12-20 01:22:16 +00:00
|
|
|
$this->assertPattern('/<li><a href="\/admin\/scaffold_mock\/add">New Scaffold Mock<\/a><\/li>/', $result);
|
2008-10-02 00:18:47 +00:00
|
|
|
|
2009-10-31 20:06:20 +00:00
|
|
|
Configure::write('Routing.prefixes', $_backAdmin);
|
2008-06-09 02:56:36 +00:00
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-09-27 03:48:23 +00:00
|
|
|
/**
|
|
|
|
* Test Admin Index Scaffolding.
|
|
|
|
*
|
|
|
|
* @access public
|
|
|
|
* @return void
|
2009-11-14 12:19:25 +00:00
|
|
|
*/
|
2008-09-27 03:48:23 +00:00
|
|
|
function testAdminEditScaffold() {
|
2009-10-31 20:06:20 +00:00
|
|
|
Configure::write('Routing.prefixes', array('admin'));
|
2008-09-27 03:48:23 +00:00
|
|
|
$params = array(
|
|
|
|
'plugin' => null,
|
2010-09-26 01:50:28 +00:00
|
|
|
'pass' => array(1),
|
2008-09-27 03:48:23 +00:00
|
|
|
'form' => array(),
|
|
|
|
'named' => array(),
|
|
|
|
'prefix' => 'admin',
|
2010-09-26 01:50:28 +00:00
|
|
|
'url' => array('url' =>'admin/scaffold_mock/edit/1'),
|
2008-09-27 03:48:23 +00:00
|
|
|
'controller' => 'scaffold_mock',
|
|
|
|
'action' => 'admin_edit',
|
|
|
|
'admin' => 1,
|
|
|
|
);
|
2010-05-18 03:11:47 +00:00
|
|
|
$this->Controller->request->base = '';
|
|
|
|
$this->Controller->request->webroot = '/';
|
2010-09-26 01:50:28 +00:00
|
|
|
$this->Controller->request->here = '/admin/scaffold_mock/edit/1';
|
2010-05-18 03:11:47 +00:00
|
|
|
$this->Controller->request->addParams($params);
|
|
|
|
|
2008-09-27 03:48:23 +00:00
|
|
|
//reset, and set router.
|
|
|
|
Router::reload();
|
2010-05-18 03:11:47 +00:00
|
|
|
Router::setRequestInfo($this->Controller->request);
|
|
|
|
|
2008-09-27 03:48:23 +00:00
|
|
|
$this->Controller->scaffold = 'admin';
|
|
|
|
$this->Controller->constructClasses();
|
2008-10-02 00:18:47 +00:00
|
|
|
|
2008-09-27 03:48:23 +00:00
|
|
|
ob_start();
|
2010-05-18 03:11:47 +00:00
|
|
|
$Scaffold = new Scaffold($this->Controller, $this->Controller->request);
|
2008-09-27 03:48:23 +00:00
|
|
|
$result = ob_get_clean();
|
|
|
|
|
|
|
|
$this->assertPattern('#admin/scaffold_mock/edit/1#', $result);
|
|
|
|
$this->assertPattern('#Scaffold Mock#', $result);
|
2009-10-31 20:06:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Test Admin Index Scaffolding.
|
|
|
|
*
|
|
|
|
* @access public
|
|
|
|
* @return void
|
2009-11-14 12:19:25 +00:00
|
|
|
*/
|
2009-10-31 20:06:20 +00:00
|
|
|
function testMultiplePrefixScaffold() {
|
|
|
|
$_backAdmin = Configure::read('Routing.prefixes');
|
|
|
|
|
|
|
|
Configure::write('Routing.prefixes', array('admin', 'member'));
|
|
|
|
$params = array(
|
|
|
|
'plugin' => null,
|
|
|
|
'pass' => array(),
|
|
|
|
'form' => array(),
|
|
|
|
'named' => array(),
|
|
|
|
'prefix' => 'member',
|
|
|
|
'url' => array('url' =>'member/scaffold_mock'),
|
|
|
|
'controller' => 'scaffold_mock',
|
|
|
|
'action' => 'member_index',
|
|
|
|
'member' => 1,
|
|
|
|
);
|
2010-05-18 03:11:47 +00:00
|
|
|
$this->Controller->request->base = '';
|
|
|
|
$this->Controller->request->webroot = '/';
|
|
|
|
$this->Controller->request->here = '/member/scaffold_mock';
|
|
|
|
$this->Controller->request->addParams($params);
|
|
|
|
|
2009-10-31 20:06:20 +00:00
|
|
|
//reset, and set router.
|
|
|
|
Router::reload();
|
2010-05-18 03:11:47 +00:00
|
|
|
Router::setRequestInfo($this->Controller->request);
|
|
|
|
|
2009-10-31 20:06:20 +00:00
|
|
|
$this->Controller->scaffold = 'member';
|
|
|
|
$this->Controller->constructClasses();
|
|
|
|
|
|
|
|
ob_start();
|
2010-05-18 03:11:47 +00:00
|
|
|
$Scaffold = new Scaffold($this->Controller, $this->Controller->request);
|
2009-10-31 20:06:20 +00:00
|
|
|
$result = ob_get_clean();
|
|
|
|
|
|
|
|
$this->assertPattern('/<h2>Scaffold Mock<\/h2>/', $result);
|
|
|
|
$this->assertPattern('/<table cellpadding="0" cellspacing="0">/', $result);
|
|
|
|
//TODO: add testing for table generation
|
2009-12-20 01:22:16 +00:00
|
|
|
$this->assertPattern('/<li><a href="\/member\/scaffold_mock\/add">New Scaffold Mock<\/a><\/li>/', $result);
|
2009-10-31 20:06:20 +00:00
|
|
|
|
|
|
|
Configure::write('Routing.prefixes', $_backAdmin);
|
2008-09-27 03:48:23 +00:00
|
|
|
}
|
2009-10-31 20:06:20 +00:00
|
|
|
|
2008-09-27 03:48:23 +00:00
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-09-27 03:48:23 +00:00
|
|
|
/**
|
2009-03-18 17:55:58 +00:00
|
|
|
* Scaffold Test class
|
2008-09-27 03:48:23 +00:00
|
|
|
*
|
2010-12-24 18:57:20 +00:00
|
|
|
* @package cake.tests.cases.libs.controller
|
2008-09-27 03:48:23 +00:00
|
|
|
*/
|
2009-03-18 17:55:58 +00:00
|
|
|
class ScaffoldTest extends CakeTestCase {
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2009-03-18 17:55:58 +00:00
|
|
|
/**
|
|
|
|
* Controller property
|
|
|
|
*
|
|
|
|
* @var SecurityTestController
|
|
|
|
* @access public
|
|
|
|
*/
|
2010-04-04 07:14:00 +00:00
|
|
|
public $Controller;
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-09-27 03:48:23 +00:00
|
|
|
/**
|
|
|
|
* fixtures property
|
2008-10-02 00:18:47 +00:00
|
|
|
*
|
2008-09-27 03:48:23 +00:00
|
|
|
* @var array
|
|
|
|
* @access public
|
|
|
|
*/
|
2010-04-04 07:14:00 +00:00
|
|
|
public $fixtures = array('core.article', 'core.user', 'core.comment', 'core.join_thing', 'core.tag');
|
2008-09-27 03:48:23 +00:00
|
|
|
/**
|
2010-09-26 01:36:49 +00:00
|
|
|
* setUp method
|
2008-10-02 00:18:47 +00:00
|
|
|
*
|
2008-09-27 03:48:23 +00:00
|
|
|
* @return void
|
|
|
|
*/
|
2010-09-26 01:36:49 +00:00
|
|
|
function setUp() {
|
|
|
|
parent::setUp();
|
2010-05-18 03:11:47 +00:00
|
|
|
$request = new CakeRequest(null, false);
|
|
|
|
$this->Controller = new ScaffoldMockController($request);
|
2010-09-19 04:38:00 +00:00
|
|
|
$this->Controller->response = $this->getMock('CakeResponse', array('_sendHeader'));
|
2008-09-27 03:48:23 +00:00
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2009-03-18 17:55:58 +00:00
|
|
|
/**
|
2010-09-26 01:36:49 +00:00
|
|
|
* tearDown method
|
2009-03-18 17:55:58 +00:00
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
2010-09-26 01:36:49 +00:00
|
|
|
function tearDown() {
|
|
|
|
parent::tearDown();
|
2009-03-18 17:55:58 +00:00
|
|
|
unset($this->Controller);
|
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-09-27 03:48:23 +00:00
|
|
|
/**
|
|
|
|
* Test the correct Generation of Scaffold Params.
|
|
|
|
* This ensures that the correct action and view will be generated
|
|
|
|
*
|
|
|
|
* @access public
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
function testScaffoldParams() {
|
|
|
|
$params = array(
|
|
|
|
'plugin' => null,
|
|
|
|
'pass' => array(),
|
|
|
|
'form' => array(),
|
|
|
|
'named' => array(),
|
|
|
|
'url' => array('url' =>'admin/scaffold_mock/edit'),
|
|
|
|
'controller' => 'scaffold_mock',
|
|
|
|
'action' => 'admin_edit',
|
|
|
|
'admin' => true,
|
|
|
|
);
|
2010-05-18 03:11:47 +00:00
|
|
|
$this->Controller->request->base = '';
|
|
|
|
$this->Controller->request->webroot = '/';
|
|
|
|
$this->Controller->request->here = '/admin/scaffold_mock/edit';
|
|
|
|
$this->Controller->request->addParams($params);
|
|
|
|
|
2008-09-27 03:48:23 +00:00
|
|
|
//set router.
|
2010-05-18 03:11:47 +00:00
|
|
|
Router::setRequestInfo($this->Controller->request);
|
2008-09-27 03:48:23 +00:00
|
|
|
|
|
|
|
$this->Controller->constructClasses();
|
2010-05-18 03:11:47 +00:00
|
|
|
$Scaffold = new TestScaffoldMock($this->Controller, $this->Controller->request);
|
2008-09-27 03:48:23 +00:00
|
|
|
$result = $Scaffold->getParams();
|
|
|
|
$this->assertEqual($result['action'], 'admin_edit');
|
|
|
|
}
|
2010-08-02 02:25:29 +00:00
|
|
|
|
2009-05-13 01:00:38 +00:00
|
|
|
/**
|
|
|
|
* test that the proper names and variable values are set by Scaffold
|
|
|
|
*
|
|
|
|
* @return void
|
2009-11-14 12:19:25 +00:00
|
|
|
*/
|
2009-05-13 01:00:38 +00:00
|
|
|
function testScaffoldVariableSetting() {
|
|
|
|
$params = array(
|
|
|
|
'plugin' => null,
|
|
|
|
'pass' => array(),
|
|
|
|
'form' => array(),
|
|
|
|
'named' => array(),
|
|
|
|
'url' => array('url' =>'admin/scaffold_mock/edit'),
|
|
|
|
'controller' => 'scaffold_mock',
|
|
|
|
'action' => 'admin_edit',
|
|
|
|
'admin' => true,
|
|
|
|
);
|
2010-05-18 03:11:47 +00:00
|
|
|
$this->Controller->request->base = '';
|
|
|
|
$this->Controller->request->webroot = '/';
|
|
|
|
$this->Controller->request->here = '/admin/scaffold_mock/edit';
|
|
|
|
$this->Controller->request->addParams($params);
|
|
|
|
|
2009-05-13 01:00:38 +00:00
|
|
|
//set router.
|
2010-05-18 03:11:47 +00:00
|
|
|
Router::setRequestInfo($this->Controller->request);
|
2009-05-13 01:00:38 +00:00
|
|
|
|
|
|
|
$this->Controller->constructClasses();
|
2010-05-18 03:11:47 +00:00
|
|
|
$Scaffold = new TestScaffoldMock($this->Controller, $this->Controller->request);
|
2009-08-03 17:38:40 +00:00
|
|
|
$result = $Scaffold->controller->viewVars;
|
2009-05-13 01:00:38 +00:00
|
|
|
|
2010-01-19 16:05:29 +00:00
|
|
|
$this->assertEqual($result['title_for_layout'], 'Scaffold :: Admin Edit :: Scaffold Mock');
|
2009-05-13 01:00:38 +00:00
|
|
|
$this->assertEqual($result['singularHumanName'], 'Scaffold Mock');
|
|
|
|
$this->assertEqual($result['pluralHumanName'], 'Scaffold Mock');
|
|
|
|
$this->assertEqual($result['modelClass'], 'ScaffoldMock');
|
|
|
|
$this->assertEqual($result['primaryKey'], 'id');
|
|
|
|
$this->assertEqual($result['displayField'], 'title');
|
|
|
|
$this->assertEqual($result['singularVar'], 'scaffoldMock');
|
|
|
|
$this->assertEqual($result['pluralVar'], 'scaffoldMock');
|
|
|
|
$this->assertEqual($result['scaffoldFields'], array('id', 'user_id', 'title', 'body', 'published', 'created', 'updated'));
|
|
|
|
}
|
2010-08-02 02:25:29 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* test that Scaffold overrides the view property even if its set to 'Theme'
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
function testScaffoldChangingViewProperty() {
|
|
|
|
$this->Controller->action = 'edit';
|
|
|
|
$this->Controller->theme = 'test_theme';
|
2011-02-21 02:52:20 +00:00
|
|
|
$this->Controller->viewClass = 'Theme';
|
2010-08-02 02:25:29 +00:00
|
|
|
$this->Controller->constructClasses();
|
2010-11-13 04:05:44 +00:00
|
|
|
$Scaffold = new TestScaffoldMock($this->Controller, $this->Controller->request);
|
2010-08-02 02:25:29 +00:00
|
|
|
|
2011-02-21 02:52:20 +00:00
|
|
|
$this->assertEqual($this->Controller->viewClass, 'Scaffold');
|
2010-08-02 02:25:29 +00:00
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2009-08-31 17:48:32 +00:00
|
|
|
/**
|
|
|
|
* test that scaffold outputs flash messages when sessions are unset.
|
|
|
|
*
|
|
|
|
* @return void
|
2009-11-14 12:19:25 +00:00
|
|
|
*/
|
2009-08-31 17:48:32 +00:00
|
|
|
function testScaffoldFlashMessages() {
|
|
|
|
$params = array(
|
|
|
|
'plugin' => null,
|
|
|
|
'pass' => array(1),
|
|
|
|
'form' => array(),
|
|
|
|
'named' => array(),
|
|
|
|
'url' => array('url' =>'scaffold_mock'),
|
|
|
|
'controller' => 'scaffold_mock',
|
|
|
|
'action' => 'edit',
|
|
|
|
);
|
2010-05-18 03:11:47 +00:00
|
|
|
$this->Controller->request->base = '';
|
|
|
|
$this->Controller->request->webroot = '/';
|
|
|
|
$this->Controller->request->here = '/scaffold_mock/edit';
|
|
|
|
$this->Controller->request->addParams($params);
|
|
|
|
|
2009-08-31 17:48:32 +00:00
|
|
|
//set router.
|
|
|
|
Router::reload();
|
2010-05-18 03:11:47 +00:00
|
|
|
Router::setRequestInfo($this->Controller->request);
|
|
|
|
$this->Controller->request->data = array(
|
2009-08-31 17:48:32 +00:00
|
|
|
'ScaffoldMock' => array(
|
|
|
|
'id' => 1,
|
|
|
|
'title' => 'New title',
|
|
|
|
'body' => 'new body'
|
|
|
|
)
|
|
|
|
);
|
|
|
|
$this->Controller->constructClasses();
|
|
|
|
unset($this->Controller->Session);
|
|
|
|
|
|
|
|
ob_start();
|
2010-05-18 03:11:47 +00:00
|
|
|
new Scaffold($this->Controller, $this->Controller->request);
|
2009-08-31 17:48:32 +00:00
|
|
|
$result = ob_get_clean();
|
|
|
|
$this->assertPattern('/Scaffold Mock has been updated/', $result);
|
|
|
|
}
|
2009-08-26 03:34:19 +00:00
|
|
|
/**
|
|
|
|
* test that habtm relationship keys get added to scaffoldFields.
|
|
|
|
*
|
|
|
|
* @return void
|
2009-11-14 12:19:25 +00:00
|
|
|
*/
|
2009-08-26 03:34:19 +00:00
|
|
|
function testHabtmFieldAdditionWithScaffoldForm() {
|
|
|
|
$params = array(
|
|
|
|
'plugin' => null,
|
|
|
|
'pass' => array(1),
|
|
|
|
'form' => array(),
|
|
|
|
'named' => array(),
|
|
|
|
'url' => array('url' =>'scaffold_mock'),
|
|
|
|
'controller' => 'scaffold_mock',
|
|
|
|
'action' => 'edit',
|
|
|
|
);
|
2010-05-18 03:11:47 +00:00
|
|
|
$this->Controller->request->base = '';
|
|
|
|
$this->Controller->request->webroot = '/';
|
|
|
|
$this->Controller->request->here = '/scaffold_mock/edit';
|
|
|
|
$this->Controller->request->addParams($params);
|
|
|
|
|
2009-08-26 03:34:19 +00:00
|
|
|
//set router.
|
|
|
|
Router::reload();
|
2010-05-18 03:11:47 +00:00
|
|
|
Router::setRequestInfo($this->Controller->request);
|
|
|
|
|
2009-08-26 03:34:19 +00:00
|
|
|
$this->Controller->constructClasses();
|
|
|
|
ob_start();
|
2010-05-18 03:11:47 +00:00
|
|
|
$Scaffold = new Scaffold($this->Controller, $this->Controller->request);
|
2009-08-26 03:34:19 +00:00
|
|
|
$result = ob_get_clean();
|
|
|
|
$this->assertPattern('/name="data\[ScaffoldTag\]\[ScaffoldTag\]"/', $result);
|
|
|
|
|
|
|
|
$result = $Scaffold->controller->viewVars;
|
|
|
|
$this->assertEqual($result['scaffoldFields'], array('id', 'user_id', 'title', 'body', 'published', 'created', 'updated', 'ScaffoldTag'));
|
|
|
|
}
|
2009-07-03 00:14:36 +00:00
|
|
|
/**
|
|
|
|
* test that the proper names and variable values are set by Scaffold
|
|
|
|
*
|
|
|
|
* @return void
|
2009-11-14 12:19:25 +00:00
|
|
|
*/
|
2009-07-03 00:14:36 +00:00
|
|
|
function testEditScaffoldWithScaffoldFields() {
|
2010-05-18 03:11:47 +00:00
|
|
|
$request = new CakeRequest(null, false);
|
|
|
|
$this->Controller = new ScaffoldMockControllerWithFields($request);
|
2010-09-19 04:38:00 +00:00
|
|
|
$this->Controller->response = $this->getMock('CakeResponse', array('_sendHeader'));
|
|
|
|
|
2009-07-03 00:14:36 +00:00
|
|
|
$params = array(
|
|
|
|
'plugin' => null,
|
|
|
|
'pass' => array(1),
|
|
|
|
'form' => array(),
|
|
|
|
'named' => array(),
|
2010-05-18 03:11:47 +00:00
|
|
|
'url' => array('url' =>'scaffold_mock/edit'),
|
2009-07-03 00:14:36 +00:00
|
|
|
'controller' => 'scaffold_mock',
|
|
|
|
'action' => 'edit',
|
|
|
|
);
|
2010-05-18 03:11:47 +00:00
|
|
|
$this->Controller->request->base = '';
|
|
|
|
$this->Controller->request->webroot = '/';
|
|
|
|
$this->Controller->request->here = '/scaffold_mock/edit';
|
|
|
|
$this->Controller->request->addParams($params);
|
|
|
|
|
2009-07-03 00:14:36 +00:00
|
|
|
//set router.
|
|
|
|
Router::reload();
|
2010-05-18 03:11:47 +00:00
|
|
|
Router::setRequestInfo($this->Controller->request);
|
|
|
|
|
2009-07-03 00:14:36 +00:00
|
|
|
$this->Controller->constructClasses();
|
|
|
|
ob_start();
|
2010-05-18 03:11:47 +00:00
|
|
|
new Scaffold($this->Controller, $this->Controller->request);
|
2009-07-03 00:14:36 +00:00
|
|
|
$result = ob_get_clean();
|
|
|
|
|
|
|
|
$this->assertNoPattern('/textarea name="data\[ScaffoldMock\]\[body\]" cols="30" rows="6" id="ScaffoldMockBody"/', $result);
|
|
|
|
}
|
2008-05-30 11:40:08 +00:00
|
|
|
}
|