Skip to content
This repository
Browse code

Adding test case for getName

  • Loading branch information...
commit 68a858b39a310afb1b73b7a48af19461056cdc15 1 parent 9b9b1fb
Mark Story authored May 14, 2009
10  cake/console/libs/tasks/controller.php
@@ -536,16 +536,16 @@ function listAll($useDbConfig = null) {
536 536
 /**
537 537
  * Forces the user to specify the controller he wants to bake, and returns the selected controller name.
538 538
  *
  539
+ * @param string $useDbConfig Connection name to get a controller name for.
539 540
  * @return string Controller name
540 541
  * @access public
541 542
  */
542  
-	function getName() {
543  
-		$useDbConfig = 'default';
  543
+	function getName($useDbConfig = null) {
544 544
 		$controllers = $this->listAll($useDbConfig);
545 545
 		$enteredController = '';
546 546
 
547 547
 		while ($enteredController == '') {
548  
-			$enteredController = $this->in(__("Enter a number from the list above, type in the name of another controller, or 'q' to exit", true), null, 'q');
  548
+			$enteredController = $this->in(__("Enter a number from the list above,\ntype in the name of another controller, or 'q' to exit", true), null, 'q');
549 549
 
550 550
 			if ($enteredController === 'q') {
551 551
 				$this->out(__("Exit", true));
@@ -553,8 +553,7 @@ function getName() {
553 553
 			}
554 554
 
555 555
 			if ($enteredController == '' || intval($enteredController) > count($controllers)) {
556  
-				$this->out(__('Error:', true));
557  
-				$this->out(__("The Controller name you supplied was empty, or the number \nyou selected was not an option. Please try again.", true));
  556
+				$this->err(__("The Controller name you supplied was empty,\nor the number you selected was not an option. Please try again.", true));
558 557
 				$enteredController = '';
559 558
 			}
560 559
 		}
@@ -564,7 +563,6 @@ function getName() {
564 563
 		} else {
565 564
 			$controllerName = Inflector::camelize($enteredController);
566 565
 		}
567  
-
568 566
 		return $controllerName;
569 567
 	}
570 568
 /**
27  cake/tests/cases/console/libs/tasks/controller.test.php
@@ -119,5 +119,32 @@ function testListAll() {
119 119
 		$expected = array('articles', 'articles_tags', 'comments', 'tags');
120 120
 		$this->assertEqual($result, $expected);	
121 121
 	}
  122
+
  123
+/**
  124
+ * Test that getName interacts with the user and returns the controller name.
  125
+ *
  126
+ * @return void
  127
+ **/
  128
+	function testGetName() {
  129
+		$this->Task->setReturnValue('in', 1);
  130
+
  131
+		$this->Task->setReturnValueAt(0, 'in', 'q');
  132
+		$this->Task->expectOnce('_stop');
  133
+		$this->Task->getName('test_suite');
  134
+
  135
+		$this->Task->setReturnValueAt(1, 'in', 1);
  136
+		$result = $this->Task->getName('test_suite');
  137
+		$expected = 'Articles';
  138
+		$this->assertEqual($result, $expected);
  139
+
  140
+		$this->Task->setReturnValueAt(2, 'in', 3);
  141
+		$result = $this->Task->getName('test_suite');
  142
+		$expected = 'Comments';
  143
+		$this->assertEqual($result, $expected);
  144
+
  145
+		$this->Task->setReturnValueAt(3, 'in', 10);
  146
+		$result = $this->Task->getName('test_suite');
  147
+		$this->Task->expectOnce('err');
  148
+	}
122 149
 }
123 150
 ?>

0 notes on commit 68a858b

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