Browse Source

Implement test generation for cell classes.

mark_story 12 years ago
parent
commit
7be6da0482

+ 7 - 0
src/Console/Command/Task/TestTask.php

@@ -52,6 +52,7 @@ class TestTask extends BakeTask {
 		'Behavior' => 'Model\Behavior',
 		'Helper' => 'View\Helper',
 		'Shell' => 'Console\Command',
+		'Cell' => 'View\Cell',
 	];
 
 /**
@@ -67,6 +68,7 @@ class TestTask extends BakeTask {
 		'behavior' => 'Behavior',
 		'helper' => 'Helper',
 		'shell' => 'Shell',
+		'cell' => 'Cell',
 	];
 
 /**
@@ -418,6 +420,11 @@ class TestTask extends BakeTask {
 			$pre = "\$this->io = \$this->getMock('Cake\Console\ConsoleIo');\n";
 			$construct = "new {$className}(\$this->io);\n";
 		}
+		if ($type === 'cell') {
+			$pre = "\$this->request = \$this->getMock('Cake\Network\Request');\n";
+			$pre .= "\t\t\$this->response = \$this->getMock('Cake\Network\Response');\n";
+			$construct = "new {$className}(\$this->request, \$this->response);\n";
+		}
 		return [$pre, $construct, $post];
 	}
 

+ 23 - 0
tests/TestCase/Console/Command/Task/TestTaskTest.php

@@ -260,6 +260,8 @@ class TestTaskTest extends TestCase {
 			['component', 'AuthComponent', 'App\Controller\Component\AuthComponent'],
 			['Shell', 'Example', 'App\Console\Command\ExampleShell'],
 			['shell', 'Example', 'App\Console\Command\ExampleShell'],
+			['Cell', 'Example', 'App\View\Cell\ExampleCell'],
+			['cell', 'Example', 'App\View\Cell\ExampleCell'],
 		];
 	}
 
@@ -308,6 +310,27 @@ class TestTaskTest extends TestCase {
 	}
 
 /**
+ * Test baking a test for a cell.
+ *
+ * @return void
+ */
+	public function testBakeCellTest() {
+		$this->Task->expects($this->once())
+			->method('createFile')
+			->will($this->returnValue(true));
+
+		$result = $this->Task->bake('Cell', 'Articles');
+
+		$this->assertContains("use App\View\Cell\ArticlesCell", $result);
+		$this->assertContains('class ArticlesCellTest extends TestCase', $result);
+
+		$this->assertContains('function setUp()', $result);
+		$this->assertContains("\$this->request = \$this->getMock('Cake\Network\Request')", $result);
+		$this->assertContains("\$this->response = \$this->getMock('Cake\Network\Response')", $result);
+		$this->assertContains("\$this->Articles = new ArticlesCell(\$this->request, \$this->response", $result);
+	}
+
+/**
  * Test baking a test for a concrete model.
  *
  * @return void