2009-04-30 02:17:08 +00:00
|
|
|
<?php
|
|
|
|
/**
|
2009-10-24 15:26:06 +00:00
|
|
|
* ModelTaskTest file
|
2009-04-30 02:17:08 +00:00
|
|
|
*
|
|
|
|
* Test Case for test generation shell task
|
|
|
|
*
|
2017-06-10 21:33:55 +00:00
|
|
|
* CakePHP : Rapid Development Framework (https://cakephp.org)
|
2013-02-08 12:28:17 +00:00
|
|
|
* Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
|
2009-04-30 02:17:08 +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:17:08 +00:00
|
|
|
* Redistributions of files must retain the above copyright notice.
|
|
|
|
*
|
2013-02-08 12:28:17 +00:00
|
|
|
* @copyright Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
|
2017-06-10 21:33:55 +00:00
|
|
|
* @link https://cakephp.org CakePHP Project
|
2011-07-26 06:16:14 +00:00
|
|
|
* @package Cake.Test.Case.Console.Command.Task
|
2009-10-24 15:26:06 +00:00
|
|
|
* @since CakePHP v 1.2.6
|
2013-05-30 22:11:14 +00:00
|
|
|
* @license http://www.opensource.org/licenses/mit-license.php MIT License
|
2009-04-30 02:17:08 +00:00
|
|
|
*/
|
|
|
|
|
2010-12-09 03:45:18 +00:00
|
|
|
App::uses('ShellDispatcher', 'Console');
|
|
|
|
App::uses('Shell', 'Console');
|
2011-03-08 05:20:07 +00:00
|
|
|
App::uses('ConsoleOutput', 'Console');
|
|
|
|
App::uses('ConsoleInput', 'Console');
|
2010-12-09 03:45:18 +00:00
|
|
|
App::uses('FixtureTask', 'Console/Command/Task');
|
|
|
|
App::uses('TemplateTask', 'Console/Command/Task');
|
|
|
|
App::uses('ModelTask', 'Console/Command/Task');
|
2009-04-30 02:17:08 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* ModelTaskTest class
|
|
|
|
*
|
2011-11-20 00:11:33 +00:00
|
|
|
* @package Cake.Test.Case.Console.Command.Task
|
2013-11-13 12:36:19 +00:00
|
|
|
* @property ModelTask $Task
|
2009-04-30 02:17:08 +00:00
|
|
|
*/
|
|
|
|
class ModelTaskTest extends CakeTestCase {
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2009-04-30 02:40:49 +00:00
|
|
|
/**
|
|
|
|
* fixtures
|
|
|
|
*
|
|
|
|
* @var array
|
2009-11-14 12:18:31 +00:00
|
|
|
*/
|
2010-11-21 18:39:18 +00:00
|
|
|
public $fixtures = array(
|
|
|
|
'core.bake_article', 'core.bake_comment', 'core.bake_articles_bake_tag',
|
2013-03-15 11:14:06 +00:00
|
|
|
'core.bake_tag', 'core.category_thread', 'core.number_tree'
|
2010-11-21 18:39:18 +00:00
|
|
|
);
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2009-04-30 02:17:08 +00:00
|
|
|
/**
|
2010-09-26 01:36:49 +00:00
|
|
|
* setUp method
|
2009-04-30 02:17:08 +00:00
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
2010-09-26 01:36:49 +00:00
|
|
|
public function setUp() {
|
|
|
|
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-06-12 21:42:53 +00:00
|
|
|
$this->Task = $this->getMock('ModelTask',
|
|
|
|
array('in', 'err', 'createFile', '_stop', '_checkUnitTest'),
|
2010-10-24 19:27:04 +00:00
|
|
|
array($out, $out, $in)
|
2010-06-12 21:42:53 +00:00
|
|
|
);
|
|
|
|
$this->_setupOtherMocks();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2012-12-22 22:48:15 +00:00
|
|
|
* Setup a mock that has out mocked. Normally this is not used as it makes $this->at() really tricky.
|
2010-06-12 21:42:53 +00:00
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
protected function _useMockedOut() {
|
2010-10-07 02:52:42 +00:00
|
|
|
$out = $this->getMock('ConsoleOutput', array(), array(), '', false);
|
|
|
|
$in = $this->getMock('ConsoleInput', array(), array(), '', false);
|
|
|
|
|
2010-06-12 21:42:53 +00:00
|
|
|
$this->Task = $this->getMock('ModelTask',
|
|
|
|
array('in', 'out', 'err', 'hr', 'createFile', '_stop', '_checkUnitTest'),
|
2010-10-24 19:27:04 +00:00
|
|
|
array($out, $out, $in)
|
2010-06-12 21:42:53 +00:00
|
|
|
);
|
|
|
|
$this->_setupOtherMocks();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* sets up the rest of the dependencies for Model Task
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
protected function _setupOtherMocks() {
|
2010-10-07 02:52:42 +00:00
|
|
|
$out = $this->getMock('ConsoleOutput', array(), array(), '', false);
|
|
|
|
$in = $this->getMock('ConsoleInput', array(), array(), '', false);
|
|
|
|
|
2010-10-24 19:27:04 +00:00
|
|
|
$this->Task->Fixture = $this->getMock('FixtureTask', array(), array($out, $out, $in));
|
|
|
|
$this->Task->Test = $this->getMock('FixtureTask', array(), array($out, $out, $in));
|
|
|
|
$this->Task->Template = new TemplateTask($out, $out, $in);
|
2010-06-12 21:42:53 +00:00
|
|
|
|
2010-10-19 03:09:23 +00:00
|
|
|
$this->Task->name = 'Model';
|
2010-03-05 02:57:48 +00:00
|
|
|
$this->Task->interactive = true;
|
2009-04-30 02:17:08 +00:00
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2009-04-30 02:17:08 +00:00
|
|
|
/**
|
2011-12-04 21:27:51 +00:00
|
|
|
* tearDown method
|
2009-04-30 02:17:08 +00:00
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
2010-09-26 01:36:49 +00:00
|
|
|
public function tearDown() {
|
|
|
|
parent::tearDown();
|
2010-10-24 19:27:04 +00:00
|
|
|
unset($this->Task);
|
2009-04-30 02:17:08 +00:00
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2009-04-30 02:17:08 +00:00
|
|
|
/**
|
|
|
|
* Test that listAll scans the database connection and lists all the tables in it.s
|
|
|
|
*
|
|
|
|
* @return void
|
2009-11-14 12:18:31 +00:00
|
|
|
*/
|
2011-11-24 02:30:28 +00:00
|
|
|
public function testListAllArgument() {
|
2010-06-12 21:42:53 +00:00
|
|
|
$this->_useMockedOut();
|
|
|
|
|
2010-09-20 02:58:30 +00:00
|
|
|
$result = $this->Task->listAll('test');
|
2011-11-24 02:30:28 +00:00
|
|
|
$this->assertContains('bake_articles', $result);
|
|
|
|
$this->assertContains('bake_articles_bake_tags', $result);
|
|
|
|
$this->assertContains('bake_tags', $result);
|
|
|
|
$this->assertContains('bake_comments', $result);
|
|
|
|
$this->assertContains('category_threads', $result);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Test that listAll uses the connection property
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function testListAllConnection() {
|
|
|
|
$this->_useMockedOut();
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2010-09-20 02:58:30 +00:00
|
|
|
$this->Task->connection = 'test';
|
2009-05-05 04:10:24 +00:00
|
|
|
$result = $this->Task->listAll();
|
2011-11-24 02:30:28 +00:00
|
|
|
$this->assertContains('bake_articles', $result);
|
|
|
|
$this->assertContains('bake_articles_bake_tags', $result);
|
|
|
|
$this->assertContains('bake_tags', $result);
|
|
|
|
$this->assertContains('bake_comments', $result);
|
|
|
|
$this->assertContains('category_threads', $result);
|
2009-04-30 02:17:08 +00:00
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2009-04-30 02:17:08 +00:00
|
|
|
/**
|
2009-05-15 03:25:52 +00:00
|
|
|
* Test that getName interacts with the user and returns the model name.
|
2009-04-30 02:17:08 +00:00
|
|
|
*
|
|
|
|
* @return void
|
2009-11-14 12:18:31 +00:00
|
|
|
*/
|
2010-06-12 21:42:53 +00:00
|
|
|
public function testGetNameQuit() {
|
|
|
|
$this->Task->expects($this->once())->method('in')->will($this->returnValue('q'));
|
|
|
|
$this->Task->expects($this->once())->method('_stop');
|
2010-09-20 02:58:30 +00:00
|
|
|
$this->Task->getName('test');
|
2010-06-12 21:42:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* test getName with a valid option.
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
2011-05-30 20:02:32 +00:00
|
|
|
public function testGetNameValidOption() {
|
2010-11-21 18:39:18 +00:00
|
|
|
$listing = $this->Task->listAll('test');
|
2010-07-10 04:22:14 +00:00
|
|
|
$this->Task->expects($this->any())->method('in')->will($this->onConsecutiveCalls(1, 4));
|
2009-04-30 02:17:08 +00:00
|
|
|
|
2010-09-20 02:58:30 +00:00
|
|
|
$result = $this->Task->getName('test');
|
2010-11-21 18:39:18 +00:00
|
|
|
$this->assertEquals(Inflector::classify($listing[0]), $result);
|
2009-04-30 02:25:42 +00:00
|
|
|
|
2010-09-20 02:58:30 +00:00
|
|
|
$result = $this->Task->getName('test');
|
2010-11-21 18:39:18 +00:00
|
|
|
$this->assertEquals(Inflector::classify($listing[3]), $result);
|
2010-06-12 21:42:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* test that an out of bounds option causes an error.
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
2011-05-30 20:02:32 +00:00
|
|
|
public function testGetNameWithOutOfBoundsOption() {
|
2010-09-10 02:54:22 +00:00
|
|
|
$this->Task->expects($this->any())->method('in')->will($this->onConsecutiveCalls(99, 1));
|
2010-06-12 21:42:53 +00:00
|
|
|
$this->Task->expects($this->once())->method('err');
|
2009-04-30 02:25:42 +00:00
|
|
|
|
2013-01-23 12:45:50 +00:00
|
|
|
$this->Task->getName('test');
|
2009-04-30 02:17:08 +00:00
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2009-04-30 02:25:42 +00:00
|
|
|
/**
|
|
|
|
* Test table name interactions
|
|
|
|
*
|
|
|
|
* @return void
|
2009-11-14 12:18:31 +00:00
|
|
|
*/
|
2010-04-05 03:19:38 +00:00
|
|
|
public function testGetTableName() {
|
2010-06-12 21:42:53 +00:00
|
|
|
$this->Task->expects($this->at(0))->method('in')->will($this->returnValue('y'));
|
2010-11-21 18:39:18 +00:00
|
|
|
$result = $this->Task->getTable('BakeArticle', 'test');
|
|
|
|
$expected = 'bake_articles';
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertEquals($expected, $result);
|
2010-06-12 21:42:53 +00:00
|
|
|
}
|
2009-04-30 02:25:42 +00:00
|
|
|
|
2010-06-12 21:42:53 +00:00
|
|
|
/**
|
2013-03-05 07:05:14 +00:00
|
|
|
* test getting a custom table name.
|
2010-06-12 21:42:53 +00:00
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
2011-05-30 20:02:32 +00:00
|
|
|
public function testGetTableNameCustom() {
|
2010-07-10 04:22:14 +00:00
|
|
|
$this->Task->expects($this->any())->method('in')->will($this->onConsecutiveCalls('n', 'my_table'));
|
2010-11-21 18:39:18 +00:00
|
|
|
$result = $this->Task->getTable('BakeArticle', 'test');
|
2009-04-30 02:25:42 +00:00
|
|
|
$expected = 'my_table';
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertEquals($expected, $result);
|
2009-04-30 02:25:42 +00:00
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2011-11-25 15:25:11 +00:00
|
|
|
/**
|
|
|
|
* test getTable with non-conventional tablenames
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
2011-12-05 11:21:18 +00:00
|
|
|
public function testGetTableOddTableInteractive() {
|
2011-11-25 15:25:11 +00:00
|
|
|
$out = $this->getMock('ConsoleOutput', array(), array(), '', false);
|
|
|
|
$in = $this->getMock('ConsoleInput', array(), array(), '', false);
|
|
|
|
$this->Task = $this->getMock('ModelTask',
|
|
|
|
array('in', 'err', '_stop', '_checkUnitTest', 'getAllTables'),
|
|
|
|
array($out, $out, $in)
|
|
|
|
);
|
|
|
|
$this->_setupOtherMocks();
|
|
|
|
|
|
|
|
$this->Task->connection = 'test';
|
|
|
|
$this->Task->path = '/my/path/';
|
|
|
|
$this->Task->interactive = true;
|
|
|
|
|
|
|
|
$this->Task->expects($this->once())->method('getAllTables')->will($this->returnValue(array('articles', 'bake_odd')));
|
|
|
|
$this->Task->expects($this->any())->method('in')
|
|
|
|
->will($this->onConsecutiveCalls(
|
|
|
|
2 // bake_odd
|
|
|
|
));
|
|
|
|
|
|
|
|
$result = $this->Task->getName();
|
|
|
|
$expected = 'BakeOdd';
|
|
|
|
$this->assertEquals($expected, $result);
|
|
|
|
|
|
|
|
$result = $this->Task->getTable($result);
|
|
|
|
$expected = 'bake_odd';
|
|
|
|
$this->assertEquals($expected, $result);
|
|
|
|
}
|
|
|
|
|
2011-12-05 11:21:18 +00:00
|
|
|
/**
|
|
|
|
* test getTable with non-conventional tablenames
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function testGetTableOddTable() {
|
|
|
|
$out = $this->getMock('ConsoleOutput', array(), array(), '', false);
|
|
|
|
$in = $this->getMock('ConsoleInput', array(), array(), '', false);
|
|
|
|
$this->Task = $this->getMock('ModelTask',
|
|
|
|
array('in', 'err', '_stop', '_checkUnitTest', 'getAllTables'),
|
|
|
|
array($out, $out, $in)
|
|
|
|
);
|
|
|
|
$this->_setupOtherMocks();
|
|
|
|
|
|
|
|
$this->Task->connection = 'test';
|
|
|
|
$this->Task->path = '/my/path/';
|
|
|
|
$this->Task->interactive = false;
|
|
|
|
$this->Task->args = array('BakeOdd');
|
|
|
|
|
|
|
|
$this->Task->expects($this->once())->method('getAllTables')->will($this->returnValue(array('articles', 'bake_odd')));
|
|
|
|
|
|
|
|
$this->Task->listAll();
|
|
|
|
|
|
|
|
$result = $this->Task->getTable('BakeOdd');
|
|
|
|
$expected = 'bake_odd';
|
|
|
|
$this->assertEquals($expected, $result);
|
|
|
|
}
|
|
|
|
|
2009-05-08 04:49:26 +00:00
|
|
|
/**
|
|
|
|
* test that initializing the validations works.
|
|
|
|
*
|
|
|
|
* @return void
|
2009-11-14 12:18:31 +00:00
|
|
|
*/
|
2010-04-05 03:19:38 +00:00
|
|
|
public function testInitValidations() {
|
2009-05-08 04:49:26 +00:00
|
|
|
$result = $this->Task->initValidations();
|
2015-05-17 20:27:16 +00:00
|
|
|
$this->assertTrue(in_array('notBlank', $result));
|
2009-05-08 04:49:26 +00:00
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2009-05-08 04:49:26 +00:00
|
|
|
/**
|
|
|
|
* test that individual field validation works, with interactive = false
|
2009-05-08 05:09:19 +00:00
|
|
|
* tests the guessing features of validation
|
2009-05-08 04:49:26 +00:00
|
|
|
*
|
|
|
|
* @return void
|
2009-11-14 12:18:31 +00:00
|
|
|
*/
|
2010-04-05 03:19:38 +00:00
|
|
|
public function testFieldValidationGuessing() {
|
2009-05-08 04:49:26 +00:00
|
|
|
$this->Task->interactive = false;
|
2009-05-08 05:09:19 +00:00
|
|
|
$this->Task->initValidations();
|
2009-05-08 04:49:26 +00:00
|
|
|
|
|
|
|
$result = $this->Task->fieldValidation('text', array('type' => 'string', 'length' => 10, 'null' => false));
|
2015-05-17 20:27:16 +00:00
|
|
|
$expected = array('notBlank' => 'notBlank');
|
2012-02-16 18:28:21 +00:00
|
|
|
$this->assertEquals($expected, $result);
|
2009-05-08 05:09:19 +00:00
|
|
|
|
|
|
|
$result = $this->Task->fieldValidation('text', array('type' => 'date', 'length' => 10, 'null' => false));
|
|
|
|
$expected = array('date' => 'date');
|
2012-02-16 18:28:21 +00:00
|
|
|
$this->assertEquals($expected, $result);
|
2009-05-08 05:09:19 +00:00
|
|
|
|
|
|
|
$result = $this->Task->fieldValidation('text', array('type' => 'time', 'length' => 10, 'null' => false));
|
|
|
|
$expected = array('time' => 'time');
|
2012-02-16 18:28:21 +00:00
|
|
|
$this->assertEquals($expected, $result);
|
2009-05-08 05:09:19 +00:00
|
|
|
|
|
|
|
$result = $this->Task->fieldValidation('email', array('type' => 'string', 'length' => 10, 'null' => false));
|
|
|
|
$expected = array('email' => 'email');
|
2012-02-16 18:28:21 +00:00
|
|
|
$this->assertEquals($expected, $result);
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2009-05-08 05:09:19 +00:00
|
|
|
$result = $this->Task->fieldValidation('test', array('type' => 'integer', 'length' => 10, 'null' => false));
|
|
|
|
$expected = array('numeric' => 'numeric');
|
2012-02-16 18:28:21 +00:00
|
|
|
$this->assertEquals($expected, $result);
|
2009-05-08 05:09:19 +00:00
|
|
|
|
|
|
|
$result = $this->Task->fieldValidation('test', array('type' => 'boolean', 'length' => 10, 'null' => false));
|
2012-02-16 18:28:21 +00:00
|
|
|
$expected = array('boolean' => 'boolean');
|
|
|
|
$this->assertEquals($expected, $result);
|
2009-05-08 05:09:19 +00:00
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2009-05-08 05:09:19 +00:00
|
|
|
/**
|
|
|
|
* test that interactive field validation works and returns multiple validators.
|
|
|
|
*
|
|
|
|
* @return void
|
2009-11-14 12:18:31 +00:00
|
|
|
*/
|
2010-04-05 03:19:38 +00:00
|
|
|
public function testInteractiveFieldValidation() {
|
2009-05-09 04:35:03 +00:00
|
|
|
$this->Task->initValidations();
|
|
|
|
$this->Task->interactive = true;
|
2010-06-12 21:42:53 +00:00
|
|
|
$this->Task->expects($this->any())->method('in')
|
2017-01-29 18:21:58 +00:00
|
|
|
->will($this->onConsecutiveCalls('26', 'y', '18', 'n'));
|
2009-05-09 04:35:03 +00:00
|
|
|
|
|
|
|
$result = $this->Task->fieldValidation('text', array('type' => 'string', 'length' => 10, 'null' => false));
|
2015-05-17 20:27:16 +00:00
|
|
|
$expected = array('notBlank' => 'notBlank', 'maxLength' => 'maxLength');
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertEquals($expected, $result);
|
2009-05-08 04:49:26 +00:00
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2010-03-13 03:58:14 +00:00
|
|
|
/**
|
|
|
|
* test that a bogus response doesn't cause errors to bubble up.
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
2011-05-30 20:02:32 +00:00
|
|
|
public function testInteractiveFieldValidationWithBogusResponse() {
|
2010-06-12 21:42:53 +00:00
|
|
|
$this->_useMockedOut();
|
2010-03-13 03:58:14 +00:00
|
|
|
$this->Task->initValidations();
|
|
|
|
$this->Task->interactive = true;
|
2010-06-12 21:42:53 +00:00
|
|
|
|
|
|
|
$this->Task->expects($this->any())->method('in')
|
2017-01-29 18:21:58 +00:00
|
|
|
->will($this->onConsecutiveCalls('999999', '26', 'n'));
|
2010-06-12 21:42:53 +00:00
|
|
|
|
2012-06-11 01:53:19 +00:00
|
|
|
$this->Task->expects($this->at(10))->method('out')
|
2011-09-29 04:35:15 +00:00
|
|
|
->with($this->stringContains('make a valid'));
|
2010-03-13 03:58:14 +00:00
|
|
|
|
|
|
|
$result = $this->Task->fieldValidation('text', array('type' => 'string', 'length' => 10, 'null' => false));
|
2015-05-17 20:27:16 +00:00
|
|
|
$expected = array('notBlank' => 'notBlank');
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertEquals($expected, $result);
|
2010-03-13 03:58:14 +00:00
|
|
|
}
|
|
|
|
|
2010-03-14 00:44:20 +00:00
|
|
|
/**
|
|
|
|
* test that a regular expression can be used for validation.
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
2011-05-30 20:02:32 +00:00
|
|
|
public function testInteractiveFieldValidationWithRegexp() {
|
2010-03-14 00:44:20 +00:00
|
|
|
$this->Task->initValidations();
|
|
|
|
$this->Task->interactive = true;
|
2010-07-10 04:22:14 +00:00
|
|
|
$this->Task->expects($this->any())->method('in')
|
|
|
|
->will($this->onConsecutiveCalls('/^[a-z]{0,9}$/', 'n'));
|
2010-03-14 00:44:20 +00:00
|
|
|
|
|
|
|
$result = $this->Task->fieldValidation('text', array('type' => 'string', 'length' => 10, 'null' => false));
|
|
|
|
$expected = array('a_z_0_9' => '/^[a-z]{0,9}$/');
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertEquals($expected, $result);
|
2010-03-14 00:44:20 +00:00
|
|
|
}
|
|
|
|
|
2009-05-08 04:49:26 +00:00
|
|
|
/**
|
2013-11-13 12:36:19 +00:00
|
|
|
* Test that skipping fields during rule choice works when doing interactive field validation.
|
2009-05-08 04:49:26 +00:00
|
|
|
*
|
|
|
|
* @return void
|
2009-11-14 12:18:31 +00:00
|
|
|
*/
|
2013-11-13 12:36:19 +00:00
|
|
|
public function testSkippingChoiceInteractiveFieldValidation() {
|
|
|
|
$this->Task->initValidations();
|
|
|
|
$this->Task->interactive = true;
|
|
|
|
$this->Task->expects($this->any())->method('in')
|
2017-01-29 18:21:58 +00:00
|
|
|
->will($this->onConsecutiveCalls('26', 'y', 's'));
|
2013-11-13 12:36:19 +00:00
|
|
|
|
|
|
|
$result = $this->Task->fieldValidation('text', array('type' => 'string', 'length' => 10, 'null' => false));
|
2015-05-17 20:27:16 +00:00
|
|
|
$expected = array('notBlank' => 'notBlank', '_skipFields' => true);
|
2013-11-13 12:36:19 +00:00
|
|
|
$this->assertEquals($expected, $result);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Test that skipping fields after rule choice works when doing interactive field validation.
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function testSkippingAnotherInteractiveFieldValidation() {
|
|
|
|
$this->Task->initValidations();
|
|
|
|
$this->Task->interactive = true;
|
|
|
|
$this->Task->expects($this->any())->method('in')
|
2017-01-29 18:21:58 +00:00
|
|
|
->will($this->onConsecutiveCalls('26', 's'));
|
2013-11-13 12:36:19 +00:00
|
|
|
|
|
|
|
$result = $this->Task->fieldValidation('text', array('type' => 'string', 'length' => 10, 'null' => false));
|
2015-05-17 20:27:16 +00:00
|
|
|
$expected = array('notBlank' => 'notBlank', '_skipFields' => true);
|
2013-11-13 12:36:19 +00:00
|
|
|
$this->assertEquals($expected, $result);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Test the validation generation routine with skipping the rest of the fields
|
|
|
|
* when doing interactive field validation.
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function testInteractiveDoValidationWithSkipping() {
|
|
|
|
$this->Task->expects($this->any())
|
|
|
|
->method('in')
|
2017-01-29 18:21:58 +00:00
|
|
|
->will($this->onConsecutiveCalls('37', '26', 'n', '10', 's'));
|
2013-11-13 12:36:19 +00:00
|
|
|
$this->Task->interactive = true;
|
2010-06-12 21:42:53 +00:00
|
|
|
$Model = $this->getMock('Model');
|
2009-05-08 05:09:19 +00:00
|
|
|
$Model->primaryKey = 'id';
|
2013-11-13 12:36:19 +00:00
|
|
|
$Model->expects($this->any())
|
|
|
|
->method('schema')
|
|
|
|
->will($this->returnValue(array(
|
|
|
|
'id' => array(
|
|
|
|
'type' => 'integer',
|
|
|
|
'length' => 11,
|
|
|
|
'null' => false,
|
|
|
|
'key' => 'primary',
|
|
|
|
),
|
|
|
|
'name' => array(
|
|
|
|
'type' => 'string',
|
|
|
|
'length' => 20,
|
|
|
|
'null' => false,
|
|
|
|
),
|
|
|
|
'email' => array(
|
|
|
|
'type' => 'string',
|
|
|
|
'length' => 255,
|
|
|
|
'null' => false,
|
|
|
|
),
|
|
|
|
'some_date' => array(
|
|
|
|
'type' => 'date',
|
|
|
|
'length' => '',
|
|
|
|
'null' => false,
|
|
|
|
),
|
|
|
|
'some_time' => array(
|
|
|
|
'type' => 'time',
|
|
|
|
'length' => '',
|
|
|
|
'null' => false,
|
|
|
|
),
|
|
|
|
'created' => array(
|
|
|
|
'type' => 'datetime',
|
|
|
|
'length' => '',
|
|
|
|
'null' => false,
|
|
|
|
)
|
|
|
|
)
|
|
|
|
));
|
|
|
|
|
|
|
|
$result = $this->Task->doValidation($Model);
|
|
|
|
$expected = array(
|
2009-05-08 04:49:26 +00:00
|
|
|
'name' => array(
|
2015-05-17 20:27:16 +00:00
|
|
|
'notBlank' => 'notBlank'
|
2009-05-08 04:49:26 +00:00
|
|
|
),
|
|
|
|
'email' => array(
|
2013-11-13 12:36:19 +00:00
|
|
|
'email' => 'email',
|
2009-05-08 04:49:26 +00:00
|
|
|
),
|
2013-11-13 12:36:19 +00:00
|
|
|
);
|
|
|
|
$this->assertEquals($expected, $result);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* test the validation Generation routine
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function testNonInteractiveDoValidation() {
|
|
|
|
$Model = $this->getMock('Model');
|
|
|
|
$Model->primaryKey = 'id';
|
|
|
|
$Model->expects($this->any())
|
|
|
|
->method('schema')
|
|
|
|
->will($this->returnValue(array(
|
|
|
|
'id' => array(
|
|
|
|
'type' => 'integer',
|
|
|
|
'length' => 11,
|
|
|
|
'null' => false,
|
|
|
|
'key' => 'primary',
|
|
|
|
),
|
|
|
|
'name' => array(
|
|
|
|
'type' => 'string',
|
|
|
|
'length' => 20,
|
|
|
|
'null' => false,
|
|
|
|
),
|
|
|
|
'email' => array(
|
|
|
|
'type' => 'string',
|
|
|
|
'length' => 255,
|
|
|
|
'null' => false,
|
|
|
|
),
|
|
|
|
'some_date' => array(
|
|
|
|
'type' => 'date',
|
|
|
|
'length' => '',
|
|
|
|
'null' => false,
|
|
|
|
),
|
|
|
|
'some_time' => array(
|
|
|
|
'type' => 'time',
|
|
|
|
'length' => '',
|
|
|
|
'null' => false,
|
|
|
|
),
|
|
|
|
'created' => array(
|
|
|
|
'type' => 'datetime',
|
|
|
|
'length' => '',
|
|
|
|
'null' => false,
|
|
|
|
)
|
2009-05-08 04:49:26 +00:00
|
|
|
)
|
2013-11-13 12:36:19 +00:00
|
|
|
));
|
2009-05-08 04:49:26 +00:00
|
|
|
$this->Task->interactive = false;
|
|
|
|
|
|
|
|
$result = $this->Task->doValidation($Model);
|
|
|
|
$expected = array(
|
|
|
|
'name' => array(
|
2015-05-17 20:27:16 +00:00
|
|
|
'notBlank' => 'notBlank'
|
2009-05-08 04:49:26 +00:00
|
|
|
),
|
|
|
|
'email' => array(
|
2009-05-08 05:09:19 +00:00
|
|
|
'email' => 'email',
|
2009-05-08 04:49:26 +00:00
|
|
|
),
|
|
|
|
'some_date' => array(
|
2009-05-08 05:09:19 +00:00
|
|
|
'date' => 'date'
|
2009-05-08 04:49:26 +00:00
|
|
|
),
|
|
|
|
'some_time' => array(
|
2009-05-08 05:09:19 +00:00
|
|
|
'time' => 'time'
|
2009-05-08 04:49:26 +00:00
|
|
|
),
|
|
|
|
);
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertEquals($expected, $result);
|
2009-05-08 04:49:26 +00:00
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2009-05-10 01:28:51 +00:00
|
|
|
/**
|
|
|
|
* test that finding primary key works
|
|
|
|
*
|
|
|
|
* @return void
|
2009-11-14 12:18:31 +00:00
|
|
|
*/
|
2010-04-05 03:19:38 +00:00
|
|
|
public function testFindPrimaryKey() {
|
2009-05-10 01:28:51 +00:00
|
|
|
$fields = array(
|
|
|
|
'one' => array(),
|
|
|
|
'two' => array(),
|
|
|
|
'key' => array('key' => 'primary')
|
|
|
|
);
|
2010-06-12 21:42:53 +00:00
|
|
|
$anything = new PHPUnit_Framework_Constraint_IsAnything();
|
|
|
|
$this->Task->expects($this->once())->method('in')
|
|
|
|
->with($anything, null, 'key')
|
|
|
|
->will($this->returnValue('my_field'));
|
2011-05-16 22:49:00 +00:00
|
|
|
|
2009-05-10 01:28:51 +00:00
|
|
|
$result = $this->Task->findPrimaryKey($fields);
|
|
|
|
$expected = 'my_field';
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertEquals($expected, $result);
|
2009-05-10 01:28:51 +00:00
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2009-07-08 13:10:18 +00:00
|
|
|
/**
|
|
|
|
* test finding Display field
|
|
|
|
*
|
|
|
|
* @return void
|
2009-11-14 12:18:31 +00:00
|
|
|
*/
|
2010-06-12 21:42:53 +00:00
|
|
|
public function testFindDisplayFieldNone() {
|
|
|
|
$fields = array(
|
|
|
|
'id' => array(), 'tagname' => array(), 'body' => array(),
|
|
|
|
'created' => array(), 'modified' => array()
|
|
|
|
);
|
|
|
|
$this->Task->expects($this->at(0))->method('in')->will($this->returnValue('n'));
|
2009-07-08 13:10:18 +00:00
|
|
|
$result = $this->Task->findDisplayField($fields);
|
|
|
|
$this->assertFalse($result);
|
2010-06-12 21:42:53 +00:00
|
|
|
}
|
2009-07-08 13:10:18 +00:00
|
|
|
|
2010-06-12 21:42:53 +00:00
|
|
|
/**
|
|
|
|
* Test finding a displayname from user input
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function testFindDisplayName() {
|
|
|
|
$fields = array(
|
|
|
|
'id' => array(), 'tagname' => array(), 'body' => array(),
|
|
|
|
'created' => array(), 'modified' => array()
|
|
|
|
);
|
2010-07-10 04:22:14 +00:00
|
|
|
$this->Task->expects($this->any())->method('in')
|
|
|
|
->will($this->onConsecutiveCalls('y', 2));
|
|
|
|
|
2009-07-08 13:10:18 +00:00
|
|
|
$result = $this->Task->findDisplayField($fields);
|
2012-03-23 06:37:12 +00:00
|
|
|
$this->assertEquals('tagname', $result);
|
2009-07-08 13:10:18 +00:00
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2009-05-10 01:28:51 +00:00
|
|
|
/**
|
|
|
|
* test that belongsTo generation works.
|
|
|
|
*
|
|
|
|
* @return void
|
2009-11-14 12:18:31 +00:00
|
|
|
*/
|
2010-04-05 03:19:38 +00:00
|
|
|
public function testBelongsToGeneration() {
|
2010-11-21 18:39:18 +00:00
|
|
|
$model = new Model(array('ds' => 'test', 'name' => 'BakeComment'));
|
2009-05-10 01:28:51 +00:00
|
|
|
$result = $this->Task->findBelongsTo($model, array());
|
|
|
|
$expected = array(
|
|
|
|
'belongsTo' => array(
|
|
|
|
array(
|
2010-11-21 18:39:18 +00:00
|
|
|
'alias' => 'BakeArticle',
|
|
|
|
'className' => 'BakeArticle',
|
|
|
|
'foreignKey' => 'bake_article_id',
|
2009-05-10 01:28:51 +00:00
|
|
|
),
|
|
|
|
array(
|
2010-11-21 18:39:18 +00:00
|
|
|
'alias' => 'BakeUser',
|
|
|
|
'className' => 'BakeUser',
|
|
|
|
'foreignKey' => 'bake_user_id',
|
2009-05-10 01:28:51 +00:00
|
|
|
),
|
|
|
|
)
|
|
|
|
);
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertEquals($expected, $result);
|
2009-05-10 03:32:22 +00:00
|
|
|
|
2010-09-20 02:58:30 +00:00
|
|
|
$model = new Model(array('ds' => 'test', 'name' => 'CategoryThread'));
|
2009-05-10 03:32:22 +00:00
|
|
|
$result = $this->Task->findBelongsTo($model, array());
|
|
|
|
$expected = array(
|
|
|
|
'belongsTo' => array(
|
|
|
|
array(
|
|
|
|
'alias' => 'ParentCategoryThread',
|
|
|
|
'className' => 'CategoryThread',
|
|
|
|
'foreignKey' => 'parent_id',
|
|
|
|
),
|
|
|
|
)
|
|
|
|
);
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertEquals($expected, $result);
|
2009-05-10 01:28:51 +00:00
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2009-05-10 01:28:51 +00:00
|
|
|
/**
|
|
|
|
* test that hasOne and/or hasMany relations are generated properly.
|
|
|
|
*
|
|
|
|
* @return void
|
2009-11-14 12:18:31 +00:00
|
|
|
*/
|
2010-04-05 03:19:38 +00:00
|
|
|
public function testHasManyHasOneGeneration() {
|
2010-11-21 18:39:18 +00:00
|
|
|
$model = new Model(array('ds' => 'test', 'name' => 'BakeArticle'));
|
2010-09-20 02:58:30 +00:00
|
|
|
$this->Task->connection = 'test';
|
2009-05-10 01:28:51 +00:00
|
|
|
$this->Task->listAll();
|
|
|
|
$result = $this->Task->findHasOneAndMany($model, array());
|
|
|
|
$expected = array(
|
|
|
|
'hasMany' => array(
|
|
|
|
array(
|
2010-11-21 18:39:18 +00:00
|
|
|
'alias' => 'BakeComment',
|
|
|
|
'className' => 'BakeComment',
|
|
|
|
'foreignKey' => 'bake_article_id',
|
2009-05-10 01:28:51 +00:00
|
|
|
),
|
|
|
|
),
|
|
|
|
'hasOne' => array(
|
|
|
|
array(
|
2010-11-21 18:39:18 +00:00
|
|
|
'alias' => 'BakeComment',
|
|
|
|
'className' => 'BakeComment',
|
|
|
|
'foreignKey' => 'bake_article_id',
|
2009-05-10 01:28:51 +00:00
|
|
|
),
|
|
|
|
),
|
|
|
|
);
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertEquals($expected, $result);
|
2009-05-10 03:32:22 +00:00
|
|
|
|
2010-09-20 02:58:30 +00:00
|
|
|
$model = new Model(array('ds' => 'test', 'name' => 'CategoryThread'));
|
2009-05-10 03:32:22 +00:00
|
|
|
$result = $this->Task->findHasOneAndMany($model, array());
|
|
|
|
$expected = array(
|
|
|
|
'hasOne' => array(
|
|
|
|
array(
|
|
|
|
'alias' => 'ChildCategoryThread',
|
|
|
|
'className' => 'CategoryThread',
|
|
|
|
'foreignKey' => 'parent_id',
|
|
|
|
),
|
|
|
|
),
|
|
|
|
'hasMany' => array(
|
|
|
|
array(
|
|
|
|
'alias' => 'ChildCategoryThread',
|
|
|
|
'className' => 'CategoryThread',
|
|
|
|
'foreignKey' => 'parent_id',
|
|
|
|
),
|
|
|
|
)
|
|
|
|
);
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertEquals($expected, $result);
|
2009-05-10 01:28:51 +00:00
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2009-05-10 01:28:51 +00:00
|
|
|
/**
|
2009-11-14 12:18:31 +00:00
|
|
|
* Test that HABTM generation works
|
2009-05-10 01:28:51 +00:00
|
|
|
*
|
|
|
|
* @return void
|
2009-11-14 12:18:31 +00:00
|
|
|
*/
|
2010-04-05 03:19:38 +00:00
|
|
|
public function testHasAndBelongsToManyGeneration() {
|
2010-11-21 18:39:18 +00:00
|
|
|
$model = new Model(array('ds' => 'test', 'name' => 'BakeArticle'));
|
2010-09-20 02:58:30 +00:00
|
|
|
$this->Task->connection = 'test';
|
2009-05-10 01:28:51 +00:00
|
|
|
$this->Task->listAll();
|
|
|
|
$result = $this->Task->findHasAndBelongsToMany($model, array());
|
|
|
|
$expected = array(
|
|
|
|
'hasAndBelongsToMany' => array(
|
|
|
|
array(
|
2010-11-21 18:39:18 +00:00
|
|
|
'alias' => 'BakeTag',
|
|
|
|
'className' => 'BakeTag',
|
|
|
|
'foreignKey' => 'bake_article_id',
|
|
|
|
'joinTable' => 'bake_articles_bake_tags',
|
|
|
|
'associationForeignKey' => 'bake_tag_id',
|
2009-05-10 01:28:51 +00:00
|
|
|
),
|
|
|
|
),
|
|
|
|
);
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertEquals($expected, $result);
|
2009-05-10 01:28:51 +00:00
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2009-05-10 16:11:20 +00:00
|
|
|
/**
|
|
|
|
* test non interactive doAssociations
|
|
|
|
*
|
|
|
|
* @return void
|
2009-11-14 12:18:31 +00:00
|
|
|
*/
|
2010-04-05 03:19:38 +00:00
|
|
|
public function testDoAssociationsNonInteractive() {
|
2010-09-20 02:58:30 +00:00
|
|
|
$this->Task->connection = 'test';
|
2009-05-10 16:11:20 +00:00
|
|
|
$this->Task->interactive = false;
|
2010-11-21 18:39:18 +00:00
|
|
|
$model = new Model(array('ds' => 'test', 'name' => 'BakeArticle'));
|
2009-05-10 16:11:20 +00:00
|
|
|
$result = $this->Task->doAssociations($model);
|
|
|
|
$expected = array(
|
2012-02-16 18:28:21 +00:00
|
|
|
'belongsTo' => array(
|
|
|
|
array(
|
|
|
|
'alias' => 'BakeUser',
|
|
|
|
'className' => 'BakeUser',
|
|
|
|
'foreignKey' => 'bake_user_id',
|
|
|
|
),
|
|
|
|
),
|
2009-05-10 16:11:20 +00:00
|
|
|
'hasMany' => array(
|
|
|
|
array(
|
2010-11-21 18:39:18 +00:00
|
|
|
'alias' => 'BakeComment',
|
|
|
|
'className' => 'BakeComment',
|
|
|
|
'foreignKey' => 'bake_article_id',
|
2009-05-10 16:11:20 +00:00
|
|
|
),
|
|
|
|
),
|
|
|
|
'hasAndBelongsToMany' => array(
|
|
|
|
array(
|
2010-11-21 18:39:18 +00:00
|
|
|
'alias' => 'BakeTag',
|
|
|
|
'className' => 'BakeTag',
|
|
|
|
'foreignKey' => 'bake_article_id',
|
|
|
|
'joinTable' => 'bake_articles_bake_tags',
|
|
|
|
'associationForeignKey' => 'bake_tag_id',
|
2009-05-10 16:11:20 +00:00
|
|
|
),
|
|
|
|
),
|
|
|
|
);
|
2012-03-23 06:37:12 +00:00
|
|
|
$this->assertEquals($expected, $result);
|
2009-05-10 16:11:20 +00:00
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2013-03-15 11:14:06 +00:00
|
|
|
/**
|
|
|
|
* test non interactive doActsAs
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function testDoActsAs() {
|
|
|
|
$this->Task->connection = 'test';
|
|
|
|
$this->Task->interactive = false;
|
|
|
|
$model = new Model(array('ds' => 'test', 'name' => 'NumberTree'));
|
|
|
|
$result = $this->Task->doActsAs($model);
|
|
|
|
|
|
|
|
$this->assertEquals(array('Tree'), $result);
|
|
|
|
}
|
|
|
|
|
2009-05-10 03:32:22 +00:00
|
|
|
/**
|
2011-11-25 15:25:11 +00:00
|
|
|
* Ensure that the fixture object is correctly called.
|
2009-05-10 03:32:22 +00:00
|
|
|
*
|
|
|
|
* @return void
|
2009-11-14 12:18:31 +00:00
|
|
|
*/
|
2010-04-05 03:19:38 +00:00
|
|
|
public function testBakeFixture() {
|
2011-05-25 19:14:23 +00:00
|
|
|
$this->Task->plugin = 'TestPlugin';
|
2010-03-05 03:02:49 +00:00
|
|
|
$this->Task->interactive = true;
|
2010-11-21 18:39:18 +00:00
|
|
|
$this->Task->Fixture->expects($this->at(0))->method('bake')->with('BakeArticle', 'bake_articles');
|
|
|
|
$this->Task->bakeFixture('BakeArticle', 'bake_articles');
|
2009-06-07 00:37:01 +00:00
|
|
|
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertEquals($this->Task->plugin, $this->Task->Fixture->plugin);
|
|
|
|
$this->assertEquals($this->Task->connection, $this->Task->Fixture->connection);
|
|
|
|
$this->assertEquals($this->Task->interactive, $this->Task->Fixture->interactive);
|
2009-05-10 03:32:22 +00:00
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2009-07-15 14:00:35 +00:00
|
|
|
/**
|
|
|
|
* Ensure that the test object is correctly called.
|
|
|
|
*
|
|
|
|
* @return void
|
2009-11-14 12:18:31 +00:00
|
|
|
*/
|
2010-04-05 03:19:38 +00:00
|
|
|
public function testBakeTest() {
|
2011-05-25 19:14:23 +00:00
|
|
|
$this->Task->plugin = 'TestPlugin';
|
2010-03-05 03:02:49 +00:00
|
|
|
$this->Task->interactive = true;
|
2010-11-21 18:39:18 +00:00
|
|
|
$this->Task->Test->expects($this->at(0))->method('bake')->with('Model', 'BakeArticle');
|
|
|
|
$this->Task->bakeTest('BakeArticle');
|
2009-07-15 14:00:35 +00:00
|
|
|
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertEquals($this->Task->plugin, $this->Task->Test->plugin);
|
|
|
|
$this->assertEquals($this->Task->connection, $this->Task->Test->connection);
|
|
|
|
$this->assertEquals($this->Task->interactive, $this->Task->Test->interactive);
|
2009-07-15 14:00:35 +00:00
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2009-05-10 05:04:40 +00:00
|
|
|
/**
|
|
|
|
* test confirming of associations, and that when an association is hasMany
|
|
|
|
* a question for the hasOne is also not asked.
|
|
|
|
*
|
|
|
|
* @return void
|
2009-11-14 12:18:31 +00:00
|
|
|
*/
|
2010-04-05 03:19:38 +00:00
|
|
|
public function testConfirmAssociations() {
|
2009-05-10 05:04:40 +00:00
|
|
|
$associations = array(
|
|
|
|
'hasOne' => array(
|
|
|
|
array(
|
|
|
|
'alias' => 'ChildCategoryThread',
|
|
|
|
'className' => 'CategoryThread',
|
|
|
|
'foreignKey' => 'parent_id',
|
|
|
|
),
|
|
|
|
),
|
|
|
|
'hasMany' => array(
|
|
|
|
array(
|
|
|
|
'alias' => 'ChildCategoryThread',
|
|
|
|
'className' => 'CategoryThread',
|
|
|
|
'foreignKey' => 'parent_id',
|
|
|
|
),
|
2009-05-10 16:11:20 +00:00
|
|
|
),
|
|
|
|
'belongsTo' => array(
|
|
|
|
array(
|
|
|
|
'alias' => 'User',
|
|
|
|
'className' => 'User',
|
|
|
|
'foreignKey' => 'user_id',
|
|
|
|
),
|
2009-05-10 05:04:40 +00:00
|
|
|
)
|
|
|
|
);
|
2010-09-20 02:58:30 +00:00
|
|
|
$model = new Model(array('ds' => 'test', 'name' => 'CategoryThread'));
|
2010-06-12 21:42:53 +00:00
|
|
|
|
|
|
|
$this->Task->expects($this->any())->method('in')
|
|
|
|
->will($this->onConsecutiveCalls('n', 'y', 'n', 'n', 'n'));
|
|
|
|
|
2009-05-10 05:04:40 +00:00
|
|
|
$result = $this->Task->confirmAssociations($model, $associations);
|
|
|
|
$this->assertTrue(empty($result['hasOne']));
|
|
|
|
|
|
|
|
$result = $this->Task->confirmAssociations($model, $associations);
|
|
|
|
$this->assertTrue(empty($result['hasMany']));
|
|
|
|
$this->assertTrue(empty($result['hasOne']));
|
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2009-05-10 15:01:15 +00:00
|
|
|
/**
|
|
|
|
* test that inOptions generates questions and only accepts a valid answer
|
|
|
|
*
|
|
|
|
* @return void
|
2009-11-14 12:18:31 +00:00
|
|
|
*/
|
2010-04-05 03:19:38 +00:00
|
|
|
public function testInOptions() {
|
2010-06-12 21:42:53 +00:00
|
|
|
$this->_useMockedOut();
|
|
|
|
|
2009-05-10 15:01:15 +00:00
|
|
|
$options = array('one', 'two', 'three');
|
2010-06-12 21:42:53 +00:00
|
|
|
$this->Task->expects($this->at(0))->method('out')->with('1. one');
|
|
|
|
$this->Task->expects($this->at(1))->method('out')->with('2. two');
|
|
|
|
$this->Task->expects($this->at(2))->method('out')->with('3. three');
|
|
|
|
$this->Task->expects($this->at(3))->method('in')->will($this->returnValue(10));
|
|
|
|
|
|
|
|
$this->Task->expects($this->at(4))->method('out')->with('1. one');
|
|
|
|
$this->Task->expects($this->at(5))->method('out')->with('2. two');
|
|
|
|
$this->Task->expects($this->at(6))->method('out')->with('3. three');
|
|
|
|
$this->Task->expects($this->at(7))->method('in')->will($this->returnValue(2));
|
2009-05-10 15:01:15 +00:00
|
|
|
$result = $this->Task->inOptions($options, 'Pick a number');
|
2012-03-23 06:37:12 +00:00
|
|
|
$this->assertEquals(1, $result);
|
2009-05-10 15:01:15 +00:00
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2009-05-14 03:36:13 +00:00
|
|
|
/**
|
|
|
|
* test baking validation
|
|
|
|
*
|
|
|
|
* @return void
|
2009-11-14 12:18:31 +00:00
|
|
|
*/
|
2010-04-05 03:19:38 +00:00
|
|
|
public function testBakeValidation() {
|
2009-05-14 03:36:13 +00:00
|
|
|
$validate = array(
|
|
|
|
'name' => array(
|
2015-05-17 20:27:16 +00:00
|
|
|
'notBlank' => 'notBlank'
|
2009-05-14 03:36:13 +00:00
|
|
|
),
|
|
|
|
'email' => array(
|
|
|
|
'email' => 'email',
|
|
|
|
),
|
|
|
|
'some_date' => array(
|
|
|
|
'date' => 'date'
|
|
|
|
),
|
|
|
|
'some_time' => array(
|
|
|
|
'time' => 'time'
|
|
|
|
)
|
|
|
|
);
|
2010-11-21 18:39:18 +00:00
|
|
|
$result = $this->Task->bake('BakeArticle', compact('validate'));
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertRegExp('/class BakeArticle extends AppModel \{/', $result);
|
|
|
|
$this->assertRegExp('/\$validate \= array\(/', $result);
|
2010-01-01 09:19:15 +00:00
|
|
|
$expected = <<< STRINGEND
|
|
|
|
array(
|
2015-05-17 20:27:16 +00:00
|
|
|
'notBlank' => array(
|
|
|
|
'rule' => array('notBlank'),
|
2010-01-01 09:19:15 +00:00
|
|
|
//'message' => 'Your custom message here',
|
|
|
|
//'allowEmpty' => false,
|
|
|
|
//'required' => false,
|
|
|
|
//'last' => false, // Stop validation after this rule
|
|
|
|
//'on' => 'create', // Limit validation to 'create' or 'update' operations
|
|
|
|
),
|
|
|
|
STRINGEND;
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertRegExp('/' . preg_quote(str_replace("\r\n", "\n", $expected), '/') . '/', $result);
|
2009-05-14 03:36:13 +00:00
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2009-05-14 03:36:13 +00:00
|
|
|
/**
|
|
|
|
* test baking relations
|
|
|
|
*
|
|
|
|
* @return void
|
2009-11-14 12:18:31 +00:00
|
|
|
*/
|
2010-04-05 03:19:38 +00:00
|
|
|
public function testBakeRelations() {
|
2009-05-14 03:36:13 +00:00
|
|
|
$associations = array(
|
|
|
|
'belongsTo' => array(
|
|
|
|
array(
|
|
|
|
'alias' => 'SomethingElse',
|
|
|
|
'className' => 'SomethingElse',
|
|
|
|
'foreignKey' => 'something_else_id',
|
|
|
|
),
|
|
|
|
array(
|
2010-11-21 18:39:18 +00:00
|
|
|
'alias' => 'BakeUser',
|
|
|
|
'className' => 'BakeUser',
|
|
|
|
'foreignKey' => 'bake_user_id',
|
2009-05-14 03:36:13 +00:00
|
|
|
),
|
|
|
|
),
|
|
|
|
'hasOne' => array(
|
|
|
|
array(
|
|
|
|
'alias' => 'OtherModel',
|
|
|
|
'className' => 'OtherModel',
|
|
|
|
'foreignKey' => 'other_model_id',
|
|
|
|
),
|
|
|
|
),
|
|
|
|
'hasMany' => array(
|
|
|
|
array(
|
2010-11-21 18:39:18 +00:00
|
|
|
'alias' => 'BakeComment',
|
|
|
|
'className' => 'BakeComment',
|
2009-05-14 03:36:13 +00:00
|
|
|
'foreignKey' => 'parent_id',
|
|
|
|
),
|
|
|
|
),
|
|
|
|
'hasAndBelongsToMany' => array(
|
|
|
|
array(
|
2010-11-21 18:39:18 +00:00
|
|
|
'alias' => 'BakeTag',
|
|
|
|
'className' => 'BakeTag',
|
|
|
|
'foreignKey' => 'bake_article_id',
|
|
|
|
'joinTable' => 'bake_articles_bake_tags',
|
|
|
|
'associationForeignKey' => 'bake_tag_id',
|
2009-05-14 03:36:13 +00:00
|
|
|
),
|
|
|
|
)
|
|
|
|
);
|
2010-11-21 18:39:18 +00:00
|
|
|
$result = $this->Task->bake('BakeArticle', compact('associations'));
|
2011-08-01 00:28:35 +00:00
|
|
|
$this->assertContains(' * @property BakeUser $BakeUser', $result);
|
|
|
|
$this->assertContains(' * @property OtherModel $OtherModel', $result);
|
|
|
|
$this->assertContains(' * @property BakeComment $BakeComment', $result);
|
|
|
|
$this->assertContains(' * @property BakeTag $BakeTag', $result);
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertRegExp('/\$hasAndBelongsToMany \= array\(/', $result);
|
|
|
|
$this->assertRegExp('/\$hasMany \= array\(/', $result);
|
|
|
|
$this->assertRegExp('/\$belongsTo \= array\(/', $result);
|
|
|
|
$this->assertRegExp('/\$hasOne \= array\(/', $result);
|
|
|
|
$this->assertRegExp('/BakeTag/', $result);
|
|
|
|
$this->assertRegExp('/OtherModel/', $result);
|
|
|
|
$this->assertRegExp('/SomethingElse/', $result);
|
|
|
|
$this->assertRegExp('/BakeComment/', $result);
|
2009-05-14 03:36:13 +00:00
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2009-06-07 00:37:01 +00:00
|
|
|
/**
|
|
|
|
* test bake() with a -plugin param
|
|
|
|
*
|
|
|
|
* @return void
|
2009-11-14 12:18:31 +00:00
|
|
|
*/
|
2010-04-05 03:19:38 +00:00
|
|
|
public function testBakeWithPlugin() {
|
2011-05-12 04:58:39 +00:00
|
|
|
$this->Task->plugin = 'ControllerTest';
|
2009-06-17 02:29:48 +00:00
|
|
|
|
2011-05-12 04:58:39 +00:00
|
|
|
//fake plugin path
|
2012-03-11 04:32:02 +00:00
|
|
|
CakePlugin::load('ControllerTest', array('path' => APP . 'Plugin' . DS . 'ControllerTest' . DS));
|
2011-05-13 07:53:53 +00:00
|
|
|
$path = APP . 'Plugin' . DS . 'ControllerTest' . DS . 'Model' . DS . 'BakeArticle.php';
|
2010-06-12 21:42:53 +00:00
|
|
|
$this->Task->expects($this->once())->method('createFile')
|
2011-09-29 04:35:15 +00:00
|
|
|
->with($path, $this->stringContains('BakeArticle extends ControllerTestAppModel'));
|
2011-05-16 22:49:00 +00:00
|
|
|
|
2011-09-10 00:32:01 +00:00
|
|
|
$result = $this->Task->bake('BakeArticle', array(), array());
|
|
|
|
$this->assertContains("App::uses('ControllerTestAppModel', 'ControllerTest.Model');", $result);
|
2010-02-12 04:01:54 +00:00
|
|
|
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertEquals(count(ClassRegistry::keys()), 0);
|
|
|
|
$this->assertEquals(count(ClassRegistry::mapKeys()), 0);
|
2009-06-07 00:37:01 +00:00
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2013-03-15 11:14:06 +00:00
|
|
|
/**
|
|
|
|
* test bake() for models with behaviors
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function testBakeWithBehaviors() {
|
|
|
|
$result = $this->Task->bake('NumberTree', array('actsAs' => array('Tree', 'PluginName.Sluggable')));
|
|
|
|
$expected = <<<TEXT
|
|
|
|
/**
|
|
|
|
* Behaviors
|
|
|
|
*
|
|
|
|
* @var array
|
|
|
|
*/
|
|
|
|
public \$actsAs = array(
|
|
|
|
'Tree',
|
|
|
|
'PluginName.Sluggable',
|
|
|
|
);
|
|
|
|
TEXT;
|
|
|
|
$this->assertTextContains($expected, $result);
|
|
|
|
}
|
|
|
|
|
2009-05-15 01:42:07 +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-15 01:42:07 +00:00
|
|
|
$this->Task->path = '/my/path/';
|
2011-03-16 02:14:10 +00:00
|
|
|
$this->Task->args = array('BakeArticle');
|
|
|
|
$filename = '/my/path/BakeArticle.php';
|
2011-05-16 22:49:00 +00:00
|
|
|
|
2010-06-12 21:42:53 +00:00
|
|
|
$this->Task->expects($this->once())->method('_checkUnitTest')->will($this->returnValue(1));
|
|
|
|
$this->Task->expects($this->once())->method('createFile')
|
2011-09-29 04:35:15 +00:00
|
|
|
->with($filename, $this->stringContains('class BakeArticle extends AppModel'));
|
2010-06-12 21:42:53 +00:00
|
|
|
|
2009-05-15 01:42:07 +00:00
|
|
|
$this->Task->execute();
|
2010-02-12 04:01:54 +00:00
|
|
|
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertEquals(count(ClassRegistry::keys()), 0);
|
|
|
|
$this->assertEquals(count(ClassRegistry::mapKeys()), 0);
|
2009-05-15 01:42:07 +00:00
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2010-06-12 21:42:53 +00:00
|
|
|
/**
|
|
|
|
* data provider for testExecuteWithNamedModelVariations
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
2012-03-11 04:32:02 +00:00
|
|
|
public static function nameVariations() {
|
2010-06-12 21:42:53 +00:00
|
|
|
return array(
|
2010-11-21 18:39:18 +00:00
|
|
|
array('BakeArticles'), array('BakeArticle'), array('bake_article'), array('bake_articles')
|
2010-06-12 21:42:53 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2010-03-06 02:30:58 +00:00
|
|
|
/**
|
|
|
|
* test that execute passes with different inflections of the same name.
|
|
|
|
*
|
2010-06-12 21:42:53 +00:00
|
|
|
* @dataProvider nameVariations
|
2010-03-06 02:30:58 +00:00
|
|
|
* @return void
|
|
|
|
*/
|
2010-06-12 21:42:53 +00:00
|
|
|
public function testExecuteWithNamedModelVariations($name) {
|
2010-09-20 02:58:30 +00:00
|
|
|
$this->Task->connection = 'test';
|
2010-03-06 02:30:58 +00:00
|
|
|
$this->Task->path = '/my/path/';
|
2010-06-12 21:42:53 +00:00
|
|
|
$this->Task->expects($this->once())->method('_checkUnitTest')->will($this->returnValue(1));
|
2010-03-06 02:30:58 +00:00
|
|
|
|
2010-06-12 21:42:53 +00:00
|
|
|
$this->Task->args = array($name);
|
2011-03-16 02:14:10 +00:00
|
|
|
$filename = '/my/path/BakeArticle.php';
|
2010-03-06 02:30:58 +00:00
|
|
|
|
2010-06-12 21:42:53 +00:00
|
|
|
$this->Task->expects($this->at(0))->method('createFile')
|
2011-09-29 04:35:15 +00:00
|
|
|
->with($filename, $this->stringContains('class BakeArticle extends AppModel'));
|
2010-03-06 02:30:58 +00:00
|
|
|
$this->Task->execute();
|
|
|
|
}
|
|
|
|
|
2010-02-21 01:13:42 +00:00
|
|
|
/**
|
|
|
|
* test that execute with a model name picks up hasMany associations.
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
2010-04-05 03:19:38 +00:00
|
|
|
public function testExecuteWithNamedModelHasManyCreated() {
|
2010-09-20 02:58:30 +00:00
|
|
|
$this->Task->connection = 'test';
|
2010-02-21 01:13:42 +00:00
|
|
|
$this->Task->path = '/my/path/';
|
2011-03-16 02:14:10 +00:00
|
|
|
$this->Task->args = array('BakeArticle');
|
|
|
|
$filename = '/my/path/BakeArticle.php';
|
2011-05-16 22:49:00 +00:00
|
|
|
|
2010-06-12 21:42:53 +00:00
|
|
|
$this->Task->expects($this->once())->method('_checkUnitTest')->will($this->returnValue(1));
|
|
|
|
$this->Task->expects($this->at(0))->method('createFile')
|
2011-09-29 04:35:15 +00:00
|
|
|
->with($filename, $this->stringContains("'BakeComment' => array("));
|
2010-06-12 21:42:53 +00:00
|
|
|
|
2010-02-21 01:13:42 +00:00
|
|
|
$this->Task->execute();
|
|
|
|
}
|
|
|
|
|
2009-05-15 01:42:07 +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
|
|
|
$count = count($this->Task->listAll('test'));
|
2010-07-10 04:22:14 +00:00
|
|
|
if ($count != count($this->fixtures)) {
|
|
|
|
$this->markTestSkipped('Additional tables detected.');
|
|
|
|
}
|
|
|
|
|
2010-09-20 02:58:30 +00:00
|
|
|
$this->Task->connection = 'test';
|
2009-05-15 01:42:07 +00:00
|
|
|
$this->Task->path = '/my/path/';
|
|
|
|
$this->Task->args = array('all');
|
2010-06-12 21:42:53 +00:00
|
|
|
$this->Task->expects($this->once())->method('_checkUnitTest')->will($this->returnValue(true));
|
2009-07-15 14:00:35 +00:00
|
|
|
|
2014-05-14 08:28:11 +00:00
|
|
|
$this->Task->Fixture->expects($this->exactly(6))->method('bake');
|
|
|
|
$this->Task->Test->expects($this->exactly(6))->method('bake');
|
2009-05-15 02:19:43 +00:00
|
|
|
|
2011-03-16 02:14:10 +00:00
|
|
|
$filename = '/my/path/BakeArticle.php';
|
2010-06-12 21:42:53 +00:00
|
|
|
$this->Task->expects($this->at(1))->method('createFile')
|
2011-09-29 04:35:15 +00:00
|
|
|
->with($filename, $this->stringContains('class BakeArticle'));
|
2009-05-15 01:42:07 +00:00
|
|
|
|
2011-03-16 02:14:10 +00:00
|
|
|
$filename = '/my/path/BakeArticlesBakeTag.php';
|
2010-06-12 21:42:53 +00:00
|
|
|
$this->Task->expects($this->at(2))->method('createFile')
|
2011-09-29 04:35:15 +00:00
|
|
|
->with($filename, $this->stringContains('class BakeArticlesBakeTag'));
|
2009-05-15 01:42:07 +00:00
|
|
|
|
2011-03-16 02:14:10 +00:00
|
|
|
$filename = '/my/path/BakeComment.php';
|
2010-06-12 21:42:53 +00:00
|
|
|
$this->Task->expects($this->at(3))->method('createFile')
|
2011-09-29 04:35:15 +00:00
|
|
|
->with($filename, $this->stringContains('class BakeComment'));
|
2009-05-15 01:42:07 +00:00
|
|
|
|
2011-11-25 15:25:11 +00:00
|
|
|
$filename = '/my/path/BakeComment.php';
|
|
|
|
$this->Task->expects($this->at(3))->method('createFile')
|
|
|
|
->with($filename, $this->stringContains('public $primaryKey = \'otherid\';'));
|
|
|
|
|
2011-03-16 02:14:10 +00:00
|
|
|
$filename = '/my/path/BakeTag.php';
|
2011-11-25 15:25:11 +00:00
|
|
|
$this->Task->expects($this->at(4))->method('createFile')
|
|
|
|
->with($filename, $this->stringContains('class BakeTag'));
|
|
|
|
|
2011-03-16 02:14:10 +00:00
|
|
|
$filename = '/my/path/BakeTag.php';
|
2011-11-25 15:25:11 +00:00
|
|
|
$this->Task->expects($this->at(4))->method('createFile')
|
|
|
|
->with($filename, $this->logicalNot($this->stringContains('public $primaryKey')));
|
2011-05-16 22:49:00 +00:00
|
|
|
|
2011-03-16 02:14:10 +00:00
|
|
|
$filename = '/my/path/CategoryThread.php';
|
2010-11-21 18:39:18 +00:00
|
|
|
$this->Task->expects($this->at(5))->method('createFile')
|
2011-09-29 04:35:15 +00:00
|
|
|
->with($filename, $this->stringContains('class CategoryThread'));
|
2009-05-15 01:42:07 +00:00
|
|
|
|
2014-05-14 08:28:11 +00:00
|
|
|
$filename = '/my/path/NumberTree.php';
|
|
|
|
$this->Task->expects($this->at(6))->method('createFile')
|
|
|
|
->with($filename, $this->stringContains('class NumberTree'));
|
|
|
|
|
2009-05-15 01:42:07 +00:00
|
|
|
$this->Task->execute();
|
2010-02-12 04:01:54 +00:00
|
|
|
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertEquals(count(ClassRegistry::keys()), 0);
|
|
|
|
$this->assertEquals(count(ClassRegistry::mapKeys()), 0);
|
2009-05-15 01:42:07 +00:00
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2011-11-25 15:25:11 +00:00
|
|
|
/**
|
2013-03-05 07:05:14 +00:00
|
|
|
* test that odd tablenames aren't inflected back from modelname
|
2011-11-25 15:25:11 +00:00
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
2011-12-16 06:52:07 +00:00
|
|
|
public function testExecuteIntoAllOddTables() {
|
2011-11-25 15:25:11 +00:00
|
|
|
$out = $this->getMock('ConsoleOutput', array(), array(), '', false);
|
|
|
|
$in = $this->getMock('ConsoleInput', array(), array(), '', false);
|
|
|
|
$this->Task = $this->getMock('ModelTask',
|
|
|
|
array('in', 'err', '_stop', '_checkUnitTest', 'getAllTables', '_getModelObject', 'bake', 'bakeFixture'),
|
|
|
|
array($out, $out, $in)
|
|
|
|
);
|
|
|
|
$this->_setupOtherMocks();
|
|
|
|
|
|
|
|
$this->Task->connection = 'test';
|
|
|
|
$this->Task->path = '/my/path/';
|
|
|
|
$this->Task->args = array('all');
|
|
|
|
$this->Task->expects($this->once())->method('_checkUnitTest')->will($this->returnValue(true));
|
|
|
|
$this->Task->expects($this->once())->method('getAllTables')->will($this->returnValue(array('bake_odd')));
|
|
|
|
$object = new Model(array('name' => 'BakeOdd', 'table' => 'bake_odd', 'ds' => 'test'));
|
|
|
|
$this->Task->expects($this->once())->method('_getModelObject')->with('BakeOdd', 'bake_odd')->will($this->returnValue($object));
|
|
|
|
$this->Task->expects($this->at(3))->method('bake')->with($object, false)->will($this->returnValue(true));
|
|
|
|
$this->Task->expects($this->once())->method('bakeFixture')->with('BakeOdd', 'bake_odd');
|
|
|
|
|
|
|
|
$this->Task->execute();
|
|
|
|
|
|
|
|
$out = $this->getMock('ConsoleOutput', array(), array(), '', false);
|
|
|
|
$in = $this->getMock('ConsoleInput', array(), array(), '', false);
|
|
|
|
$this->Task = $this->getMock('ModelTask',
|
2013-03-15 11:14:06 +00:00
|
|
|
array('in', 'err', '_stop', '_checkUnitTest', 'getAllTables', '_getModelObject', 'doAssociations', 'doValidation', 'doActsAs', 'createFile'),
|
2011-11-25 15:25:11 +00:00
|
|
|
array($out, $out, $in)
|
|
|
|
);
|
|
|
|
$this->_setupOtherMocks();
|
|
|
|
|
|
|
|
$this->Task->connection = 'test';
|
|
|
|
$this->Task->path = '/my/path/';
|
|
|
|
$this->Task->args = array('all');
|
|
|
|
$this->Task->expects($this->once())->method('_checkUnitTest')->will($this->returnValue(true));
|
|
|
|
$this->Task->expects($this->once())->method('getAllTables')->will($this->returnValue(array('bake_odd')));
|
|
|
|
$object = new Model(array('name' => 'BakeOdd', 'table' => 'bake_odd', 'ds' => 'test'));
|
|
|
|
$this->Task->expects($this->once())->method('_getModelObject')->will($this->returnValue($object));
|
|
|
|
$this->Task->expects($this->once())->method('doAssociations')->will($this->returnValue(array()));
|
|
|
|
$this->Task->expects($this->once())->method('doValidation')->will($this->returnValue(array()));
|
2013-03-15 11:14:06 +00:00
|
|
|
$this->Task->expects($this->once())->method('doActsAs')->will($this->returnValue(array()));
|
2011-11-25 15:25:11 +00:00
|
|
|
|
|
|
|
$filename = '/my/path/BakeOdd.php';
|
|
|
|
$this->Task->expects($this->once())->method('createFile')
|
|
|
|
->with($filename, $this->stringContains('class BakeOdd'));
|
|
|
|
|
|
|
|
$filename = '/my/path/BakeOdd.php';
|
|
|
|
$this->Task->expects($this->once())->method('createFile')
|
|
|
|
->with($filename, $this->stringContains('public $useTable = \'bake_odd\''));
|
2011-12-05 11:21:18 +00:00
|
|
|
|
|
|
|
$this->Task->execute();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2013-03-05 07:05:14 +00:00
|
|
|
* test that odd tablenames aren't inflected back from modelname
|
2011-12-05 11:21:18 +00:00
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
2011-12-16 06:52:07 +00:00
|
|
|
public function testExecuteIntoBakeOddTables() {
|
2011-12-05 11:21:18 +00:00
|
|
|
$out = $this->getMock('ConsoleOutput', array(), array(), '', false);
|
|
|
|
$in = $this->getMock('ConsoleInput', array(), array(), '', false);
|
|
|
|
$this->Task = $this->getMock('ModelTask',
|
|
|
|
array('in', 'err', '_stop', '_checkUnitTest', 'getAllTables', '_getModelObject', 'bake', 'bakeFixture'),
|
|
|
|
array($out, $out, $in)
|
|
|
|
);
|
|
|
|
$this->_setupOtherMocks();
|
|
|
|
|
|
|
|
$this->Task->connection = 'test';
|
|
|
|
$this->Task->path = '/my/path/';
|
|
|
|
$this->Task->args = array('BakeOdd');
|
|
|
|
$this->Task->expects($this->once())->method('_checkUnitTest')->will($this->returnValue(true));
|
|
|
|
$this->Task->expects($this->once())->method('getAllTables')->will($this->returnValue(array('articles', 'bake_odd')));
|
|
|
|
$object = new Model(array('name' => 'BakeOdd', 'table' => 'bake_odd', 'ds' => 'test'));
|
|
|
|
$this->Task->expects($this->once())->method('_getModelObject')->with('BakeOdd', 'bake_odd')->will($this->returnValue($object));
|
|
|
|
$this->Task->expects($this->once())->method('bake')->with($object, false)->will($this->returnValue(true));
|
|
|
|
$this->Task->expects($this->once())->method('bakeFixture')->with('BakeOdd', 'bake_odd');
|
|
|
|
|
|
|
|
$this->Task->execute();
|
|
|
|
|
|
|
|
$out = $this->getMock('ConsoleOutput', array(), array(), '', false);
|
|
|
|
$in = $this->getMock('ConsoleInput', array(), array(), '', false);
|
|
|
|
$this->Task = $this->getMock('ModelTask',
|
2013-03-15 11:14:06 +00:00
|
|
|
array('in', 'err', '_stop', '_checkUnitTest', 'getAllTables', '_getModelObject', 'doAssociations', 'doValidation', 'doActsAs', 'createFile'),
|
2011-12-05 11:21:18 +00:00
|
|
|
array($out, $out, $in)
|
|
|
|
);
|
|
|
|
$this->_setupOtherMocks();
|
|
|
|
|
|
|
|
$this->Task->connection = 'test';
|
|
|
|
$this->Task->path = '/my/path/';
|
|
|
|
$this->Task->args = array('BakeOdd');
|
|
|
|
$this->Task->expects($this->once())->method('_checkUnitTest')->will($this->returnValue(true));
|
|
|
|
$this->Task->expects($this->once())->method('getAllTables')->will($this->returnValue(array('articles', 'bake_odd')));
|
|
|
|
$object = new Model(array('name' => 'BakeOdd', 'table' => 'bake_odd', 'ds' => 'test'));
|
|
|
|
$this->Task->expects($this->once())->method('_getModelObject')->will($this->returnValue($object));
|
|
|
|
$this->Task->expects($this->once())->method('doAssociations')->will($this->returnValue(array()));
|
2011-11-25 15:25:11 +00:00
|
|
|
$this->Task->expects($this->once())->method('doValidation')->will($this->returnValue(array()));
|
2013-03-15 11:14:06 +00:00
|
|
|
$this->Task->expects($this->once())->method('doActsAs')->will($this->returnValue(array()));
|
2011-11-25 15:25:11 +00:00
|
|
|
|
|
|
|
$filename = '/my/path/BakeOdd.php';
|
|
|
|
$this->Task->expects($this->once())->method('createFile')
|
|
|
|
->with($filename, $this->stringContains('class BakeOdd'));
|
|
|
|
|
|
|
|
$filename = '/my/path/BakeOdd.php';
|
|
|
|
$this->Task->expects($this->once())->method('createFile')
|
|
|
|
->with($filename, $this->stringContains('public $useTable = \'bake_odd\''));
|
|
|
|
|
|
|
|
$this->Task->execute();
|
|
|
|
}
|
|
|
|
|
2010-02-13 23:15:11 +00:00
|
|
|
/**
|
|
|
|
* test that skipTables changes how all() works.
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
2011-05-30 20:02:32 +00:00
|
|
|
public function testSkipTablesAndAll() {
|
2010-09-20 02:58:30 +00:00
|
|
|
$count = count($this->Task->listAll('test'));
|
2010-07-10 04:22:14 +00:00
|
|
|
if ($count != count($this->fixtures)) {
|
|
|
|
$this->markTestSkipped('Additional tables detected.');
|
|
|
|
}
|
|
|
|
|
2010-09-20 02:58:30 +00:00
|
|
|
$this->Task->connection = 'test';
|
2010-02-13 23:15:11 +00:00
|
|
|
$this->Task->path = '/my/path/';
|
|
|
|
$this->Task->args = array('all');
|
2010-06-12 21:42:53 +00:00
|
|
|
$this->Task->expects($this->once())->method('_checkUnitTest')->will($this->returnValue(true));
|
2014-05-14 08:28:11 +00:00
|
|
|
$this->Task->skipTables = array('bake_tags', 'number_trees');
|
2010-02-13 23:15:11 +00:00
|
|
|
|
2010-06-12 21:42:53 +00:00
|
|
|
$this->Task->Fixture->expects($this->exactly(4))->method('bake');
|
|
|
|
$this->Task->Test->expects($this->exactly(4))->method('bake');
|
2010-02-13 23:15:11 +00:00
|
|
|
|
2011-03-16 02:14:10 +00:00
|
|
|
$filename = '/my/path/BakeArticle.php';
|
2010-06-12 21:42:53 +00:00
|
|
|
$this->Task->expects($this->at(1))->method('createFile')
|
2011-09-29 04:35:15 +00:00
|
|
|
->with($filename, $this->stringContains('class BakeArticle'));
|
2010-02-13 23:15:11 +00:00
|
|
|
|
2011-03-16 02:14:10 +00:00
|
|
|
$filename = '/my/path/BakeArticlesBakeTag.php';
|
2010-06-12 21:42:53 +00:00
|
|
|
$this->Task->expects($this->at(2))->method('createFile')
|
2011-09-29 04:35:15 +00:00
|
|
|
->with($filename, $this->stringContains('class BakeArticlesBakeTag'));
|
2010-02-13 23:15:11 +00:00
|
|
|
|
2011-03-16 02:14:10 +00:00
|
|
|
$filename = '/my/path/BakeComment.php';
|
2010-06-12 21:42:53 +00:00
|
|
|
$this->Task->expects($this->at(3))->method('createFile')
|
2011-09-29 04:35:15 +00:00
|
|
|
->with($filename, $this->stringContains('class BakeComment'));
|
2010-02-13 23:15:11 +00:00
|
|
|
|
2011-03-16 02:14:10 +00:00
|
|
|
$filename = '/my/path/CategoryThread.php';
|
2010-06-12 21:42:53 +00:00
|
|
|
$this->Task->expects($this->at(4))->method('createFile')
|
2011-09-29 04:35:15 +00:00
|
|
|
->with($filename, $this->stringContains('class CategoryThread'));
|
2010-02-13 23:15:11 +00:00
|
|
|
|
|
|
|
$this->Task->execute();
|
|
|
|
}
|
|
|
|
|
2009-05-15 02:36:04 +00:00
|
|
|
/**
|
|
|
|
* test the interactive side of bake.
|
|
|
|
*
|
|
|
|
* @return void
|
2009-11-14 12:18:31 +00:00
|
|
|
*/
|
2010-04-05 03:19:38 +00:00
|
|
|
public function testExecuteIntoInteractive() {
|
2011-11-24 02:30:28 +00:00
|
|
|
$tables = $this->Task->listAll('test');
|
|
|
|
$article = array_search('bake_articles', $tables) + 1;
|
2010-07-10 04:22:14 +00:00
|
|
|
|
2010-09-20 02:58:30 +00:00
|
|
|
$this->Task->connection = 'test';
|
2009-05-15 02:36:04 +00:00
|
|
|
$this->Task->path = '/my/path/';
|
2009-07-09 03:30:29 +00:00
|
|
|
$this->Task->interactive = true;
|
2009-05-15 02:36:04 +00:00
|
|
|
|
2010-06-12 21:42:53 +00:00
|
|
|
$this->Task->expects($this->any())->method('in')
|
|
|
|
->will($this->onConsecutiveCalls(
|
2011-11-24 02:30:28 +00:00
|
|
|
$article, // article
|
2010-06-12 21:42:53 +00:00
|
|
|
'n', // no validation
|
|
|
|
'y', // associations
|
|
|
|
'y', // comment relation
|
|
|
|
'y', // user relation
|
|
|
|
'y', // tag relation
|
|
|
|
'n', // additional assocs
|
|
|
|
'y' // looks good?
|
|
|
|
));
|
|
|
|
$this->Task->expects($this->once())->method('_checkUnitTest')->will($this->returnValue(true));
|
|
|
|
|
|
|
|
$this->Task->Test->expects($this->once())->method('bake');
|
|
|
|
$this->Task->Fixture->expects($this->once())->method('bake');
|
2009-05-15 02:36:04 +00:00
|
|
|
|
2011-03-16 02:14:10 +00:00
|
|
|
$filename = '/my/path/BakeArticle.php';
|
2010-06-12 21:42:53 +00:00
|
|
|
|
|
|
|
$this->Task->expects($this->once())->method('createFile')
|
2011-09-29 04:35:15 +00:00
|
|
|
->with($filename, $this->stringContains('class BakeArticle'));
|
2010-06-12 21:42:53 +00:00
|
|
|
|
2009-05-15 02:36:04 +00:00
|
|
|
$this->Task->execute();
|
2010-02-12 04:01:54 +00:00
|
|
|
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertEquals(count(ClassRegistry::keys()), 0);
|
|
|
|
$this->assertEquals(count(ClassRegistry::mapKeys()), 0);
|
2009-05-15 02:36:04 +00:00
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2009-07-09 03:30:29 +00:00
|
|
|
/**
|
|
|
|
* test using bake interactively with a table that does not exist.
|
|
|
|
*
|
|
|
|
* @return void
|
2009-11-14 12:18:31 +00:00
|
|
|
*/
|
2010-04-05 03:19:38 +00:00
|
|
|
public function testExecuteWithNonExistantTableName() {
|
2010-09-20 02:58:30 +00:00
|
|
|
$this->Task->connection = 'test';
|
2009-07-09 03:30:29 +00:00
|
|
|
$this->Task->path = '/my/path/';
|
|
|
|
|
2011-11-20 00:11:33 +00:00
|
|
|
$this->Task->expects($this->any())->method('in')
|
|
|
|
->will($this->onConsecutiveCalls(
|
|
|
|
'Foobar', // Or type in the name of the model
|
|
|
|
'y', // Do you want to use this table
|
|
|
|
'n' // Doesn't exist, continue anyway?
|
|
|
|
));
|
|
|
|
|
|
|
|
$this->Task->execute();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* test using bake interactively with a table that does not exist.
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function testForcedExecuteWithNonExistantTableName() {
|
|
|
|
$this->Task->connection = 'test';
|
|
|
|
$this->Task->path = '/my/path/';
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2010-07-10 04:22:14 +00:00
|
|
|
$this->Task->expects($this->any())->method('in')
|
2011-11-20 00:11:33 +00:00
|
|
|
->will($this->onConsecutiveCalls(
|
|
|
|
'Foobar', // Or type in the name of the model
|
|
|
|
'y', // Do you want to use this table
|
|
|
|
'y', // Doesn't exist, continue anyway?
|
|
|
|
'id', // Primary key
|
|
|
|
'y' // Looks good?
|
|
|
|
));
|
2010-07-10 04:22:14 +00:00
|
|
|
|
2009-07-09 03:30:29 +00:00
|
|
|
$this->Task->execute();
|
|
|
|
}
|
2011-11-20 00:11:33 +00:00
|
|
|
|
2009-04-30 02:17:08 +00:00
|
|
|
}
|