diff --git a/cake/libs/controller/scaffold.php b/cake/libs/controller/scaffold.php index 3490c7169..04102c4d9 100644 --- a/cake/libs/controller/scaffold.php +++ b/cake/libs/controller/scaffold.php @@ -434,10 +434,7 @@ class Scaffold extends Object { /** * When methods are now present in a controller * scaffoldView is used to call default Scaffold methods if: - * - * var $scaffold; - * - * is placed in the controller's class definition. + * `var $scaffold;` is placed in the controller's class definition. * * @param array $params Parameters for scaffolding * @return mixed A rendered view of scaffold action, or showing the error @@ -445,23 +442,30 @@ class Scaffold extends Object { */ function __scaffold($params) { $db = &ConnectionManager::getDataSource($this->ScaffoldModel->useDbConfig); - $admin = Configure::read('Routing.admin'); - + $prefixes = Configure::read('Routing.prefixes'); + $scaffoldPrefix = $this->scaffoldActions; + if (isset($db)) { if (empty($this->scaffoldActions)) { $this->scaffoldActions = array( 'index', 'list', 'view', 'add', 'create', 'edit', 'update', 'delete' ); - } elseif (!empty($admin) && $this->scaffoldActions === $admin) { + } elseif (!empty($prefixes) && in_array($this->scaffoldActions, $prefixes)) { $this->scaffoldActions = array( - $admin .'_index', $admin .'_list', $admin .'_view', $admin .'_add', - $admin .'_create', $admin .'_edit', $admin .'_update', $admin .'_delete' + $scaffoldPrefix . '_index', + $scaffoldPrefix . '_list', + $scaffoldPrefix . '_view', + $scaffoldPrefix . '_add', + $scaffoldPrefix . '_create', + $scaffoldPrefix . '_edit', + $scaffoldPrefix . '_update', + $scaffoldPrefix . '_delete' ); } if (in_array($params['action'], $this->scaffoldActions)) { - if (!empty($admin)) { - $params['action'] = str_replace($admin . '_', '', $params['action']); + if (!empty($prefixes)) { + $params['action'] = str_replace($scaffoldPrefix . '_', '', $params['action']); } switch ($params['action']) { case 'index': @@ -556,10 +560,15 @@ class ScaffoldView extends ThemeView { $name = $this->action; } $name = Inflector::underscore($name); - $admin = Configure::read('Routing.admin'); + $prefixes = Configure::read('Routing.prefixes'); - if (!empty($admin) && strpos($name, $admin . '_') !== false) { - $name = substr($name, strlen($admin) + 1); + if (!empty($prefixes)) { + foreach ($prefixes as $prefix) { + if (strpos($name, $prefix . '_') !== false) { + $name = substr($name, strlen($prefix) + 1); + break; + } + } } if ($name === 'add') { diff --git a/cake/tests/cases/libs/controller/scaffold.test.php b/cake/tests/cases/libs/controller/scaffold.test.php index 3d6f5f64b..c0a4a0fcd 100644 --- a/cake/tests/cases/libs/controller/scaffold.test.php +++ b/cake/tests/cases/libs/controller/scaffold.test.php @@ -315,8 +315,8 @@ class ScaffoldViewTest extends CakeTestCase { * @return void */ function testGetViewFilename() { - $_admin = Configure::read('Routing.admin'); - Configure::write('Routing.admin', 'admin'); + $_admin = Configure::read('Routing.prefixes'); + Configure::write('Routing.prefixes', array('admin')); $this->Controller->action = 'index'; $ScaffoldView =& new TestScaffoldView($this->Controller); @@ -385,7 +385,7 @@ class ScaffoldViewTest extends CakeTestCase { . DS .'test_plugin' . DS . 'views' . DS . 'tests' . DS . 'scaffold.edit.ctp'; $this->assertEqual($result, $expected); - Configure::write('Routing.admin', $_admin); + Configure::write('Routing.prefixes', $_admin); } /** @@ -499,7 +499,7 @@ class ScaffoldViewTest extends CakeTestCase { new Scaffold($this->Controller, $params); $result = ob_get_clean(); - $this->assertPattern('/
/', $result); + $this->assertPattern('/assertPattern('/Edit Scaffold Mock<\/legend>/', $result); $this->assertPattern('/input type="hidden" name="data\[ScaffoldMock\]\[id\]" value="1" id="ScaffoldMockId"/', $result); @@ -509,6 +509,7 @@ class ScaffoldViewTest extends CakeTestCase { $this->assertPattern('/textarea name="data\[ScaffoldMock\]\[body\]" cols="30" rows="6" id="ScaffoldMockBody"/', $result); $this->assertPattern('/
  • ]*>Delete<\/a>\s*<\/li>/', $result); } + /** * Test Admin Index Scaffolding. * @@ -516,9 +517,9 @@ class ScaffoldViewTest extends CakeTestCase { * @return void **/ function testAdminIndexScaffold() { - $_backAdmin = Configure::read('Routing.admin'); + $_backAdmin = Configure::read('Routing.prefixes'); - Configure::write('Routing.admin', 'admin'); + Configure::write('Routing.prefixes', array('admin')); $params = array( 'plugin' => null, 'pass' => array(), @@ -551,7 +552,7 @@ class ScaffoldViewTest extends CakeTestCase { //TODO: add testing for table generation $this->assertPattern('/
  • New Scaffold Mock<\/a><\/li>/', $result); - Configure::write('Routing.admin', $_backAdmin); + Configure::write('Routing.prefixes', $_backAdmin); } /** @@ -561,9 +562,9 @@ class ScaffoldViewTest extends CakeTestCase { * @return void **/ function testAdminEditScaffold() { - $_backAdmin = Configure::read('Routing.admin'); + $_backAdmin = Configure::read('Routing.prefixes'); - Configure::write('Routing.admin', 'admin'); + Configure::write('Routing.prefixes', array('admin')); $params = array( 'plugin' => null, 'pass' => array(), @@ -594,8 +595,54 @@ class ScaffoldViewTest extends CakeTestCase { $this->assertPattern('#admin/scaffold_mock/edit/1#', $result); $this->assertPattern('#Scaffold Mock#', $result); - Configure::write('Routing.admin', $_backAdmin); + Configure::write('Routing.prefixes', $_backAdmin); } + +/** + * Test Admin Index Scaffolding. + * + * @access public + * @return void + **/ + 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, + ); + //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 = '/'; + $this->Controller->scaffold = 'member'; + $this->Controller->constructClasses(); + + ob_start(); + $Scaffold = new Scaffold($this->Controller, $params); + $result = ob_get_clean(); + + $this->assertPattern('/

    Scaffold Mock<\/h2>/', $result); + $this->assertPattern('//', $result); + //TODO: add testing for table generation + $this->assertPattern('/
  • New Scaffold Mock<\/a><\/li>/', $result); + + Configure::write('Routing.prefixes', $_backAdmin); + } + } /**