Browse Source

Update remaining tests and fix path issues.

mark_story 12 years ago
parent
commit
eac89bf8bb

+ 16 - 16
src/Console/Command/Task/FixtureTask.php

@@ -30,7 +30,7 @@ class FixtureTask extends BakeTask {
  *
  * @var array
  */
-	public $tasks = ['DbConfig', 'Model', 'Template'];
+	public $tasks = ['Model', 'Template'];
 
 /**
  * path to fixtures directory
@@ -48,7 +48,7 @@ class FixtureTask extends BakeTask {
  */
 	public function __construct($stdout = null, $stderr = null, $stdin = null) {
 		parent::__construct($stdout, $stderr, $stdin);
-		$this->path = APP . 'Test/Fixture/';
+		$this->path = ROOT . '/Test/Fixture/';
 	}
 
 /**
@@ -90,6 +90,9 @@ class FixtureTask extends BakeTask {
 			'help' => __d('cake_console', 'Used with --count and <name>/all commands to pull [n] records from the live tables, where [n] is either --count or the default of 10.'),
 			'short' => 'r',
 			'boolean' => true
+		])->addOption('conditions', [
+			'help' => __d('cake_console', 'The SQL snippet to use when importing records.'),
+			'default' => '1=1',
 		]);
 
 		return $parser;
@@ -430,14 +433,18 @@ class FixtureTask extends BakeTask {
  * @return array Array of records.
  */
 	protected function _getRecordsFromTable($modelName, $useTable = null) {
-		$condition = 'WHERE 1=1';
 		$recordCount = (isset($this->params['count']) ? $this->params['count'] : 10);
-		$model = TableRegistry::get($modelName, [
-			'table' => $useTable,
-			'connection' => ConnectionManager::get($this->connection)
-		]);
+		$conditions = (isset($this->params['conditions']) ? $this->params['conditions'] : '1=1');
+		if (TableRegistry::exists($modelName)) {
+			$model = TableRegistry::get($modelName);
+		} else {
+			$model = TableRegistry::get($modelName, [
+				'table' => $useTable,
+				'connection' => ConnectionManager::get($this->connection)
+			]);
+		}
 		$records = $model->find('all', [
-			'conditions' => $condition,
+			'conditions' => $conditions,
 			'recursive' => -1,
 			'limit' => $recordCount
 		]);
@@ -446,14 +453,7 @@ class FixtureTask extends BakeTask {
 		$alias = $model->alias();
 		$out = [];
 		foreach ($records as $record) {
-			$row = [];
-			foreach ($record[$model->alias] as $field => $value) {
-				if ($schema->columnType($field) === 'boolean') {
-					$value = (int)(bool)$value;
-				}
-				$row[$field] = $value;
-			}
-			$out[] = $row;
+			$out[] = $record->toArray();
 		}
 		return $out;
 	}

+ 12 - 20
tests/TestCase/Console/Command/Task/FixtureTaskTest.php

@@ -78,7 +78,7 @@ class FixtureTaskTest extends TestCase {
 		$in = $this->getMock('Cake\Console\ConsoleInput', array(), array(), '', false);
 
 		$Task = new FixtureTask($out, $out, $in);
-		$this->assertEquals(APP . 'Test/Fixture/', $Task->path);
+		$this->assertEquals(ROOT . '/Test/Fixture/', $Task->path);
 	}
 
 /**
@@ -126,16 +126,13 @@ class FixtureTaskTest extends TestCase {
  * @return void
  */
 	public function testImportRecordsFromDatabaseWithConditionsPoo() {
-		$this->markTestIncomplete('not done');
-		$this->Task->interactive = true;
-		$this->Task->expects($this->at(0))->method('in')
-			->will($this->returnValue('WHERE 1=1'));
-
 		$this->Task->connection = 'test';
 		$this->Task->path = '/my/path/';
 
-		$result = $this->Task->bake('Article', false, array(
-			'fromTable' => true, 'schema' => 'Article', 'records' => false
+		$result = $this->Task->bake('Articles', false, array(
+			'fromTable' => true,
+			'schema' => 'Articles',
+			'records' => false
 		));
 
 		$this->assertContains('namespace App\Test\Fixture;', $result);
@@ -165,19 +162,13 @@ class FixtureTaskTest extends TestCase {
  * @return void
  */
 	public function testImportRecordsNoEscaping() {
-		$this->markTestIncomplete('not done');
 		$db = ConnectionManager::get('test');
 		if ($db instanceof Sqlserver) {
 			$this->markTestSkipped('This test does not run on SQLServer');
 		}
 
 		$articles = TableRegistry::get('Articles');
-		$articles->updateAll(['body' => "'Body \"value\"'"]);
-
-		$this->Task->interactive = true;
-		$this->Task->expects($this->at(0))
-			->method('in')
-			->will($this->returnValue('WHERE 1=1 LIMIT 10'));
+		$articles->updateAll(['body' => "Body \"value\""], []);
 
 		$this->Task->connection = 'test';
 		$this->Task->path = '/my/path/';
@@ -239,21 +230,22 @@ class FixtureTaskTest extends TestCase {
  * @return void
  */
 	public function testAllWithCountAndRecordsFlags() {
-		$this->markTestIncomplete('not done');
 		$this->Task->connection = 'test';
 		$this->Task->path = '/my/path/';
-		$this->Task->args = array('all');
-		$this->Task->params = array('count' => 10, 'records' => true);
+		$this->Task->args = ['all'];
+		$this->Task->params = ['count' => 10, 'records' => true];
 
 		$this->Task->Model->expects($this->any())->method('listAll')
 			->will($this->returnValue(array('Articles', 'comments')));
 
 		$filename = '/my/path/ArticleFixture.php';
-		$this->Task->expects($this->at(0))->method('createFile')
+		$this->Task->expects($this->at(0))
+			->method('createFile')
 			->with($filename, $this->stringContains("'title' => 'Third Article'"));
 
 		$filename = '/my/path/CommentFixture.php';
-		$this->Task->expects($this->at(1))->method('createFile')
+		$this->Task->expects($this->at(1))
+			->method('createFile')
 			->with($filename, $this->stringContains("'comment' => 'First Comment for First Article'"));
 		$this->Task->expects($this->exactly(2))->method('createFile');
 

+ 1 - 0
tests/TestCase/Console/Command/Task/ModelTaskTest.php

@@ -54,6 +54,7 @@ class ModelTaskTest extends TestCase {
 		);
 		$this->Task->connection = 'test';
 		$this->_setupOtherMocks();
+		TableRegistry::clear();
 	}
 
 /**

+ 1 - 5
tests/TestCase/Console/Command/Task/TemplateTaskTest.php

@@ -1,9 +1,5 @@
 <?php
 /**
- * TemplateTask file
- *
- * Test Case for TemplateTask generation shell task
- *
  * CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
  * Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
  *
@@ -24,7 +20,6 @@ use Cake\TestSuite\TestCase;
 
 /**
  * TemplateTaskTest class
- *
  */
 class TemplateTaskTest extends TestCase {
 
@@ -115,6 +110,7 @@ class TemplateTaskTest extends TestCase {
 		$this->Task->initialize();
 		$this->Task->params['theme'] = 'test';
 		$this->Task->set(array(
+			'name' => 'Article',
 			'model' => 'Article',
 			'table' => 'articles',
 			'import' => false,