Browse Source

Add additional tests for bake commands for plugin.name

Add tests to the various bake tasks for using Plugin.Name style
parameters.

Refs #3512
mark_story 12 years ago
parent
commit
b91b066e37

+ 26 - 1
tests/TestCase/Console/Command/Task/CellTaskTest.php

@@ -74,12 +74,37 @@ class CellTaskTest extends TestCase {
 	}
 
 /**
- * Test baking within a plugin.
+ * Test main within a plugin.
  *
  * @return void
  */
 	public function testMainPlugin() {
 		Plugin::load('TestPlugin');
+		$path = Plugin::path('TestPlugin');
+
+		$this->Task->expects($this->at(0))
+			->method('createFile')
+			->with(
+				$this->_normalizePath($path . 'Template/Cell/Example/display.ctp'),
+				''
+			);
+		$this->Task->expects($this->at(1))
+			->method('createFile')
+			->with(
+				$this->_normalizePath($path . 'View/Cell/ExampleCell.php'),
+				$this->stringContains('class ExampleCell extends Cell')
+			);
+
+		$this->Task->main('TestPlugin.Example');
+	}
+
+/**
+ * Test baking within a plugin.
+ *
+ * @return void
+ */
+	public function testBakePlugin() {
+		Plugin::load('TestPlugin');
 
 		$path = Plugin::path('TestPlugin');
 

+ 22 - 2
tests/TestCase/Console/Command/Task/ControllerTaskTest.php

@@ -213,7 +213,6 @@ class ControllerTaskTest extends TestCase {
 	public function testBakeWithPlugin() {
 		$this->Task->plugin = 'ControllerTest';
 
-		//fake plugin path
 		Plugin::load('ControllerTest', array('path' => APP . 'Plugin/ControllerTest/'));
 		$path = APP . 'Plugin/ControllerTest/Controller/BakeArticlesController.php';
 
@@ -227,11 +226,11 @@ class ControllerTaskTest extends TestCase {
 		$result = $this->Task->bake('BakeArticles');
 		$this->assertContains('namespace ControllerTest\Controller;', $result);
 		$this->assertContains('use ControllerTest\Controller\AppController;', $result);
-
 		Plugin::unload();
 	}
 
 /**
+ *
  * test that bakeActions is creating the correct controller Code. (Using sessions)
  *
  * @return void
@@ -346,4 +345,25 @@ class ControllerTaskTest extends TestCase {
 		$this->Task->main($name);
 	}
 
+/**
+ * test main with plugin.name
+ *
+ * @return void
+ */
+	public function testMainWithPluginDot() {
+		$this->Task->connection = 'test';
+
+		Plugin::load('ControllerTest', array('path' => APP . 'Plugin/ControllerTest/'));
+		$path = APP . 'Plugin/ControllerTest/Controller/BakeArticlesController.php';
+
+		$this->Task->expects($this->at(1))
+			->method('createFile')
+			->with(
+				$this->_normalizePath($path),
+				$this->stringContains('BakeArticlesController extends AppController')
+			)->will($this->returnValue(true));
+
+		$this->Task->main('ControllerTest.BakeArticles');
+	}
+
 }

+ 18 - 0
tests/TestCase/Console/Command/Task/FixtureTaskTest.php

@@ -206,6 +206,24 @@ class FixtureTaskTest extends TestCase {
 	}
 
 /**
+ * test that execute passes runs bake depending with named model.
+ *
+ * @return void
+ */
+	public function testMainWithPluginModel() {
+		$this->Task->connection = 'test';
+		$filename = $this->_normalizePath(TEST_APP . 'Plugin/TestPlugin/Test/Fixture/ArticleFixture.php');
+
+		Plugin::load('TestPlugin');
+
+		$this->Task->expects($this->at(0))
+			->method('createFile')
+			->with($filename, $this->stringContains('class ArticleFixture'));
+
+		$this->Task->main('TestPlugin.Article');
+	}
+
+/**
  * test that execute runs all() when args[0] = all
  *
  * @return void

+ 23 - 2
tests/TestCase/Console/Command/Task/SimpleBakeTaskTest.php

@@ -62,11 +62,11 @@ class SimpleBakeTaskTest extends TestCase {
 	}
 
 /**
- * Test the excute method.
+ * Test the main method.
  *
  * @return void
  */
-	public function testExecute() {
+	public function testMain() {
 		$this->Task->expects($this->once())
 			->method('createFile')
 			->with(
@@ -81,6 +81,27 @@ class SimpleBakeTaskTest extends TestCase {
 	}
 
 /**
+ * Test the main with plugin.name method.
+ *
+ * @return void
+ */
+	public function testMainWithPlugin() {
+		Plugin::load('TestPlugin');
+		$filename = $this->_normalizePath(TEST_APP . 'Plugin/TestPlugin/Model/Behavior/ExampleBehavior.php');
+		$this->Task->expects($this->once())
+			->method('createFile')
+			->with(
+				$filename,
+				$this->stringContains('class ExampleBehavior extends Behavior')
+			);
+		$this->Task->Test->expects($this->once())
+			->method('bake')
+			->with('behavior', 'Example');
+
+		$this->Task->main('TestPlugin.Example');
+	}
+
+/**
  * Test generating code.
  *
  * @return void

+ 19 - 0
tests/TestCase/Console/Command/Task/ViewTaskTest.php

@@ -539,6 +539,25 @@ class ViewTaskTest extends TestCase {
 	}
 
 /**
+ * test that plugin.name works.
+ *
+ * @return void
+ */
+	public function testMainWithPluginName() {
+		$this->_setupTask(['in', 'err', 'createFile']);
+
+		$this->Task->connection = 'test';
+		$filename = $this->_normalizePath(TEST_APP . 'Plugin/TestPlugin/Template/ViewTaskComments/index.ctp');
+
+		Plugin::load('TestPlugin');
+
+		$this->Task->expects($this->at(0))
+			->method('createFile')
+			->with($filename);
+		$this->Task->main('TestPlugin.ViewTaskComments');
+	}
+
+/**
  * static dataprovider for test cases
  *
  * @return void