Browse Source

Unskip more tests and fix issues in filenames.

mark_story 12 years ago
parent
commit
c26df7838b

+ 3 - 3
src/Console/Command/Task/ModelTask.php

@@ -504,7 +504,7 @@ class ModelTask extends BakeTask {
 		if (!empty($this->params['no-entity'])) {
 			return;
 		}
-		$name = $model->alias();
+		$name = Inflector::singularize($model->alias());
 
 		$ns = Configure::read('App.namespace');
 		$pluginPath = '';
@@ -514,7 +514,7 @@ class ModelTask extends BakeTask {
 		}
 
 		$data += [
-			'name' => Inflector::singularize($name),
+			'name' => $name,
 			'namespace' => $ns,
 			'plugin' => $this->plugin,
 			'pluginPath' => $pluginPath,
@@ -568,7 +568,7 @@ class ModelTask extends BakeTask {
 		$out = $this->Template->generate('classes', 'table');
 
 		$path = $this->getPath();
-		$filename = $path . 'Table/' . $name . '.php';
+		$filename = $path . 'Table/' . $name . 'Table.php';
 		$this->out("\n" . __d('cake_console', 'Baking table class for %s...', $name), 1, Shell::QUIET);
 		$this->createFile($filename, $out);
 		TableRegistry::clear();

+ 30 - 10
tests/TestCase/Console/Command/Task/ModelTaskTest.php

@@ -570,28 +570,48 @@ class ModelTaskTest extends TestCase {
 		$this->assertContains("protected \$_accessible = ['title', 'body', 'published']", $result);
 	}
 
+/**
+ * test bake() with a -plugin param
+ *
+ * @return void
+ */
+	public function testBakeTableWithPlugin() {
+		$this->Task->plugin = 'ControllerTest';
+
+		// fake plugin path
+		Plugin::load('ControllerTest', array('path' => APP . 'Plugin/ControllerTest/'));
+		$path = APP . 'Plugin/ControllerTest/Model/Table/BakeArticlesTable.php';
+		$this->Task->expects($this->once())->method('createFile')
+			->with($path, $this->logicalAnd(
+				$this->stringContains('namespace ControllerTest\\Model\\Table;'),
+				$this->stringContains('use Cake\\ORM\\Table;'),
+				$this->stringContains('class BakeArticlesTable extends Table {')
+			));
 
+		$model = TableRegistry::get('BakeArticles');
+		$this->Task->bakeTable($model);
+	}
 
 /**
  * test bake() with a -plugin param
  *
  * @return void
  */
-	public function testBakeWithPlugin() {
-		$this->markTestIncomplete('Not done here yet');
+	public function testBakeEntityWithPlugin() {
 		$this->Task->plugin = 'ControllerTest';
 
-		//fake plugin path
+		// fake plugin path
 		Plugin::load('ControllerTest', array('path' => APP . 'Plugin/ControllerTest/'));
-		$path = APP . 'Plugin/ControllerTest/Model/BakeArticle.php';
+		$path = APP . 'Plugin/ControllerTest/Model/Entity/BakeArticle.php';
 		$this->Task->expects($this->once())->method('createFile')
-			->with($path, $this->stringContains('BakeArticle extends ControllerTestAppModel'));
-
-		$result = $this->Task->bake('BakeArticle', array(), array());
-		$this->assertContains("App::uses('ControllerTestAppModel', 'ControllerTest.Model');", $result);
+			->with($path, $this->logicalAnd(
+				$this->stringContains('namespace ControllerTest\\Model\\Entity;'),
+				$this->stringContains('use Cake\\ORM\\Entity;'),
+				$this->stringContains('class BakeArticle extends Entity {')
+			));
 
-		$this->assertEquals(count(ClassRegistry::keys()), 0);
-		$this->assertEquals(count(ClassRegistry::mapKeys()), 0);
+		$model = TableRegistry::get('BakeArticles');
+		$this->Task->bakeEntity($model);
 	}
 
 /**