Fixing interactions with Routing.prefixes in Controller and View task.

This commit is contained in:
mark_story 2009-10-07 01:35:29 -04:00
parent 1110f3e1c2
commit 4b862de085
3 changed files with 19 additions and 16 deletions

View file

@ -88,15 +88,15 @@ class ControllerTask extends Shell {
} elseif (!empty($this->args[1]) && $this->args[1] == 'admin') {
$admin = $this->Project->getPrefix();
if ($admin) {
$this->out('Adding ' . Configure::read('Routing.admin') .' methods');
$actions= $this->bakeActions($controller, $admin);
$this->out(sprintf(__('Adding %s methods', true), $admin));
$actions = $this->bakeActions($controller, $admin);
}
}
if (!empty($this->args[2]) && $this->args[2] == 'admin') {
$admin = $this->Project->getPrefix();
if ($admin) {
$this->out('Adding ' . Configure::read('Routing.admin') .' methods');
$this->out(sprintf(__('Adding %s methods', true), $admin));
$actions .= "\n" . $this->bakeActions($controller, $admin);
}
}

View file

@ -156,13 +156,13 @@ class ViewTask extends Shell {
$scaffoldActions = true;
$methods = $this->scaffoldActions;
}
$adminRoute = Configure::read('Routing.admin');
$adminRoute = $this->Project->getPrefix();
foreach ($methods as $i => $method) {
if ($adminRoute && isset($this->params['admin'])) {
if ($scaffoldActions) {
$methods[$i] = $adminRoute . '_' . $method;
$methods[$i] = $adminRoute . $method;
continue;
} elseif (strpos($method, $adminRoute . '_') === false) {
} elseif (strpos($method, $adminRoute) === false) {
unset($methods[$i]);
}
}
@ -403,9 +403,11 @@ class ViewTask extends Shell {
return $this->template;
}
$template = $action;
$adminRoute = Configure::read('Routing.admin');
if (!empty($adminRoute) && strpos($template, $adminRoute) !== false) {
$template = str_replace($adminRoute . '_', '', $template);
$prefixes = Configure::read('Routing.prefixes');
foreach ((array)$prefixes as $prefix) {
if (strpos($template, $prefix) !== false) {
$template = str_replace($prefix . '_', '', $template);
}
}
if (in_array($template, array('add', 'edit'))) {
$template = 'form';

View file

@ -181,8 +181,8 @@ class ViewTaskTest extends CakeTestCase {
* @return void
**/
function testGetContentWithAdminAction() {
$_back = Configure::read('Routing.admin');
Configure::write('Routing.admin', 'admin');
$_back = Configure::read('Routing');
Configure::write('Routing.prefixes', array('admin'));
$vars = array(
'modelClass' => 'TestViewModel',
'schema' => array(),
@ -206,7 +206,7 @@ class ViewTaskTest extends CakeTestCase {
$this->assertPattern('/testViewModel\[\'TestViewModel\'\]\[\'name\'\]/', $result);
$this->assertPattern('/testViewModel\[\'TestViewModel\'\]\[\'body\'\]/', $result);
Configure::write('Routing.admin', $_back);
Configure::write('Routing', $_back);
}
/**
@ -347,10 +347,11 @@ class ViewTaskTest extends CakeTestCase {
* @return void
**/
function testExecuteWithControllerAndAdminFlag() {
$_back = Configure::read('Routing.admin');
Configure::write('Routing.admin', 'admin');
$_back = Configure::read('Routing');
Configure::write('Routing.prefixes', array('admin'));
$this->Task->args[0] = 'ViewTaskArticles';
$this->Task->params['admin'] = 1;
$this->Task->Project->setReturnValue('getPrefix', 'admin_');
$this->Task->expectCallCount('createFile', 4);
$this->Task->expectAt(0, 'createFile', array(TMP . 'view_task_articles' . DS . 'admin_index.ctp', '*'));
@ -359,7 +360,7 @@ class ViewTaskTest extends CakeTestCase {
$this->Task->expectAt(3, 'createFile', array(TMP . 'view_task_articles' . DS . 'admin_edit.ctp', '*'));
$this->Task->execute();
Configure::write('Routing.admin', $_back);
Configure::write('Routing', $_back);
}
/**
@ -423,7 +424,7 @@ class ViewTaskTest extends CakeTestCase {
* @return void
**/
function testExecuteInteractiveWithAdmin() {
Configure::write('Routing.admin', 'admin');
Configure::write('Routing.prefixes', array('admin'));
$this->Task->connection = 'test_suite';
$this->Task->args = array();