Skip to content
This repository
Browse code

Moved Shell::getAdmin() to ProjectTask

  • Loading branch information...
commit da99aa1c6af099ae3a1dd7186716a07409dfca52 1 parent 90b7f7f
Mark Story authored June 30, 2009
35  cake/console/libs/tasks/project.php
@@ -28,6 +28,12 @@
28 28
  */
29 29
 class ProjectTask extends Shell {
30 30
 /**
  31
+ * configs path (used in testing).
  32
+ *
  33
+ * @var string
  34
+ **/
  35
+	var $configPath = null;
  36
+/**
31 37
  * Checks that given project path does not already exist, and
32 38
  * finds the app directory in it. Then it calls bake() with that information.
33 39
  *
@@ -241,7 +247,8 @@ function corePath($path) {
241 247
  * @access public
242 248
  */
243 249
 	function cakeAdmin($name) {
244  
-		$File =& new File(CONFIGS . 'core.php');
  250
+		$path = (empty($this->configPath)) ? CONFIGS : $this->configPath;
  251
+		$File =& new File($path . 'core.php');
245 252
 		$contents = $File->read();
246 253
 		if (preg_match('%([/\\t\\x20]*Configure::write\(\'Routing.admin\',[\\t\\x20\'a-z]*\\);)%', $contents, $match)) {
247 254
 			$result = str_replace($match[0], "\t" . 'Configure::write(\'Routing.admin\', \''.$name.'\');', $contents);
@@ -256,6 +263,32 @@ function cakeAdmin($name) {
256 263
 		}
257 264
 	}
258 265
 /**
  266
+ * Checks for Configure::read('Routing.admin') and forces user to input it if not enabled
  267
+ *
  268
+ * @return string Admin route to use
  269
+ * @access public
  270
+ */
  271
+	function getAdmin() {
  272
+		$admin = '';
  273
+		$cakeAdmin = null;
  274
+		$adminRoute = Configure::read('Routing.admin');
  275
+		if (!empty($adminRoute)) {
  276
+		 	return $adminRoute . '_';
  277
+		}
  278
+		$this->out('You need to enable Configure::write(\'Routing.admin\',\'admin\') in /app/config/core.php to use admin routing.');
  279
+		$this->out('What would you like the admin route to be?');
  280
+		$this->out('Example: www.example.com/admin/controller');
  281
+		while ($admin == '') {
  282
+			$admin = $this->in("What would you like the admin route to be?", null, 'admin');
  283
+		}
  284
+		if ($this->cakeAdmin($admin) !== true) {
  285
+			$this->out('Unable to write to /app/config/core.php.');
  286
+			$this->out('You need to enable Configure::write(\'Routing.admin\',\'admin\') in /app/config/core.php to use admin routing.');
  287
+			$this->_stop();
  288
+		}
  289
+		return $admin . '_';
  290
+	}
  291
+/**
259 292
  * Help
260 293
  *
261 294
  * @return void
40  cake/tests/cases/console/libs/tasks/project.test.php
@@ -80,17 +80,24 @@ function endTest() {
80 80
 		$Folder =& new Folder($this->Task->path . 'bake_test_app');
81 81
 		$Folder->delete();
82 82
 	}
83  
-
84 83
 /**
85  
- * test bake() method and directory creation.
  84
+ * creates a test project that is used for testing project task.
86 85
  *
87 86
  * @return void
88 87
  **/
89  
-	function testBake() {
  88
+	function _setupTestProject() {
90 89
 		$skel = CAKE_CORE_INCLUDE_PATH . DS . CONSOLE_LIBS . 'templates' . DS . 'skel';
91 90
 		$this->Task->setReturnValueAt(0, 'in', 'y');
92 91
 		$this->Task->setReturnValueAt(1, 'in', 'n');
93 92
 		$this->Task->bake($this->Task->path . 'bake_test_app', $skel);
  93
+	}
  94
+/**
  95
+ * test bake() method and directory creation.
  96
+ *
  97
+ * @return void
  98
+ **/
  99
+	function testBake() {
  100
+		$this->_setupTestProject();
94 101
 
95 102
 		$path = $this->Task->path . 'bake_test_app';
96 103
 		$this->assertTrue(is_dir($path), 'No project dir %s');
@@ -111,18 +118,33 @@ function testBake() {
111 118
  * @return void
112 119
  **/
113 120
 	function testSecuritySaltGeneration() {
114  
-		$skel = CAKE_CORE_INCLUDE_PATH . DS . CONSOLE_LIBS . 'templates' . DS . 'skel';
115  
-		$this->Task->setReturnValueAt(0, 'in', 'y');
116  
-		$this->Task->setReturnValueAt(1, 'in', 'n');
117  
-		$this->Task->bake($this->Task->path . 'bake_test_app', $skel);
118  
-		
  121
+		$this->_setupTestProject();
  122
+
119 123
 		$path = $this->Task->path . 'bake_test_app' . DS;
120 124
 		$result = $this->Task->securitySalt($path);
121 125
 		$this->assertTrue($result);
122  
-		
  126
+
123 127
 		$file =& new File($path . 'config' . DS . 'core.php');
124 128
 		$contents = $file->read();
125 129
 		$this->assertNoPattern('/DYhG93b0qyJfIxfs2guVoUubWwvniR2G0FgaC9mi/', $contents, 'Default Salt left behind. %s');
126 130
 	}
  131
+/**
  132
+ * test getAdmin method, and that it returns Routing.admin or writes to config file.
  133
+ *
  134
+ * @return void
  135
+ **/
  136
+	function testGetAdmin() {
  137
+		Configure::write('Routing.admin', 'admin');
  138
+		$result = $this->Task->getAdmin();
  139
+		$this->assertEqual($result, 'admin_');
  140
+
  141
+		Configure::write('Routing.admin', null);
  142
+		$this->_setupTestProject();
  143
+		$this->Task->configPath = $this->Task->path . 'bake_test_app' . DS . 'config' . DS;
  144
+		$this->Task->setReturnValue('in', 'super_duper_admin');
  145
+
  146
+		$result = $this->Task->getAdmin();
  147
+		$this->assertEqual($result, 'super_duper_admin_');
  148
+	}
127 149
 }
128 150
 ?>

0 notes on commit da99aa1

Please sign in to comment.
Something went wrong with that request. Please try again.