mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2024-11-15 11:28:25 +00:00
Moved Shell::getAdmin() to ProjectTask
This commit is contained in:
parent
90b7f7f0ee
commit
da99aa1c6a
2 changed files with 67 additions and 12 deletions
|
@ -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
|
||||
*
|
||||
|
|
|
@ -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_');
|
||||
}
|
||||
}
|
||||
?>
|
Loading…
Reference in a new issue