From da99aa1c6af099ae3a1dd7186716a07409dfca52 Mon Sep 17 00:00:00 2001 From: mark_story Date: Tue, 30 Jun 2009 20:44:09 -0400 Subject: [PATCH] Moved Shell::getAdmin() to ProjectTask --- cake/console/libs/tasks/project.php | 35 ++++++++++++++- .../cases/console/libs/tasks/project.test.php | 44 ++++++++++++++----- 2 files changed, 67 insertions(+), 12 deletions(-) diff --git a/cake/console/libs/tasks/project.php b/cake/console/libs/tasks/project.php index 40d9086d3..2d6d64380 100644 --- a/cake/console/libs/tasks/project.php +++ b/cake/console/libs/tasks/project.php @@ -27,6 +27,12 @@ * @subpackage cake.cake.console.libs.tasks */ class ProjectTask extends Shell { +/** + * configs path (used in testing). + * + * @var string + **/ + var $configPath = null; /** * Checks that given project path does not already exist, and * finds the app directory in it. Then it calls bake() with that information. @@ -241,7 +247,8 @@ class ProjectTask extends Shell { * @access public */ function cakeAdmin($name) { - $File =& new File(CONFIGS . 'core.php'); + $path = (empty($this->configPath)) ? CONFIGS : $this->configPath; + $File =& new File($path . 'core.php'); $contents = $File->read(); if (preg_match('%([/\\t\\x20]*Configure::write\(\'Routing.admin\',[\\t\\x20\'a-z]*\\);)%', $contents, $match)) { $result = str_replace($match[0], "\t" . 'Configure::write(\'Routing.admin\', \''.$name.'\');', $contents); @@ -255,6 +262,32 @@ class ProjectTask extends Shell { return false; } } +/** + * Checks for Configure::read('Routing.admin') and forces user to input it if not enabled + * + * @return string Admin route to use + * @access public + */ + function getAdmin() { + $admin = ''; + $cakeAdmin = null; + $adminRoute = Configure::read('Routing.admin'); + if (!empty($adminRoute)) { + return $adminRoute . '_'; + } + $this->out('You need to enable Configure::write(\'Routing.admin\',\'admin\') in /app/config/core.php to use admin routing.'); + $this->out('What would you like the admin route to be?'); + $this->out('Example: www.example.com/admin/controller'); + while ($admin == '') { + $admin = $this->in("What would you like the admin route to be?", null, 'admin'); + } + if ($this->cakeAdmin($admin) !== true) { + $this->out('Unable to write to /app/config/core.php.'); + $this->out('You need to enable Configure::write(\'Routing.admin\',\'admin\') in /app/config/core.php to use admin routing.'); + $this->_stop(); + } + return $admin . '_'; + } /** * Help * diff --git a/cake/tests/cases/console/libs/tasks/project.test.php b/cake/tests/cases/console/libs/tasks/project.test.php index be1988562..8c987b349 100644 --- a/cake/tests/cases/console/libs/tasks/project.test.php +++ b/cake/tests/cases/console/libs/tasks/project.test.php @@ -80,17 +80,24 @@ class ProjectTaskTest extends CakeTestCase { $Folder =& new Folder($this->Task->path . 'bake_test_app'); $Folder->delete(); } - +/** + * creates a test project that is used for testing project task. + * + * @return void + **/ + function _setupTestProject() { + $skel = CAKE_CORE_INCLUDE_PATH . DS . CONSOLE_LIBS . 'templates' . DS . 'skel'; + $this->Task->setReturnValueAt(0, 'in', 'y'); + $this->Task->setReturnValueAt(1, 'in', 'n'); + $this->Task->bake($this->Task->path . 'bake_test_app', $skel); + } /** * test bake() method and directory creation. * * @return void **/ function testBake() { - $skel = CAKE_CORE_INCLUDE_PATH . DS . CONSOLE_LIBS . 'templates' . DS . 'skel'; - $this->Task->setReturnValueAt(0, 'in', 'y'); - $this->Task->setReturnValueAt(1, 'in', 'n'); - $this->Task->bake($this->Task->path . 'bake_test_app', $skel); + $this->_setupTestProject(); $path = $this->Task->path . 'bake_test_app'; $this->assertTrue(is_dir($path), 'No project dir %s'); @@ -111,18 +118,33 @@ class ProjectTaskTest extends CakeTestCase { * @return void **/ function testSecuritySaltGeneration() { - $skel = CAKE_CORE_INCLUDE_PATH . DS . CONSOLE_LIBS . 'templates' . DS . 'skel'; - $this->Task->setReturnValueAt(0, 'in', 'y'); - $this->Task->setReturnValueAt(1, 'in', 'n'); - $this->Task->bake($this->Task->path . 'bake_test_app', $skel); - + $this->_setupTestProject(); + $path = $this->Task->path . 'bake_test_app' . DS; $result = $this->Task->securitySalt($path); $this->assertTrue($result); - + $file =& new File($path . 'config' . DS . 'core.php'); $contents = $file->read(); $this->assertNoPattern('/DYhG93b0qyJfIxfs2guVoUubWwvniR2G0FgaC9mi/', $contents, 'Default Salt left behind. %s'); } +/** + * test getAdmin method, and that it returns Routing.admin or writes to config file. + * + * @return void + **/ + function testGetAdmin() { + Configure::write('Routing.admin', 'admin'); + $result = $this->Task->getAdmin(); + $this->assertEqual($result, 'admin_'); + + Configure::write('Routing.admin', null); + $this->_setupTestProject(); + $this->Task->configPath = $this->Task->path . 'bake_test_app' . DS . 'config' . DS; + $this->Task->setReturnValue('in', 'super_duper_admin'); + + $result = $this->Task->getAdmin(); + $this->assertEqual($result, 'super_duper_admin_'); + } } ?> \ No newline at end of file