2009-04-30 02:40:49 +00:00
|
|
|
<?php
|
|
|
|
/**
|
2009-05-13 01:35:06 +00:00
|
|
|
* FixtureTask Test case
|
2009-04-30 02:40:49 +00:00
|
|
|
*
|
2017-06-10 21:33:55 +00:00
|
|
|
* CakePHP(tm) : Rapid Development Framework (https://cakephp.org)
|
2017-06-10 22:10:52 +00:00
|
|
|
* Copyright (c) Cake Software Foundation, Inc. (https://cakefoundation.org)
|
2009-04-30 02:40:49 +00:00
|
|
|
*
|
|
|
|
* Licensed under The MIT License
|
2013-02-08 12:22:51 +00:00
|
|
|
* For full copyright and license information, please see the LICENSE.txt
|
2009-04-30 02:40:49 +00:00
|
|
|
* Redistributions of files must retain the above copyright notice.
|
|
|
|
*
|
2017-06-10 22:10:52 +00:00
|
|
|
* @copyright Copyright (c) Cake Software Foundation, Inc. (https://cakefoundation.org)
|
2017-06-10 21:33:55 +00:00
|
|
|
* @link https://cakephp.org CakePHP(tm) Project
|
2011-07-26 06:16:14 +00:00
|
|
|
* @package Cake.Test.Case.Console.Command.Task
|
2009-05-13 01:35:06 +00:00
|
|
|
* @since CakePHP(tm) v 1.3
|
2017-06-10 22:23:14 +00:00
|
|
|
* @license https://opensource.org/licenses/mit-license.php MIT License
|
2009-04-30 02:40:49 +00:00
|
|
|
*/
|
|
|
|
|
2010-12-09 03:45:18 +00:00
|
|
|
App::uses('ShellDispatcher', 'Console');
|
|
|
|
App::uses('Shell', 'Console');
|
2011-03-08 05:21:58 +00:00
|
|
|
App::uses('ConsoleOutput', 'Console');
|
|
|
|
App::uses('ConsoleInput', 'Console');
|
2011-11-21 04:00:58 +00:00
|
|
|
App::uses('ModelTask', 'Console/Command/Task');
|
2010-12-09 03:45:18 +00:00
|
|
|
App::uses('FixtureTask', 'Console/Command/Task');
|
|
|
|
App::uses('TemplateTask', 'Console/Command/Task');
|
|
|
|
App::uses('DbConfigTask', 'Console/Command/Task');
|
2009-04-30 02:40:49 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* FixtureTaskTest class
|
|
|
|
*
|
2011-07-26 06:16:14 +00:00
|
|
|
* @package Cake.Test.Case.Console.Command.Task
|
2009-04-30 02:40:49 +00:00
|
|
|
*/
|
|
|
|
class FixtureTaskTest extends CakeTestCase {
|
2009-07-26 09:59:51 +00:00
|
|
|
|
2009-04-30 02:40:49 +00:00
|
|
|
/**
|
|
|
|
* fixtures
|
|
|
|
*
|
|
|
|
* @var array
|
2009-11-14 12:18:31 +00:00
|
|
|
*/
|
2011-09-03 11:34:51 +00:00
|
|
|
public $fixtures = array('core.article', 'core.comment', 'core.datatype', 'core.binary_test', 'core.user');
|
2009-07-26 09:59:51 +00:00
|
|
|
|
2011-09-29 03:27:50 +00:00
|
|
|
/**
|
|
|
|
* Whether backup global state for each test method or not
|
|
|
|
*
|
2014-07-03 13:36:42 +00:00
|
|
|
* @var bool
|
2011-09-29 03:27:50 +00:00
|
|
|
*/
|
|
|
|
public $backupGlobals = false;
|
|
|
|
|
2009-04-30 02:40:49 +00:00
|
|
|
/**
|
2010-09-26 01:36:49 +00:00
|
|
|
* setUp method
|
2009-04-30 02:40:49 +00:00
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
2022-12-28 07:03:39 +00:00
|
|
|
public function setUp() : void {
|
2010-09-26 01:36:49 +00:00
|
|
|
parent::setUp();
|
2010-10-07 02:52:42 +00:00
|
|
|
$out = $this->getMock('ConsoleOutput', array(), array(), '', false);
|
|
|
|
$in = $this->getMock('ConsoleInput', array(), array(), '', false);
|
2010-10-06 04:15:51 +00:00
|
|
|
|
2011-05-16 22:49:00 +00:00
|
|
|
$this->Task = $this->getMock('FixtureTask',
|
2010-10-06 04:15:51 +00:00
|
|
|
array('in', 'err', 'createFile', '_stop', 'clear'),
|
2010-10-24 19:27:04 +00:00
|
|
|
array($out, $out, $in)
|
2010-06-10 04:25:23 +00:00
|
|
|
);
|
2011-09-29 03:27:50 +00:00
|
|
|
$this->Task->Model = $this->getMock('ModelTask',
|
|
|
|
array('in', 'out', 'err', 'createFile', 'getName', 'getTable', 'listAll'),
|
2010-10-24 19:27:04 +00:00
|
|
|
array($out, $out, $in)
|
2010-06-10 04:25:23 +00:00
|
|
|
);
|
2010-10-24 19:27:04 +00:00
|
|
|
$this->Task->Template = new TemplateTask($out, $out, $in);
|
|
|
|
$this->Task->DbConfig = $this->getMock('DbConfigTask', array(), array($out, $out, $in));
|
2009-05-13 01:26:37 +00:00
|
|
|
$this->Task->Template->initialize();
|
2009-04-30 02:40:49 +00:00
|
|
|
}
|
2009-07-26 09:59:51 +00:00
|
|
|
|
2009-04-30 02:40:49 +00:00
|
|
|
/**
|
2010-09-26 01:36:49 +00:00
|
|
|
* tearDown method
|
2009-04-30 02:40:49 +00:00
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
2022-12-28 07:03:39 +00:00
|
|
|
public function tearDown() : void {
|
2010-09-26 01:36:49 +00:00
|
|
|
parent::tearDown();
|
2010-10-24 19:27:04 +00:00
|
|
|
unset($this->Task);
|
2009-04-30 02:40:49 +00:00
|
|
|
}
|
2009-07-26 09:59:51 +00:00
|
|
|
|
2009-04-30 02:40:49 +00:00
|
|
|
/**
|
|
|
|
* test that initialize sets the path
|
|
|
|
*
|
|
|
|
* @return void
|
2009-11-14 12:18:31 +00:00
|
|
|
*/
|
2010-04-05 03:19:38 +00:00
|
|
|
public function testConstruct() {
|
2010-10-07 02:52:42 +00:00
|
|
|
$out = $this->getMock('ConsoleOutput', array(), array(), '', false);
|
|
|
|
$in = $this->getMock('ConsoleInput', array(), array(), '', false);
|
2009-04-30 02:40:49 +00:00
|
|
|
|
2010-10-24 19:27:04 +00:00
|
|
|
$Task = new FixtureTask($out, $out, $in);
|
2012-03-23 06:37:12 +00:00
|
|
|
$this->assertEquals(APP . 'Test' . DS . 'Fixture' . DS, $Task->path);
|
2009-04-30 02:40:49 +00:00
|
|
|
}
|
2009-07-26 09:59:51 +00:00
|
|
|
|
2009-04-30 02:40:49 +00:00
|
|
|
/**
|
|
|
|
* test import option array generation
|
|
|
|
*
|
|
|
|
* @return void
|
2009-11-14 12:18:31 +00:00
|
|
|
*/
|
2010-06-10 04:25:23 +00:00
|
|
|
public function testImportOptionsSchemaRecords() {
|
2016-04-23 20:15:54 +00:00
|
|
|
$this->Task->interactive = true;
|
2010-06-10 04:25:23 +00:00
|
|
|
$this->Task->expects($this->at(0))->method('in')->will($this->returnValue('y'));
|
|
|
|
$this->Task->expects($this->at(1))->method('in')->will($this->returnValue('y'));
|
2009-04-30 02:40:49 +00:00
|
|
|
|
|
|
|
$result = $this->Task->importOptions('Article');
|
|
|
|
$expected = array('schema' => 'Article', 'records' => true);
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertEquals($expected, $result);
|
2010-06-10 04:25:23 +00:00
|
|
|
}
|
2009-05-04 01:43:22 +00:00
|
|
|
|
2010-06-10 04:25:23 +00:00
|
|
|
/**
|
|
|
|
* test importOptions choosing nothing.
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function testImportOptionsNothing() {
|
2016-04-23 20:15:54 +00:00
|
|
|
$this->Task->interactive = true;
|
2010-06-10 04:25:23 +00:00
|
|
|
$this->Task->expects($this->at(0))->method('in')->will($this->returnValue('n'));
|
|
|
|
$this->Task->expects($this->at(1))->method('in')->will($this->returnValue('n'));
|
|
|
|
$this->Task->expects($this->at(2))->method('in')->will($this->returnValue('n'));
|
2009-04-30 02:40:49 +00:00
|
|
|
|
|
|
|
$result = $this->Task->importOptions('Article');
|
|
|
|
$expected = array();
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertEquals($expected, $result);
|
2010-06-10 04:25:23 +00:00
|
|
|
}
|
2011-05-16 22:49:00 +00:00
|
|
|
|
2013-05-01 22:19:46 +00:00
|
|
|
/**
|
|
|
|
* test importOptions with overwriting command line options.
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function testImportOptionsWithCommandLineOptions() {
|
|
|
|
$this->Task->params = array('schema' => true, 'records' => true);
|
|
|
|
|
|
|
|
$result = $this->Task->importOptions('Article');
|
2016-04-23 20:15:54 +00:00
|
|
|
$expected = array('schema' => 'Article', 'fromTable' => true);
|
2013-05-01 22:19:46 +00:00
|
|
|
$this->assertEquals($expected, $result);
|
|
|
|
}
|
|
|
|
|
2016-04-23 20:18:15 +00:00
|
|
|
/**
|
|
|
|
* test importOptions with overwriting CLI options
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function testImportOptionsWithCommandLineOptionsPlugin() {
|
|
|
|
$this->Task->params = array('schema' => true, 'records' => true, 'plugin' => 'TestPlugin');
|
|
|
|
|
|
|
|
$result = $this->Task->importOptions('Article');
|
|
|
|
$expected = array('schema' => 'TestPlugin.Article', 'fromTable' => true);
|
|
|
|
$this->assertEquals($expected, $result);
|
|
|
|
}
|
|
|
|
|
2013-05-01 22:19:46 +00:00
|
|
|
/**
|
|
|
|
* test importOptions with schema.
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function testImportOptionsWithSchema() {
|
2016-04-23 20:15:54 +00:00
|
|
|
$this->Task->interactive = true;
|
2013-05-01 22:19:46 +00:00
|
|
|
$this->Task->params = array('schema' => true);
|
|
|
|
$this->Task->expects($this->at(0))->method('in')->will($this->returnValue('n'));
|
|
|
|
$this->Task->expects($this->at(1))->method('in')->will($this->returnValue('n'));
|
|
|
|
|
|
|
|
$result = $this->Task->importOptions('Article');
|
|
|
|
$expected = array('schema' => 'Article');
|
|
|
|
$this->assertEquals($expected, $result);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* test importOptions with records.
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function testImportOptionsWithRecords() {
|
2016-04-23 20:15:54 +00:00
|
|
|
$this->Task->interactive = true;
|
2013-05-01 22:19:46 +00:00
|
|
|
$this->Task->params = array('records' => true);
|
|
|
|
$this->Task->expects($this->at(0))->method('in')->will($this->returnValue('n'));
|
|
|
|
|
|
|
|
$result = $this->Task->importOptions('Article');
|
2016-04-23 20:15:54 +00:00
|
|
|
$expected = array('fromTable' => true);
|
2013-05-01 22:19:46 +00:00
|
|
|
$this->assertEquals($expected, $result);
|
|
|
|
}
|
|
|
|
|
2010-06-10 04:25:23 +00:00
|
|
|
/**
|
|
|
|
* test importOptions choosing from Table.
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function testImportOptionsTable() {
|
2016-04-23 20:15:54 +00:00
|
|
|
$this->Task->interactive = true;
|
2010-06-10 04:25:23 +00:00
|
|
|
$this->Task->expects($this->at(0))->method('in')->will($this->returnValue('n'));
|
|
|
|
$this->Task->expects($this->at(1))->method('in')->will($this->returnValue('n'));
|
|
|
|
$this->Task->expects($this->at(2))->method('in')->will($this->returnValue('y'));
|
2009-07-20 04:59:18 +00:00
|
|
|
$result = $this->Task->importOptions('Article');
|
|
|
|
$expected = array('fromTable' => true);
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertEquals($expected, $result);
|
2009-04-30 02:40:49 +00:00
|
|
|
}
|
2009-07-26 09:59:51 +00:00
|
|
|
|
2009-07-21 04:00:39 +00:00
|
|
|
/**
|
|
|
|
* test generating a fixture with database conditions.
|
|
|
|
*
|
|
|
|
* @return void
|
2009-11-14 12:18:31 +00:00
|
|
|
*/
|
2010-10-06 04:15:51 +00:00
|
|
|
public function testImportRecordsFromDatabaseWithConditionsPoo() {
|
2010-03-05 02:57:48 +00:00
|
|
|
$this->Task->interactive = true;
|
2010-06-10 04:25:23 +00:00
|
|
|
$this->Task->expects($this->at(0))->method('in')
|
2011-06-20 23:33:00 +00:00
|
|
|
->will($this->returnValue('WHERE 1=1'));
|
2015-07-23 16:03:42 +00:00
|
|
|
$this->Task->expects($this->at(1))->method('in')
|
|
|
|
->with($this->anything(), $this->anything(), '3')
|
|
|
|
->will($this->returnValue('2'));
|
2010-06-10 04:25:23 +00:00
|
|
|
|
2010-09-20 02:58:30 +00:00
|
|
|
$this->Task->connection = 'test';
|
2009-07-21 04:00:39 +00:00
|
|
|
$this->Task->path = '/my/path/';
|
2010-06-10 04:25:23 +00:00
|
|
|
|
|
|
|
$result = $this->Task->bake('Article', false, array(
|
|
|
|
'fromTable' => true, 'schema' => 'Article', 'records' => false
|
|
|
|
));
|
2009-07-21 04:02:08 +00:00
|
|
|
|
2022-12-30 08:53:58 +00:00
|
|
|
$this->assertStringContainsString('class ArticleFixture extends CakeTestFixture', $result);
|
|
|
|
$this->assertStringContainsString('public $records', $result);
|
|
|
|
$this->assertStringContainsString('public $import', $result);
|
|
|
|
$this->assertStringContainsString("'title' => 'First Article'", $result, 'Missing import data');
|
|
|
|
$this->assertStringContainsString('Second Article', $result, 'Missing import data');
|
2009-07-21 04:00:39 +00:00
|
|
|
}
|
2009-07-26 09:59:51 +00:00
|
|
|
|
2011-01-09 04:49:19 +00:00
|
|
|
/**
|
|
|
|
* test that connection gets set to the import options when a different connection is used.
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
2011-05-30 20:02:32 +00:00
|
|
|
public function testImportOptionsAlternateConnection() {
|
2011-01-09 04:49:19 +00:00
|
|
|
$this->Task->connection = 'test';
|
|
|
|
$result = $this->Task->bake('Article', false, array('schema' => 'Article'));
|
2022-12-30 08:53:58 +00:00
|
|
|
$this->assertStringContainsString("'connection' => 'test'", $result);
|
2011-01-09 04:49:19 +00:00
|
|
|
}
|
|
|
|
|
2011-08-29 02:07:59 +00:00
|
|
|
/**
|
|
|
|
* Ensure that fixture data doesn't get overly escaped.
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
2012-02-17 07:13:12 +00:00
|
|
|
public function testImportRecordsNoEscaping() {
|
2012-01-07 03:21:54 +00:00
|
|
|
$db = ConnectionManager::getDataSource('test');
|
|
|
|
if ($db instanceof Sqlserver) {
|
|
|
|
$this->markTestSkipped('This test does not run on SQLServer');
|
|
|
|
}
|
|
|
|
|
2011-08-29 02:07:59 +00:00
|
|
|
$Article = ClassRegistry::init('Article');
|
|
|
|
$Article->updateAll(array('body' => "'Body \"value\"'"));
|
|
|
|
|
|
|
|
$this->Task->interactive = true;
|
|
|
|
$this->Task->expects($this->at(0))
|
|
|
|
->method('in')
|
|
|
|
->will($this->returnValue('WHERE 1=1 LIMIT 10'));
|
|
|
|
|
|
|
|
$this->Task->connection = 'test';
|
|
|
|
$this->Task->path = '/my/path/';
|
|
|
|
$result = $this->Task->bake('Article', false, array(
|
2011-10-28 05:01:17 +00:00
|
|
|
'fromTable' => true,
|
2011-08-29 02:07:59 +00:00
|
|
|
'schema' => 'Article',
|
|
|
|
'records' => false
|
|
|
|
));
|
2022-12-30 08:53:58 +00:00
|
|
|
$this->assertStringContainsString("'body' => 'Body \"value\"'", $result, 'Data has bad escaping');
|
2011-08-29 02:07:59 +00:00
|
|
|
}
|
|
|
|
|
2016-04-23 20:15:54 +00:00
|
|
|
/**
|
|
|
|
* test that execute includes import options
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function testExecuteWithImportSchema() {
|
|
|
|
$this->Task->connection = 'test';
|
|
|
|
$this->Task->path = '/my/path/';
|
|
|
|
$this->Task->args = array('article');
|
|
|
|
$this->Task->params = array(
|
|
|
|
'schema' => true,
|
|
|
|
'records' => false,
|
|
|
|
);
|
|
|
|
$filename = '/my/path/ArticleFixture.php';
|
|
|
|
|
|
|
|
$this->Task->expects($this->never())
|
|
|
|
->method('in');
|
|
|
|
|
|
|
|
$this->Task->expects($this->at(0))
|
|
|
|
->method('createFile')
|
|
|
|
->with($filename, $this->logicalAnd(
|
|
|
|
$this->stringContains('class ArticleFixture'),
|
|
|
|
$this->stringContains("\$import = array('model' => 'Article'")
|
|
|
|
));
|
|
|
|
|
|
|
|
$this->Task->execute();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* test that execute includes import options
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function testExecuteWithImportRecords() {
|
|
|
|
$this->Task->connection = 'test';
|
|
|
|
$this->Task->path = '/my/path/';
|
|
|
|
$this->Task->args = array('article');
|
|
|
|
$this->Task->params = array(
|
|
|
|
'schema' => true,
|
|
|
|
'records' => true,
|
|
|
|
);
|
|
|
|
$filename = '/my/path/ArticleFixture.php';
|
|
|
|
|
|
|
|
$this->Task->expects($this->never())
|
|
|
|
->method('in');
|
|
|
|
|
|
|
|
$this->Task->expects($this->at(0))
|
|
|
|
->method('createFile')
|
|
|
|
->with($filename, $this->logicalAnd(
|
|
|
|
$this->stringContains('class ArticleFixture'),
|
|
|
|
$this->stringContains("\$import = array('model' => 'Article', 'connection' => 'test')")
|
|
|
|
));
|
|
|
|
|
|
|
|
$this->Task->execute();
|
|
|
|
}
|
|
|
|
|
2009-05-05 03:08:15 +00:00
|
|
|
/**
|
|
|
|
* test that execute passes runs bake depending with named model.
|
|
|
|
*
|
|
|
|
* @return void
|
2009-11-14 12:18:31 +00:00
|
|
|
*/
|
2010-04-05 03:19:38 +00:00
|
|
|
public function testExecuteWithNamedModel() {
|
2010-09-20 02:58:30 +00:00
|
|
|
$this->Task->connection = 'test';
|
2009-05-05 03:08:15 +00:00
|
|
|
$this->Task->path = '/my/path/';
|
|
|
|
$this->Task->args = array('article');
|
2011-04-11 01:26:06 +00:00
|
|
|
$filename = '/my/path/ArticleFixture.php';
|
2010-06-10 04:25:23 +00:00
|
|
|
|
|
|
|
$this->Task->expects($this->at(0))->method('createFile')
|
2011-09-29 04:09:07 +00:00
|
|
|
->with($filename, $this->stringContains('class ArticleFixture'));
|
2011-10-28 05:01:17 +00:00
|
|
|
|
2010-03-06 02:30:58 +00:00
|
|
|
$this->Task->execute();
|
|
|
|
}
|
|
|
|
|
2009-05-05 03:08:15 +00:00
|
|
|
/**
|
|
|
|
* test that execute runs all() when args[0] = all
|
|
|
|
*
|
|
|
|
* @return void
|
2009-11-14 12:18:31 +00:00
|
|
|
*/
|
2010-04-05 03:19:38 +00:00
|
|
|
public function testExecuteIntoAll() {
|
2010-09-20 02:58:30 +00:00
|
|
|
$this->Task->connection = 'test';
|
2009-05-05 03:08:15 +00:00
|
|
|
$this->Task->path = '/my/path/';
|
|
|
|
$this->Task->args = array('all');
|
2011-09-14 00:45:45 +00:00
|
|
|
$this->Task->Model->expects($this->any())
|
|
|
|
->method('listAll')
|
2011-09-29 04:09:07 +00:00
|
|
|
->will($this->returnValue(array('articles', 'comments')));
|
2009-05-05 03:08:15 +00:00
|
|
|
|
2011-04-11 01:26:06 +00:00
|
|
|
$filename = '/my/path/ArticleFixture.php';
|
2011-09-14 00:45:45 +00:00
|
|
|
$this->Task->expects($this->at(0))
|
|
|
|
->method('createFile')
|
|
|
|
->with($filename, $this->stringContains('class ArticleFixture'));
|
2009-05-05 03:08:15 +00:00
|
|
|
|
2011-04-11 01:26:06 +00:00
|
|
|
$filename = '/my/path/CommentFixture.php';
|
2011-09-14 00:45:45 +00:00
|
|
|
$this->Task->expects($this->at(1))
|
|
|
|
->method('createFile')
|
|
|
|
->with($filename, $this->stringContains('class CommentFixture'));
|
2010-06-10 04:25:23 +00:00
|
|
|
|
2009-05-05 03:08:15 +00:00
|
|
|
$this->Task->execute();
|
|
|
|
}
|
2009-07-26 09:59:51 +00:00
|
|
|
|
2009-10-24 18:08:08 +00:00
|
|
|
/**
|
|
|
|
* test using all() with -count and -records
|
|
|
|
*
|
|
|
|
* @return void
|
2009-11-14 12:18:31 +00:00
|
|
|
*/
|
2010-04-05 03:19:38 +00:00
|
|
|
public function testAllWithCountAndRecordsFlags() {
|
2010-09-20 02:58:30 +00:00
|
|
|
$this->Task->connection = 'test';
|
2009-10-24 18:08:08 +00:00
|
|
|
$this->Task->path = '/my/path/';
|
|
|
|
$this->Task->args = array('all');
|
|
|
|
$this->Task->params = array('count' => 10, 'records' => true);
|
2010-06-10 04:25:23 +00:00
|
|
|
|
|
|
|
$this->Task->Model->expects($this->any())->method('listAll')
|
2011-09-29 04:09:07 +00:00
|
|
|
->will($this->returnValue(array('Articles', 'comments')));
|
2009-10-24 18:08:08 +00:00
|
|
|
|
2011-04-11 01:26:06 +00:00
|
|
|
$filename = '/my/path/ArticleFixture.php';
|
2010-06-10 04:25:23 +00:00
|
|
|
$this->Task->expects($this->at(0))->method('createFile')
|
2011-09-29 04:09:07 +00:00
|
|
|
->with($filename, $this->stringContains("'title' => 'Third Article'"));
|
2009-10-24 18:08:08 +00:00
|
|
|
|
2011-04-11 01:26:06 +00:00
|
|
|
$filename = '/my/path/CommentFixture.php';
|
2010-06-10 04:25:23 +00:00
|
|
|
$this->Task->expects($this->at(1))->method('createFile')
|
2011-09-29 04:09:07 +00:00
|
|
|
->with($filename, $this->stringContains("'comment' => 'First Comment for First Article'"));
|
2010-06-10 04:25:23 +00:00
|
|
|
$this->Task->expects($this->exactly(2))->method('createFile');
|
2013-05-01 22:19:46 +00:00
|
|
|
|
|
|
|
$this->Task->all();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* test using all() with -schema
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function testAllWithSchemaImport() {
|
|
|
|
$this->Task->connection = 'test';
|
|
|
|
$this->Task->path = '/my/path/';
|
|
|
|
$this->Task->args = array('all');
|
|
|
|
$this->Task->params = array('schema' => 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')
|
|
|
|
->with($filename, $this->stringContains('public $import = array(\'model\' => \'Article\''));
|
|
|
|
|
|
|
|
$filename = '/my/path/CommentFixture.php';
|
|
|
|
$this->Task->expects($this->at(1))->method('createFile')
|
|
|
|
->with($filename, $this->stringContains('public $import = array(\'model\' => \'Comment\''));
|
|
|
|
$this->Task->expects($this->exactly(2))->method('createFile');
|
2010-06-10 04:25:23 +00:00
|
|
|
|
2009-10-24 18:08:08 +00:00
|
|
|
$this->Task->all();
|
|
|
|
}
|
|
|
|
|
2009-05-05 03:08:15 +00:00
|
|
|
/**
|
|
|
|
* test interactive mode of execute
|
|
|
|
*
|
|
|
|
* @return void
|
2009-11-14 12:18:31 +00:00
|
|
|
*/
|
2010-04-05 03:19:38 +00:00
|
|
|
public function testExecuteInteractive() {
|
2010-09-20 02:58:30 +00:00
|
|
|
$this->Task->connection = 'test';
|
2009-05-05 03:08:15 +00:00
|
|
|
$this->Task->path = '/my/path/';
|
2009-07-26 09:59:51 +00:00
|
|
|
|
2010-06-10 04:25:23 +00:00
|
|
|
$this->Task->expects($this->any())->method('in')->will($this->returnValue('y'));
|
|
|
|
$this->Task->Model->expects($this->any())->method('getName')->will($this->returnValue('Article'));
|
|
|
|
$this->Task->Model->expects($this->any())->method('getTable')
|
|
|
|
->with('Article')
|
|
|
|
->will($this->returnValue('articles'));
|
2009-05-05 03:08:15 +00:00
|
|
|
|
2011-04-11 01:26:06 +00:00
|
|
|
$filename = '/my/path/ArticleFixture.php';
|
2010-06-10 04:25:23 +00:00
|
|
|
$this->Task->expects($this->once())->method('createFile')
|
2011-09-29 04:09:07 +00:00
|
|
|
->with($filename, $this->stringContains('class ArticleFixture'));
|
2010-06-10 04:25:23 +00:00
|
|
|
|
2009-05-05 03:08:15 +00:00
|
|
|
$this->Task->execute();
|
|
|
|
}
|
2009-07-26 09:59:51 +00:00
|
|
|
|
2009-05-04 01:43:22 +00:00
|
|
|
/**
|
|
|
|
* Test that bake works
|
|
|
|
*
|
|
|
|
* @return void
|
2009-11-14 12:18:31 +00:00
|
|
|
*/
|
2010-04-05 03:19:38 +00:00
|
|
|
public function testBake() {
|
2010-09-20 02:58:30 +00:00
|
|
|
$this->Task->connection = 'test';
|
2009-05-04 01:43:22 +00:00
|
|
|
$this->Task->path = '/my/path/';
|
|
|
|
|
|
|
|
$result = $this->Task->bake('Article');
|
2022-12-30 08:53:58 +00:00
|
|
|
$this->assertStringContainsString('class ArticleFixture extends CakeTestFixture', $result);
|
|
|
|
$this->assertStringContainsString('public $fields', $result);
|
|
|
|
$this->assertStringContainsString('public $records', $result);
|
2022-12-30 09:44:36 +00:00
|
|
|
$this->assertStringNotContainsString('public $import', $result);
|
2009-05-04 01:43:22 +00:00
|
|
|
|
|
|
|
$result = $this->Task->bake('Article', 'comments');
|
2022-12-30 08:53:58 +00:00
|
|
|
$this->assertStringContainsString('class ArticleFixture extends CakeTestFixture', $result);
|
|
|
|
$this->assertStringContainsString('public $table = \'comments\';', $result);
|
|
|
|
$this->assertStringContainsString('public $fields = array(', $result);
|
2009-05-04 01:43:22 +00:00
|
|
|
|
|
|
|
$result = $this->Task->bake('Article', 'comments', array('records' => true));
|
2022-12-30 08:53:58 +00:00
|
|
|
$this->assertStringContainsString("public \$import = array('records' => true, 'connection' => 'test');", $result);
|
2022-12-30 09:44:36 +00:00
|
|
|
$this->assertStringNotContainsString('public $records', $result);
|
2009-05-04 01:43:22 +00:00
|
|
|
|
|
|
|
$result = $this->Task->bake('Article', 'comments', array('schema' => 'Article'));
|
2022-12-30 08:53:58 +00:00
|
|
|
$this->assertStringContainsString("public \$import = array('model' => 'Article', 'connection' => 'test');", $result);
|
2022-12-30 09:44:36 +00:00
|
|
|
$this->assertStringNotContainsString('public $fields', $result);
|
2009-04-30 02:40:49 +00:00
|
|
|
|
2009-05-04 01:43:22 +00:00
|
|
|
$result = $this->Task->bake('Article', 'comments', array('schema' => 'Article', 'records' => true));
|
2022-12-30 08:53:58 +00:00
|
|
|
$this->assertStringContainsString("public \$import = array('model' => 'Article', 'records' => true, 'connection' => 'test');", $result);
|
2022-12-30 09:44:36 +00:00
|
|
|
$this->assertStringNotContainsString('public $fields', $result);
|
|
|
|
$this->assertStringNotContainsString('public $records', $result);
|
2009-05-04 01:43:22 +00:00
|
|
|
}
|
2009-07-26 09:59:51 +00:00
|
|
|
|
2009-11-09 03:22:08 +00:00
|
|
|
/**
|
2017-03-12 02:46:14 +00:00
|
|
|
* test record generation with various integer, float and binary types
|
2009-11-09 03:22:08 +00:00
|
|
|
*
|
|
|
|
* @return void
|
2009-11-14 12:18:31 +00:00
|
|
|
*/
|
2017-03-12 02:46:14 +00:00
|
|
|
public function testRecordGenerationForBinaryFloatAndIntegerTypes() {
|
2010-09-20 02:58:30 +00:00
|
|
|
$this->Task->connection = 'test';
|
2009-11-09 03:22:08 +00:00
|
|
|
$this->Task->path = '/my/path/';
|
|
|
|
|
|
|
|
$result = $this->Task->bake('Article', 'datatypes');
|
2022-12-30 08:53:58 +00:00
|
|
|
$this->assertStringContainsString("'float_field' => 1", $result);
|
|
|
|
$this->assertStringContainsString("'bool' => 1", $result);
|
|
|
|
$this->assertStringContainsString("'tiny_int' => 1", $result);
|
|
|
|
$this->assertStringContainsString("'small_int' => 1", $result);
|
|
|
|
$this->assertStringContainsString("'huge_int' => 1", $result);
|
2009-11-09 03:22:08 +00:00
|
|
|
|
|
|
|
$result = $this->Task->bake('Article', 'binary_tests');
|
2022-12-30 08:53:58 +00:00
|
|
|
$this->assertStringContainsString("'data' => 'Lorem ipsum dolor sit amet'", $result);
|
2009-11-09 03:22:08 +00:00
|
|
|
}
|
|
|
|
|
2009-05-04 01:43:22 +00:00
|
|
|
/**
|
|
|
|
* Test that file generation includes headers and correct path for plugins.
|
|
|
|
*
|
|
|
|
* @return void
|
2009-11-14 12:18:31 +00:00
|
|
|
*/
|
2010-04-05 03:19:38 +00:00
|
|
|
public function testGenerateFixtureFile() {
|
2010-09-20 02:58:30 +00:00
|
|
|
$this->Task->connection = 'test';
|
2009-05-04 01:43:22 +00:00
|
|
|
$this->Task->path = '/my/path/';
|
2011-04-11 01:26:06 +00:00
|
|
|
$filename = '/my/path/ArticleFixture.php';
|
2009-05-04 01:43:22 +00:00
|
|
|
|
2010-06-10 04:25:23 +00:00
|
|
|
$this->Task->expects($this->at(0))->method('createFile')
|
2011-09-29 04:09:07 +00:00
|
|
|
->with($filename, $this->stringContains('ArticleFixture'));
|
2010-06-10 04:25:23 +00:00
|
|
|
|
|
|
|
$this->Task->expects($this->at(1))->method('createFile')
|
2011-09-29 04:09:07 +00:00
|
|
|
->with($filename, $this->stringContains('<?php'));
|
2010-06-10 04:25:23 +00:00
|
|
|
|
2014-02-11 21:38:24 +00:00
|
|
|
$this->Task->generateFixtureFile('Article', array());
|
|
|
|
$this->Task->generateFixtureFile('Article', array());
|
2009-05-04 01:43:22 +00:00
|
|
|
}
|
2009-07-26 09:59:51 +00:00
|
|
|
|
2009-06-07 00:03:04 +00:00
|
|
|
/**
|
|
|
|
* test generating files into plugins.
|
|
|
|
*
|
|
|
|
* @return void
|
2009-11-14 12:18:31 +00:00
|
|
|
*/
|
2010-04-05 03:19:38 +00:00
|
|
|
public function testGeneratePluginFixtureFile() {
|
2010-09-20 02:58:30 +00:00
|
|
|
$this->Task->connection = 'test';
|
2009-06-07 00:03:04 +00:00
|
|
|
$this->Task->path = '/my/path/';
|
|
|
|
$this->Task->plugin = 'TestFixture';
|
2011-05-30 19:04:38 +00:00
|
|
|
$filename = APP . 'Plugin' . DS . 'TestFixture' . DS . 'Test' . DS . 'Fixture' . DS . 'ArticleFixture.php';
|
2009-06-07 00:03:04 +00:00
|
|
|
|
2011-05-12 04:58:39 +00:00
|
|
|
//fake plugin path
|
2012-03-11 04:32:02 +00:00
|
|
|
CakePlugin::load('TestFixture', array('path' => APP . 'Plugin' . DS . 'TestFixture' . DS));
|
2010-06-10 04:25:23 +00:00
|
|
|
$this->Task->expects($this->at(0))->method('createFile')
|
2011-09-29 04:09:07 +00:00
|
|
|
->with($filename, $this->stringContains('class Article'));
|
2010-06-10 04:25:23 +00:00
|
|
|
|
2013-01-23 12:45:50 +00:00
|
|
|
$this->Task->generateFixtureFile('Article', array());
|
2011-05-12 04:58:39 +00:00
|
|
|
CakePlugin::unload();
|
2009-06-07 00:03:04 +00:00
|
|
|
}
|
2011-01-09 04:49:19 +00:00
|
|
|
|
2009-04-30 02:40:49 +00:00
|
|
|
}
|