Skip to content
Permalink
Browse files

Moved Shell::getAdmin() to ProjectTask

  • Loading branch information...
markstory committed Jul 1, 2009
1 parent 90b7f7f commit da99aa1c6af099ae3a1dd7186716a07409dfca52
Showing with 65 additions and 10 deletions.
  1. +34 −1 cake/console/libs/tasks/project.php
  2. +31 −9 cake/tests/cases/console/libs/tasks/project.test.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 @@ function corePath($path) {
* @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 @@ function cakeAdmin($name) {
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
*
@@ -80,17 +80,24 @@ function endTest() {
$Folder =& new Folder($this->Task->path . 'bake_test_app');
$Folder->delete();
}
/**
* test bake() method and directory creation.
* creates a test project that is used for testing project task.
*
* @return void
**/
function testBake() {
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() {
$this->_setupTestProject();
$path = $this->Task->path . 'bake_test_app';
$this->assertTrue(is_dir($path), 'No project dir %s');
@@ -111,18 +118,33 @@ function testBake() {
* @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_');
}
}
?>

0 comments on commit da99aa1

Please sign in to comment.
You can’t perform that action at this time.