diff --git a/cake/libs/controller/scaffold.php b/cake/libs/controller/scaffold.php index 9913608e6..8b48e3e56 100644 --- a/cake/libs/controller/scaffold.php +++ b/cake/libs/controller/scaffold.php @@ -37,7 +37,6 @@ class Scaffold extends Object { * Controller object * * @var Controller - * @access public */ public $controller = null; @@ -45,23 +44,13 @@ class Scaffold extends Object { * Name of the controller to scaffold * * @var string - * @access public */ public $name = null; -/** - * Action to be performed. - * - * @var string - * @access public - */ - public $action = null; - /** * Name of current model this view context is attached to * * @var string - * @access public */ public $model = null; @@ -69,39 +58,27 @@ class Scaffold extends Object { * Path to View. * * @var string - * @access public */ public $viewPath; -/** - * Path parts for creating links in views. - * - * @var string Base URL - * @access public - */ - public $base = null; - /** * Name of layout to use with this View. * * @var string - * @access public */ public $layout = 'default'; /** - * Array of parameter data + * Request object * - * @var array - * @access public + * @var CakeRequest */ - public $params; + public $request; /** * File extension. Defaults to Cake's template ".ctp". * * @var array - * @access public */ public $ext = '.ctp'; @@ -109,18 +86,9 @@ class Scaffold extends Object { * Sub-directory for this view file. * * @var string - * @access public */ public $subDir = null; -/** - * Plugin name. - * - * @var string - * @access public - */ - public $plugin = null; - /** * valid session. * @@ -137,7 +105,8 @@ class Scaffold extends Object { */ private $__passedVars = array( 'action', 'base', 'webroot', 'layout', 'name', - 'viewPath', 'ext', 'params', 'data', 'plugin', 'cacheAction' + 'viewPath', 'ext', 'params', 'data', 'plugin', 'cacheAction', + 'request' ); /** @@ -151,11 +120,11 @@ class Scaffold extends Object { /** * Construct and set up given controller with given parameters. * - * @param string $controller_class Name of controller - * @param array $params Parameters for scaffolding + * @param Controller $controller Controller to scaffold + * @param CakeRequest $request Request parameters. */ - function __construct(&$controller, $params) { - $this->controller =& $controller; + function __construct(Controller $controller, CakeRequest $request) { + $this->controller = $controller; $count = count($this->__passedVars); for ($j = 0; $j < $count; $j++) { @@ -170,14 +139,16 @@ class Scaffold extends Object { if (!is_object($this->controller->{$this->modelClass})) { return $this->cakeError('missingModel', array(array( - 'className' => $this->modelClass, 'webroot' => '', 'base' => $controller->base + 'className' => $this->modelClass, + 'webroot' => $request->webroot, + 'base' => $request->base ))); } - $this->ScaffoldModel =& $this->controller->{$this->modelClass}; + $this->ScaffoldModel = $this->controller->{$this->modelClass}; $this->scaffoldTitle = Inflector::humanize($this->viewPath); $this->scaffoldActions = $controller->scaffold; - $title_for_layout = __('Scaffold :: ') . Inflector::humanize($this->action) . ' :: ' . $this->scaffoldTitle; + $title_for_layout = __('Scaffold :: ') . Inflector::humanize($request->action) . ' :: ' . $this->scaffoldTitle; $modelClass = $this->controller->modelClass; $primaryKey = $this->ScaffoldModel->primaryKey; $displayField = $this->ScaffoldModel->displayField; @@ -199,7 +170,7 @@ class Scaffold extends Object { $this->_validSession = ( isset($this->controller->Session) && $this->controller->Session->valid() != false ); - $this->__scaffold($params); + $this->__scaffold($request); } /** @@ -215,17 +186,16 @@ class Scaffold extends Object { /** * Renders a view action of scaffolded model. * - * @param array $params Parameters for scaffolding + * @param CakeRequest $request Request Object for scaffolding * @return mixed A rendered view of a row from Models database table * @access private */ - function __scaffoldView($params) { + function __scaffoldView(CakeRequest $request) { if ($this->controller->_beforeScaffold('view')) { $message = __(sprintf("No id set for %s::view()", Inflector::humanize($this->modelKey))); - - if (isset($params['pass'][0])) { - $this->ScaffoldModel->id = $params['pass'][0]; + if (isset($request->params['pass'][0])) { + $this->ScaffoldModel->id = $request->params['pass'][0]; } elseif ($this->_validSession) { $this->controller->Session->setFlash($message); $this->controller->redirect($this->redirect); @@ -233,11 +203,11 @@ class Scaffold extends Object { return $this->controller->flash($message, '/' . Inflector::underscore($this->controller->viewPath)); } $this->ScaffoldModel->recursive = 1; - $this->controller->data = $this->ScaffoldModel->read(); + $this->controller->request->data = $this->controller->data = $this->ScaffoldModel->read(); $this->controller->set( - Inflector::variable($this->controller->modelClass), $this->controller->data + Inflector::variable($this->controller->modelClass), $this->request->data ); - $this->controller->render($this->action, $this->layout); + $this->controller->render($this->request['action'], $this->layout); $this->_output(); } elseif ($this->controller->_scaffoldError('view') === false) { return $this->__scaffoldError(); @@ -257,7 +227,7 @@ class Scaffold extends Object { $this->controller->set( Inflector::variable($this->controller->name), $this->controller->paginate() ); - $this->controller->render($this->action, $this->layout); + $this->controller->render($this->request['action'], $this->layout); $this->_output(); } elseif ($this->controller->_scaffoldError('index') === false) { return $this->__scaffoldError(); @@ -283,12 +253,12 @@ class Scaffold extends Object { /** * Saves or updates the scaffolded model. * - * @param array $params Parameters for scaffolding + * @param CakeRequest $request Request Object for scaffolding * @param string $action add or edt * @return mixed Success on save/update, add/edit form if data is empty or error if save or update fails * @access private */ - function __scaffoldSave($params = array(), $action = 'edit') { + function __scaffoldSave(CakeRequest $request, $action = 'edit') { $formAction = 'edit'; $success = __('updated'); if ($action === 'add') { @@ -298,8 +268,8 @@ class Scaffold extends Object { if ($this->controller->_beforeScaffold($action)) { if ($action == 'edit') { - if (isset($params['pass'][0])) { - $this->ScaffoldModel->id = $params['pass'][0]; + if (isset($request->params['pass'][0])) { + $this->ScaffoldModel->id = $request['pass'][0]; } if (!$this->ScaffoldModel->exists()) { @@ -314,12 +284,12 @@ class Scaffold extends Object { } } - if (!empty($this->controller->data)) { + if (!empty($request->data)) { if ($action == 'create') { $this->ScaffoldModel->create(); } - if ($this->ScaffoldModel->save($this->controller->data)) { + if ($this->ScaffoldModel->save($request->data)) { if ($this->controller->_afterScaffoldSave($action)) { $message = __( sprintf('The %1$s has been %2$s', Inflector::humanize($this->modelKey), $success) @@ -341,11 +311,11 @@ class Scaffold extends Object { } } - if (empty($this->controller->data)) { + if (empty($request->data)) { if ($this->ScaffoldModel->id) { - $this->controller->data = $this->ScaffoldModel->read(); + $this->controller->data = $request->data = $this->ScaffoldModel->read(); } else { - $this->controller->data = $this->ScaffoldModel->create(); + $this->controller->data = $request->data = $this->ScaffoldModel->create(); } } @@ -373,13 +343,13 @@ class Scaffold extends Object { * @return mixed Success on delete, error if delete fails * @access private */ - function __scaffoldDelete($params = array()) { + function __scaffoldDelete(CakeRequest $request) { if ($this->controller->_beforeScaffold('delete')) { $message = __( sprintf("No id set for %s::delete()", Inflector::humanize($this->modelKey)) ); - if (isset($params['pass'][0])) { - $id = $params['pass'][0]; + if (isset($request->params['pass'][0])) { + $id = $request->params['pass'][0]; } elseif ($this->_validSession) { $this->controller->Session->setFlash($message); $this->controller->redirect($this->redirect); @@ -433,11 +403,11 @@ class Scaffold extends Object { * scaffoldView is used to call default Scaffold methods if: * `public $scaffold;` is placed in the controller's class definition. * - * @param array $params Parameters for scaffolding + * @param CakeRequest $request Request object for scaffolding * @return mixed A rendered view of scaffold action, or showing the error * @access private */ - function __scaffold($params) { + function __scaffold(CakeRequest $request) { $db = &ConnectionManager::getDataSource($this->ScaffoldModel->useDbConfig); $prefixes = Configure::read('Routing.prefixes'); $scaffoldPrefix = $this->scaffoldActions; @@ -460,41 +430,41 @@ class Scaffold extends Object { ); } - if (in_array($params['action'], $this->scaffoldActions)) { + if (in_array($request->params['action'], $this->scaffoldActions)) { if (!empty($prefixes)) { - $params['action'] = str_replace($scaffoldPrefix . '_', '', $params['action']); + $request->params['action'] = str_replace($scaffoldPrefix . '_', '', $request->params['action']); } - switch ($params['action']) { + switch ($request->params['action']) { case 'index': case 'list': - $this->__scaffoldIndex($params); + $this->__scaffoldIndex($request); break; case 'view': - $this->__scaffoldView($params); + $this->__scaffoldView($request); break; case 'add': case 'create': - $this->__scaffoldSave($params, 'add'); + $this->__scaffoldSave($request, 'add'); break; case 'edit': case 'update': - $this->__scaffoldSave($params, 'edit'); + $this->__scaffoldSave($request, 'edit'); break; case 'delete': - $this->__scaffoldDelete($params); + $this->__scaffoldDelete($request); break; } } else { return $this->cakeError('missingAction', array(array( 'className' => $this->controller->name . "Controller", - 'base' => $this->controller->base, - 'action' => $this->action, - 'webroot' => $this->controller->webroot + 'base' => $request->base, + 'action' => $request->action, + 'webroot' => $request->webroot ))); } } else { return $this->cakeError('missingDatabase', array(array( - 'webroot' => $this->controller->webroot + 'webroot' => $request->webroot ))); } } diff --git a/cake/tests/cases/libs/controller/scaffold.test.php b/cake/tests/cases/libs/controller/scaffold.test.php index 56f734247..7858bb52b 100644 --- a/cake/tests/cases/libs/controller/scaffold.test.php +++ b/cake/tests/cases/libs/controller/scaffold.test.php @@ -280,7 +280,8 @@ class ScaffoldViewTest extends CakeTestCase { * @return void */ function startTest() { - $this->Controller =& new ScaffoldMockController(); + $this->request = new CakeRequest(null, false); + $this->Controller = new ScaffoldMockController($this->request); App::build(array( 'views' => array(TEST_CAKE_CORE_INCLUDE_PATH . 'tests' . DS . 'test_app' . DS . 'views' . DS), @@ -310,8 +311,8 @@ class ScaffoldViewTest extends CakeTestCase { $_admin = Configure::read('Routing.prefixes'); Configure::write('Routing.prefixes', array('admin')); - $this->Controller->action = 'index'; - $ScaffoldView =& new TestScaffoldView($this->Controller); + $this->Controller->request->params['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); @@ -348,11 +349,12 @@ class ScaffoldViewTest extends CakeTestCase { $expected = 'cake' . DS . 'libs' . DS . 'view' . DS . 'errors' . DS . 'scaffold_error.ctp'; $this->assertEqual($result, $expected); - $Controller =& new ScaffoldMockController(); + $Controller = new ScaffoldMockController($this->request); $Controller->scaffold = 'admin'; $Controller->viewPath = 'posts'; - $Controller->action = 'admin_edit'; - $ScaffoldView =& new TestScaffoldView($Controller); + $Controller->request['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); @@ -361,12 +363,17 @@ class ScaffoldViewTest extends CakeTestCase { $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 = new ScaffoldMockController($this->request); $Controller->scaffold = 'admin'; $Controller->viewPath = 'tests'; + $Controller->request->addParams(array( + 'plugin' => 'test_plugin', + 'action' => 'admin_add', + 'admin' => true + )); $Controller->plugin = 'test_plugin'; - $Controller->action = 'admin_add'; - $ScaffoldView =& new TestScaffoldView($Controller); + + $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'; @@ -386,10 +393,10 @@ class ScaffoldViewTest extends CakeTestCase { * @return void */ function testGetViewFileNameWithTheme() { - $this->Controller->action = 'index'; + $this->Controller->request['action'] = 'index'; $this->Controller->viewPath = 'posts'; $this->Controller->theme = 'test_theme'; - $ScaffoldView =& new TestScaffoldView($this->Controller); + $ScaffoldView = new TestScaffoldView($this->Controller); $result = $ScaffoldView->testGetFilename('index'); $expected = TEST_CAKE_CORE_INCLUDE_PATH . 'tests' . DS . 'test_app' . DS . 'views' . DS @@ -404,9 +411,6 @@ class ScaffoldViewTest extends CakeTestCase { * @return void */ function testIndexScaffold() { - $this->Controller->action = 'index'; - $this->Controller->here = '/scaffold_mock'; - $this->Controller->webroot = '/'; $params = array( 'plugin' => null, 'pass' => array(), @@ -416,15 +420,18 @@ class ScaffoldViewTest extends CakeTestCase { 'controller' => 'scaffold_mock', 'action' => 'index', ); + $this->Controller->request->addParams($params); + $this->Controller->request->webroot = '/'; + $this->Controller->request->base = ''; + $this->Controller->request->here = '/scaffold_mock/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 = '/'; + Router::setRequestInfo($this->Controller->request); + $this->Controller->constructClasses(); ob_start(); - new Scaffold($this->Controller, $params); + new Scaffold($this->Controller, $this->Controller->request); $result = ob_get_clean(); $this->assertPattern('#

Scaffold Mock

#', $result); @@ -443,28 +450,27 @@ class ScaffoldViewTest extends CakeTestCase { * @return void */ function testViewScaffold() { - $this->Controller->action = 'view'; - $this->Controller->here = '/scaffold_mock'; - $this->Controller->webroot = '/'; + $this->Controller->request->base = ''; + $this->Controller->request->here = '/scaffold_mock'; + $this->Controller->request->webroot = '/'; $params = array( 'plugin' => null, 'pass' => array(1), 'form' => array(), 'named' => array(), - 'url' => array('url' =>'scaffold_mock'), + 'url' => array('url' => 'scaffold_mock/view/1'), 'controller' => 'scaffold_mock', 'action' => 'view', ); + $this->Controller->request->addParams($params); + //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 = '/'; + Router::setRequestInfo($this->Controller->request); $this->Controller->constructClasses(); ob_start(); - new Scaffold($this->Controller, $params); + new Scaffold($this->Controller, $this->Controller->request); $result = ob_get_clean(); $this->assertPattern('/

View Scaffold Mock<\/h2>/', $result); @@ -486,9 +492,10 @@ class ScaffoldViewTest extends CakeTestCase { * @return void */ function testEditScaffold() { - $this->Controller->action = 'edit'; - $this->Controller->here = '/scaffold_mock'; - $this->Controller->webroot = '/'; + $this->Controller->request->base = ''; + $this->Controller->request->webroot = '/'; + $this->Controller->request->here = '/scaffold_mock'; + $params = array( 'plugin' => null, 'pass' => array(1), @@ -498,15 +505,14 @@ class ScaffoldViewTest extends CakeTestCase { 'controller' => 'scaffold_mock', 'action' => 'edit', ); + $this->Controller->request->addParams($params); + //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 = '/'; + Router::setRequestInfo($this->Controller->request); $this->Controller->constructClasses(); ob_start(); - new Scaffold($this->Controller, $params); + new Scaffold($this->Controller, $this->Controller->request); $result = ob_get_clean(); $this->assertPattern('/
'admin_index', 'admin' => 1, ); + $this->Controller->request->base = ''; + $this->Controller->request->webroot = '/'; + $this->Controller->request->here = '/admin/scaffold_mock'; + $this->Controller->request->addParams($params); + //reset, and set router. Router::reload(); - Router::setRequestInfo(array($params, array('base' => '/', 'here' => '/admin/scaffold_mock', 'webroot' => '/'))); - $this->Controller->params = $params; - $this->Controller->controller = 'scaffold_mock'; - $this->Controller->base = '/'; - $this->Controller->action = 'admin_index'; - $this->Controller->here = '/tests/admin/scaffold_mock'; - $this->Controller->webroot = '/'; + Router::setRequestInfo($this->Controller->request); + $this->Controller->scaffold = 'admin'; $this->Controller->constructClasses(); ob_start(); - $Scaffold = new Scaffold($this->Controller, $params); + $Scaffold = new Scaffold($this->Controller, $this->Controller->request); $result = ob_get_clean(); $this->assertPattern('/

Scaffold Mock<\/h2>/', $result); @@ -586,20 +592,20 @@ class ScaffoldViewTest extends CakeTestCase { 'action' => 'admin_edit', 'admin' => 1, ); + $this->Controller->request->base = ''; + $this->Controller->request->webroot = '/'; + $this->Controller->request->here = '/admin/scaffold_mock/edit'; + $this->Controller->request->addParams($params); + //reset, and set router. Router::reload(); - Router::setRequestInfo(array($params, array('base' => '/', 'here' => '/admin/scaffold_mock/edit', 'webroot' => '/'))); - $this->Controller->params = $params; - $this->Controller->controller = 'scaffold_mock'; - $this->Controller->base = '/'; - $this->Controller->action = 'admin_index'; - $this->Controller->here = '/tests/admin/scaffold_mock'; - $this->Controller->webroot = '/'; + Router::setRequestInfo($this->Controller->request); + $this->Controller->scaffold = 'admin'; $this->Controller->constructClasses(); ob_start(); - $Scaffold = new Scaffold($this->Controller, $params); + $Scaffold = new Scaffold($this->Controller, $this->Controller->request); $result = ob_get_clean(); $this->assertPattern('#admin/scaffold_mock/edit/1#', $result); @@ -629,20 +635,20 @@ class ScaffoldViewTest extends CakeTestCase { 'action' => 'member_index', 'member' => 1, ); + $this->Controller->request->base = ''; + $this->Controller->request->webroot = '/'; + $this->Controller->request->here = '/member/scaffold_mock'; + $this->Controller->request->addParams($params); + //reset, and set router. Router::reload(); - Router::setRequestInfo(array($params, array('base' => '/', 'here' => '/member/scaffold_mock', 'webroot' => '/'))); - $this->Controller->params = $params; - $this->Controller->controller = 'scaffold_mock'; - $this->Controller->base = '/'; - $this->Controller->action = 'member_index'; - $this->Controller->here = '/tests/member/scaffold_mock'; - $this->Controller->webroot = '/'; + Router::setRequestInfo($this->Controller->request); + $this->Controller->scaffold = 'member'; $this->Controller->constructClasses(); ob_start(); - $Scaffold = new Scaffold($this->Controller, $params); + $Scaffold = new Scaffold($this->Controller, $this->Controller->request); $result = ob_get_clean(); $this->assertPattern('/

Scaffold Mock<\/h2>/', $result); @@ -685,7 +691,8 @@ class ScaffoldTest extends CakeTestCase { * @return void */ function startTest() { - $this->Controller =& new ScaffoldMockController(); + $request = new CakeRequest(null, false); + $this->Controller = new ScaffoldMockController($request); } /** @@ -706,9 +713,6 @@ class ScaffoldTest extends CakeTestCase { * @return void */ function testScaffoldParams() { - $this->Controller->action = 'admin_edit'; - $this->Controller->here = '/admin/scaffold_mock/edit'; - $this->Controller->webroot = '/'; $params = array( 'plugin' => null, 'pass' => array(), @@ -719,14 +723,16 @@ class ScaffoldTest extends CakeTestCase { 'action' => 'admin_edit', 'admin' => true, ); - //set router. - Router::setRequestInfo(array($params, array('base' => '/', 'here' => 'admin/scaffold_mock', 'webroot' => '/'))); + $this->Controller->request->base = ''; + $this->Controller->request->webroot = '/'; + $this->Controller->request->here = '/admin/scaffold_mock/edit'; + $this->Controller->request->addParams($params); + + //set router. + Router::setRequestInfo($this->Controller->request); - $this->Controller->params = $params; - $this->Controller->controller = 'scaffold_mock'; - $this->Controller->base = '/'; $this->Controller->constructClasses(); - $Scaffold =& new TestScaffoldMock($this->Controller, $params); + $Scaffold = new TestScaffoldMock($this->Controller, $this->Controller->request); $result = $Scaffold->getParams(); $this->assertEqual($result['action'], 'admin_edit'); } @@ -736,9 +742,6 @@ class ScaffoldTest extends CakeTestCase { * @return void */ function testScaffoldVariableSetting() { - $this->Controller->action = 'admin_edit'; - $this->Controller->here = '/admin/scaffold_mock/edit'; - $this->Controller->webroot = '/'; $params = array( 'plugin' => null, 'pass' => array(), @@ -749,14 +752,16 @@ class ScaffoldTest extends CakeTestCase { 'action' => 'admin_edit', 'admin' => true, ); - //set router. - Router::setRequestInfo(array($params, array('base' => '/', 'here' => 'admin/scaffold_mock', 'webroot' => '/'))); + $this->Controller->request->base = ''; + $this->Controller->request->webroot = '/'; + $this->Controller->request->here = '/admin/scaffold_mock/edit'; + $this->Controller->request->addParams($params); + + //set router. + Router::setRequestInfo($this->Controller->request); - $this->Controller->params = $params; - $this->Controller->controller = 'scaffold_mock'; - $this->Controller->base = '/'; $this->Controller->constructClasses(); - $Scaffold =& new TestScaffoldMock($this->Controller, $params); + $Scaffold = new TestScaffoldMock($this->Controller, $this->Controller->request); $result = $Scaffold->controller->viewVars; $this->assertEqual($result['title_for_layout'], 'Scaffold :: Admin Edit :: Scaffold Mock'); @@ -776,9 +781,6 @@ class ScaffoldTest extends CakeTestCase { * @return void */ function testScaffoldFlashMessages() { - $this->Controller->action = 'edit'; - $this->Controller->here = '/scaffold_mock'; - $this->Controller->webroot = '/'; $params = array( 'plugin' => null, 'pass' => array(1), @@ -788,13 +790,15 @@ class ScaffoldTest extends CakeTestCase { 'controller' => 'scaffold_mock', 'action' => 'edit', ); + $this->Controller->request->base = ''; + $this->Controller->request->webroot = '/'; + $this->Controller->request->here = '/scaffold_mock/edit'; + $this->Controller->request->addParams($params); + //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->data = array( + Router::setRequestInfo($this->Controller->request); + $this->Controller->request->data = array( 'ScaffoldMock' => array( 'id' => 1, 'title' => 'New title', @@ -805,7 +809,7 @@ class ScaffoldTest extends CakeTestCase { unset($this->Controller->Session); ob_start(); - new Scaffold($this->Controller, $params); + new Scaffold($this->Controller, $this->Controller->request); $result = ob_get_clean(); $this->assertPattern('/Scaffold Mock has been updated/', $result); } @@ -816,9 +820,6 @@ class ScaffoldTest extends CakeTestCase { * @return void */ function testHabtmFieldAdditionWithScaffoldForm() { - $this->Controller->action = 'edit'; - $this->Controller->here = '/scaffold_mock'; - $this->Controller->webroot = '/'; $params = array( 'plugin' => null, 'pass' => array(1), @@ -828,15 +829,18 @@ class ScaffoldTest extends CakeTestCase { 'controller' => 'scaffold_mock', 'action' => 'edit', ); + $this->Controller->request->base = ''; + $this->Controller->request->webroot = '/'; + $this->Controller->request->here = '/scaffold_mock/edit'; + $this->Controller->request->addParams($params); + //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 = '/'; + Router::setRequestInfo($this->Controller->request); + $this->Controller->constructClasses(); ob_start(); - $Scaffold = new Scaffold($this->Controller, $params); + $Scaffold = new Scaffold($this->Controller, $this->Controller->request); $result = ob_get_clean(); $this->assertPattern('/name="data\[ScaffoldTag\]\[ScaffoldTag\]"/', $result); @@ -849,28 +853,29 @@ class ScaffoldTest extends CakeTestCase { * @return void */ function testEditScaffoldWithScaffoldFields() { - $this->Controller = new ScaffoldMockControllerWithFields(); - $this->Controller->action = 'edit'; - $this->Controller->here = '/scaffold_mock'; - $this->Controller->webroot = '/'; + $request = new CakeRequest(null, false); + $this->Controller = new ScaffoldMockControllerWithFields($request); $params = array( 'plugin' => null, 'pass' => array(1), 'form' => array(), 'named' => array(), - 'url' => array('url' =>'scaffold_mock'), + 'url' => array('url' =>'scaffold_mock/edit'), 'controller' => 'scaffold_mock', 'action' => 'edit', ); + $this->Controller->request->base = ''; + $this->Controller->request->webroot = '/'; + $this->Controller->request->here = '/scaffold_mock/edit'; + $this->Controller->request->addParams($params); + //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 = '/'; + Router::setRequestInfo($this->Controller->request); + $this->Controller->constructClasses(); ob_start(); - new Scaffold($this->Controller, $params); + new Scaffold($this->Controller, $this->Controller->request); $result = ob_get_clean(); $this->assertNoPattern('/textarea name="data\[ScaffoldMock\]\[body\]" cols="30" rows="6" id="ScaffoldMockBody"/', $result);