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
|
|
|
*
|
2012-04-27 02:49:18 +00:00
|
|
|
* CakePHP(tm) Tests <http://book.cakephp.org/2.0/en/development/testing.html>
|
2012-03-13 02:46:07 +00:00
|
|
|
* Copyright 2005-2012, 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
|
|
|
*
|
2012-03-13 02:46:07 +00:00
|
|
|
* @copyright Copyright 2005-2012, Cake Software Foundation, Inc. (http://cakefoundation.org)
|
2012-04-27 02:49:18 +00:00
|
|
|
* @link http://book.cakephp.org/2.0/en/development/testing.html CakePHP(tm) Tests
|
2011-07-26 06:16:14 +00:00
|
|
|
* @package Cake.Test.Case.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-09-17 02:05:09 +00:00
|
|
|
App::uses('Router', 'Routing');
|
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');
|
2011-09-17 02:05:09 +00:00
|
|
|
App::uses('AppModel', 'Model');
|
|
|
|
|
|
|
|
require_once dirname(dirname(__FILE__)) . DS . 'Model' . DS . 'models.php';
|
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
|
|
|
*
|
2011-07-26 06:16:14 +00:00
|
|
|
* @package Cake.Test.Case.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'
|
|
|
|
*/
|
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
|
|
|
*/
|
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
|
|
|
|
*
|
2011-07-26 06:16:14 +00:00
|
|
|
* @package Cake.Test.Case.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'
|
|
|
|
*/
|
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
|
|
|
|
*/
|
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
|
|
|
/**
|
2011-08-25 01:45:33 +00:00
|
|
|
* function beforeScaffold
|
2009-07-03 00:14:36 +00:00
|
|
|
*
|
|
|
|
* @param string method
|
|
|
|
*/
|
2011-08-25 01:45:33 +00:00
|
|
|
public function beforeScaffold($method) {
|
2009-07-03 00:14:36 +00:00
|
|
|
$this->set('scaffoldFields', array('title'));
|
|
|
|
return true;
|
|
|
|
}
|
2012-03-12 02:20:25 +00:00
|
|
|
|
2009-07-03 00:14:36 +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
|
|
|
* TestScaffoldMock class
|
2008-09-27 03:48:23 +00:00
|
|
|
*
|
2011-07-26 06:16:14 +00:00
|
|
|
* @package Cake.Test.Case.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
|
|
|
/**
|
2011-11-13 01:43:55 +00:00
|
|
|
* Overload _scaffold
|
2008-09-27 03:48:23 +00:00
|
|
|
*
|
|
|
|
* @param unknown_type $params
|
|
|
|
*/
|
2012-02-17 07:13:12 +00:00
|
|
|
protected function _scaffold(CakeRequest $request) {
|
2011-12-16 06:52:07 +00:00
|
|
|
$this->_params = $request;
|
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-09-27 03:48:23 +00:00
|
|
|
/**
|
|
|
|
* Get Params from the Controller.
|
|
|
|
*
|
|
|
|
* @return unknown
|
|
|
|
*/
|
2012-02-17 07:13:12 +00:00
|
|
|
public function getParams() {
|
2011-12-16 06:52:07 +00:00
|
|
|
return $this->_params;
|
|
|
|
}
|
2012-03-12 02:20:25 +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
|
|
|
*
|
2011-07-26 06:16:14 +00:00
|
|
|
* @package Cake.Test.Case.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
|
|
|
|
*/
|
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
|
|
|
|
*/
|
2010-04-04 07:14:00 +00:00
|
|
|
public $fixtures = array('core.article', 'core.user', 'core.comment', 'core.join_thing', 'core.tag');
|
2011-12-06 20:52:48 +00:00
|
|
|
|
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
|
|
|
|
*/
|
2011-05-30 20:02:32 +00:00
|
|
|
public function setUp() {
|
2010-09-26 01:36:49 +00:00
|
|
|
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
|
|
|
|
*/
|
2011-05-30 20:02:32 +00:00
|
|
|
public function tearDown() {
|
2010-09-26 01:36:49 +00:00
|
|
|
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
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
2011-05-30 20:02:32 +00:00
|
|
|
public function testScaffoldParams() {
|
2008-09-27 03:48:23 +00:00
|
|
|
$params = array(
|
|
|
|
'plugin' => null,
|
|
|
|
'pass' => array(),
|
|
|
|
'form' => array(),
|
|
|
|
'named' => array(),
|
2011-12-01 07:21:31 +00:00
|
|
|
'url' => array('url' => 'admin/scaffold_mock/edit'),
|
2008-09-27 03:48:23 +00:00
|
|
|
'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();
|
2012-03-23 06:37:12 +00:00
|
|
|
$this->assertEquals('admin_edit', $result['action']);
|
2008-09-27 03:48:23 +00:00
|
|
|
}
|
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
|
|
|
*/
|
2011-05-30 20:02:32 +00:00
|
|
|
public function testScaffoldVariableSetting() {
|
2009-05-13 01:00:38 +00:00
|
|
|
$params = array(
|
|
|
|
'plugin' => null,
|
|
|
|
'pass' => array(),
|
|
|
|
'form' => array(),
|
|
|
|
'named' => array(),
|
2011-12-01 07:21:31 +00:00
|
|
|
'url' => array('url' => 'admin/scaffold_mock/edit'),
|
2009-05-13 01:00:38 +00:00
|
|
|
'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
|
|
|
|
2012-03-23 06:37:12 +00:00
|
|
|
$this->assertEquals('Scaffold :: Admin Edit :: Scaffold Mock', $result['title_for_layout']);
|
|
|
|
$this->assertEquals('Scaffold Mock', $result['singularHumanName']);
|
|
|
|
$this->assertEquals('Scaffold Mock', $result['pluralHumanName']);
|
|
|
|
$this->assertEquals('ScaffoldMock', $result['modelClass']);
|
|
|
|
$this->assertEquals('id', $result['primaryKey']);
|
|
|
|
$this->assertEquals('title', $result['displayField']);
|
|
|
|
$this->assertEquals('scaffoldMock', $result['singularVar']);
|
|
|
|
$this->assertEquals('scaffoldMock', $result['pluralVar']);
|
|
|
|
$this->assertEquals(array('id', 'user_id', 'title', 'body', 'published', 'created', 'updated'), $result['scaffoldFields']);
|
2012-11-28 02:57:12 +00:00
|
|
|
$this->assertArrayHasKey('plugin', $result['associations']['belongsTo']['User']);
|
2009-05-13 01:00:38 +00:00
|
|
|
}
|
2010-08-02 02:25:29 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* test that Scaffold overrides the view property even if its set to 'Theme'
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
2011-05-30 20:02:32 +00:00
|
|
|
public function testScaffoldChangingViewProperty() {
|
2010-08-02 02:25:29 +00:00
|
|
|
$this->Controller->action = 'edit';
|
2011-05-16 22:31:59 +00:00
|
|
|
$this->Controller->theme = 'TestTheme';
|
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
|
|
|
|
2012-03-23 06:37:12 +00:00
|
|
|
$this->assertEquals('Scaffold', $this->Controller->viewClass);
|
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
|
|
|
*/
|
2011-05-30 20:02:32 +00:00
|
|
|
public function testScaffoldFlashMessages() {
|
2009-08-31 17:48:32 +00:00
|
|
|
$params = array(
|
|
|
|
'plugin' => null,
|
|
|
|
'pass' => array(1),
|
|
|
|
'form' => array(),
|
|
|
|
'named' => array(),
|
2011-12-01 07:21:31 +00:00
|
|
|
'url' => array('url' => 'scaffold_mock'),
|
2009-08-31 17:48:32 +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-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);
|
2011-07-28 22:09:19 +00:00
|
|
|
$this->Controller->response->send();
|
2009-08-31 17:48:32 +00:00
|
|
|
$result = ob_get_clean();
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertRegExp('/Scaffold Mock has been updated/', $result);
|
2009-08-31 17:48:32 +00:00
|
|
|
}
|
2011-12-06 20:52:48 +00:00
|
|
|
|
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
|
|
|
*/
|
2012-02-17 07:13:12 +00:00
|
|
|
public function testHabtmFieldAdditionWithScaffoldForm() {
|
2011-05-27 06:58:38 +00:00
|
|
|
CakePlugin::unload();
|
2009-08-26 03:34:19 +00:00
|
|
|
$params = array(
|
|
|
|
'plugin' => null,
|
|
|
|
'pass' => array(1),
|
|
|
|
'form' => array(),
|
|
|
|
'named' => array(),
|
2011-12-01 07:21:31 +00:00
|
|
|
'url' => array('url' => 'scaffold_mock'),
|
2009-08-26 03:34:19 +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-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);
|
2011-07-28 22:09:19 +00:00
|
|
|
$this->Controller->response->send();
|
2009-08-26 03:34:19 +00:00
|
|
|
$result = ob_get_clean();
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertRegExp('/name="data\[ScaffoldTag\]\[ScaffoldTag\]"/', $result);
|
2009-08-26 03:34:19 +00:00
|
|
|
|
|
|
|
$result = $Scaffold->controller->viewVars;
|
2012-03-23 06:37:12 +00:00
|
|
|
$this->assertEquals(array('id', 'user_id', 'title', 'body', 'published', 'created', 'updated', 'ScaffoldTag'), $result['scaffoldFields']);
|
2009-08-26 03:34:19 +00:00
|
|
|
}
|
2011-12-06 20:52:48 +00:00
|
|
|
|
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
|
|
|
*/
|
2011-05-30 20:02:32 +00:00
|
|
|
public 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(),
|
2011-12-01 07:21:31 +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);
|
2011-07-28 22:09:19 +00:00
|
|
|
$this->Controller->response->send();
|
2009-07-03 00:14:36 +00:00
|
|
|
$result = ob_get_clean();
|
|
|
|
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertNotRegExp('/textarea name="data\[ScaffoldMock\]\[body\]" cols="30" rows="6" id="ScaffoldMockBody"/', $result);
|
2009-07-03 00:14:36 +00:00
|
|
|
}
|
2012-03-12 02:20:25 +00:00
|
|
|
|
2008-05-30 11:40:08 +00:00
|
|
|
}
|