2009-02-13 14:22:11 +00:00
|
|
|
<?php
|
|
|
|
/**
|
2009-03-19 21:10:13 +00:00
|
|
|
* TestTaskTest file
|
2009-02-13 14:22:11 +00:00
|
|
|
*
|
2009-03-19 21:10:13 +00:00
|
|
|
* Test Case for test generation shell task
|
2009-02-13 14:22:11 +00:00
|
|
|
*
|
2017-06-10 21:33:55 +00:00
|
|
|
* CakePHP : Rapid Development Framework (https://cakephp.org)
|
2017-06-10 22:10:52 +00:00
|
|
|
* Copyright (c) Cake Software Foundation, Inc. (https://cakefoundation.org)
|
2009-02-13 14:22:11 +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-02-13 14:22:11 +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 Project
|
2011-07-26 06:16:14 +00:00
|
|
|
* @package Cake.Test.Case.Console.Command.Task
|
2009-02-13 14:22:11 +00:00
|
|
|
* @since CakePHP v 1.2.0.7726
|
2017-06-10 22:23:14 +00:00
|
|
|
* @license https://opensource.org/licenses/mit-license.php MIT License
|
2009-02-13 14:22:11 +00:00
|
|
|
*/
|
2010-10-17 19:43:20 +00:00
|
|
|
|
2010-12-09 03:45:18 +00:00
|
|
|
App::uses('ShellDispatcher', 'Console');
|
2011-03-07 05:27:21 +00:00
|
|
|
App::uses('ConsoleOutput', 'Console');
|
|
|
|
App::uses('ConsoleInput', 'Console');
|
2010-12-09 03:45:18 +00:00
|
|
|
App::uses('Shell', 'Console');
|
|
|
|
App::uses('TestTask', 'Console/Command/Task');
|
|
|
|
App::uses('TemplateTask', 'Console/Command/Task');
|
|
|
|
App::uses('Controller', 'Controller');
|
|
|
|
App::uses('Model', 'Model');
|
2010-01-17 00:41:52 +00:00
|
|
|
|
2009-05-24 05:15:31 +00:00
|
|
|
/**
|
2009-11-14 12:18:31 +00:00
|
|
|
* Test Article model
|
|
|
|
*
|
2011-07-26 06:16:14 +00:00
|
|
|
* @package Cake.Test.Case.Console.Command.Task
|
2009-11-14 12:18:31 +00:00
|
|
|
*/
|
2009-05-24 05:15:31 +00:00
|
|
|
class TestTaskArticle extends Model {
|
2009-11-14 12:18:31 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Table name to use
|
|
|
|
*
|
|
|
|
* @var string
|
|
|
|
*/
|
2010-04-04 07:14:00 +00:00
|
|
|
public $useTable = 'articles';
|
2009-11-14 12:18:31 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* HasMany Associations
|
|
|
|
*
|
|
|
|
* @var array
|
|
|
|
*/
|
2010-04-04 07:14:00 +00:00
|
|
|
public $hasMany = array(
|
2009-05-24 05:15:31 +00:00
|
|
|
'Comment' => array(
|
|
|
|
'className' => 'TestTask.TestTaskComment',
|
|
|
|
'foreignKey' => 'article_id',
|
|
|
|
)
|
|
|
|
);
|
2009-11-14 12:18:31 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Has and Belongs To Many Associations
|
|
|
|
*
|
|
|
|
* @var array
|
|
|
|
*/
|
2010-04-04 07:14:00 +00:00
|
|
|
public $hasAndBelongsToMany = array(
|
2009-05-24 05:15:31 +00:00
|
|
|
'Tag' => array(
|
|
|
|
'className' => 'TestTaskTag',
|
|
|
|
'joinTable' => 'articles_tags',
|
|
|
|
'foreignKey' => 'article_id',
|
|
|
|
'associationForeignKey' => 'tag_id'
|
|
|
|
)
|
|
|
|
);
|
2009-05-25 03:50:21 +00:00
|
|
|
|
2009-11-14 12:18:31 +00:00
|
|
|
/**
|
|
|
|
* Example public method
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
2010-04-05 03:19:38 +00:00
|
|
|
public function doSomething() {
|
2009-05-25 03:50:21 +00:00
|
|
|
}
|
|
|
|
|
2009-11-14 12:18:31 +00:00
|
|
|
/**
|
|
|
|
* Example Secondary public method
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
2010-04-05 03:19:38 +00:00
|
|
|
public function doSomethingElse() {
|
2009-05-25 03:50:21 +00:00
|
|
|
}
|
|
|
|
|
2009-11-14 12:18:31 +00:00
|
|
|
/**
|
|
|
|
* Example protected method
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
2010-04-05 03:21:28 +00:00
|
|
|
protected function _innerMethod() {
|
2009-05-25 03:50:21 +00:00
|
|
|
}
|
2012-03-11 04:32:02 +00:00
|
|
|
|
2009-05-24 05:15:31 +00:00
|
|
|
}
|
2009-11-14 12:18:31 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Tag Testing Model
|
|
|
|
*
|
2011-07-26 06:16:14 +00:00
|
|
|
* @package Cake.Test.Case.Console.Command.Task
|
2009-11-14 12:18:31 +00:00
|
|
|
*/
|
2009-05-24 05:15:31 +00:00
|
|
|
class TestTaskTag extends Model {
|
2009-11-14 12:18:31 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Table name
|
|
|
|
*
|
|
|
|
* @var string
|
|
|
|
*/
|
2010-04-04 07:14:00 +00:00
|
|
|
public $useTable = 'tags';
|
2009-11-14 12:18:31 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Has and Belongs To Many Associations
|
|
|
|
*
|
|
|
|
* @var array
|
|
|
|
*/
|
2010-04-04 07:14:00 +00:00
|
|
|
public $hasAndBelongsToMany = array(
|
2009-05-24 05:15:31 +00:00
|
|
|
'Article' => array(
|
|
|
|
'className' => 'TestTaskArticle',
|
|
|
|
'joinTable' => 'articles_tags',
|
|
|
|
'foreignKey' => 'tag_id',
|
|
|
|
'associationForeignKey' => 'article_id'
|
|
|
|
)
|
|
|
|
);
|
|
|
|
}
|
2009-07-26 09:59:51 +00:00
|
|
|
|
2009-05-24 05:15:31 +00:00
|
|
|
/**
|
2009-11-14 12:18:31 +00:00
|
|
|
* Simulated plugin
|
|
|
|
*
|
2011-07-26 06:16:14 +00:00
|
|
|
* @package Cake.Test.Case.Console.Command.Task
|
2009-11-14 12:18:31 +00:00
|
|
|
*/
|
2009-05-24 05:15:31 +00:00
|
|
|
class TestTaskAppModel extends Model {
|
2009-05-24 03:48:25 +00:00
|
|
|
}
|
2009-11-14 12:18:31 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Testing AppMode (TaskComment)
|
|
|
|
*
|
2011-07-26 06:16:14 +00:00
|
|
|
* @package Cake.Test.Case.Console.Command.Task
|
2009-11-14 12:18:31 +00:00
|
|
|
*/
|
2009-05-24 05:15:31 +00:00
|
|
|
class TestTaskComment extends TestTaskAppModel {
|
2009-11-14 12:18:31 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Table name
|
|
|
|
*
|
|
|
|
* @var string
|
|
|
|
*/
|
2010-04-04 07:14:00 +00:00
|
|
|
public $useTable = 'comments';
|
2009-11-14 12:18:31 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Belongs To Associations
|
|
|
|
*
|
|
|
|
* @var array
|
|
|
|
*/
|
2010-04-04 07:14:00 +00:00
|
|
|
public $belongsTo = array(
|
2009-05-24 05:15:31 +00:00
|
|
|
'Article' => array(
|
|
|
|
'className' => 'TestTaskArticle',
|
|
|
|
'foreignKey' => 'article_id',
|
|
|
|
)
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2009-11-14 12:18:31 +00:00
|
|
|
/**
|
|
|
|
* Test Task Comments Controller
|
|
|
|
*
|
2011-07-26 06:16:14 +00:00
|
|
|
* @package Cake.Test.Case.Console.Command.Task
|
2009-11-14 12:18:31 +00:00
|
|
|
*/
|
2009-05-24 05:30:04 +00:00
|
|
|
class TestTaskCommentsController extends Controller {
|
2009-11-14 12:18:31 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Models to use
|
|
|
|
*
|
|
|
|
* @var array
|
|
|
|
*/
|
2010-04-04 07:14:00 +00:00
|
|
|
public $uses = array('TestTaskComment', 'TestTaskTag');
|
2009-05-24 05:30:04 +00:00
|
|
|
}
|
|
|
|
|
2009-03-13 16:06:18 +00:00
|
|
|
/**
|
|
|
|
* TestTaskTest class
|
|
|
|
*
|
2011-07-26 06:16:14 +00:00
|
|
|
* @package Cake.Test.Case.Console.Command.Task
|
2009-03-13 16:06:18 +00:00
|
|
|
*/
|
2009-02-13 14:22:11 +00:00
|
|
|
class TestTaskTest extends CakeTestCase {
|
2009-05-24 05:15:31 +00:00
|
|
|
|
2009-11-14 12:18:31 +00:00
|
|
|
/**
|
|
|
|
* Fixtures
|
|
|
|
*
|
|
|
|
* @var string
|
|
|
|
*/
|
2010-04-04 07:14:00 +00:00
|
|
|
public $fixtures = array('core.article', 'core.comment', 'core.articles_tag', 'core.tag');
|
2009-07-26 09:59:51 +00:00
|
|
|
|
2009-03-13 16:06:18 +00:00
|
|
|
/**
|
2011-12-04 21:27:51 +00:00
|
|
|
* setUp method
|
2009-03-13 16:06:18 +00:00
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
2022-12-28 07:03:39 +00:00
|
|
|
public function setUp() : void {
|
2011-12-04 21:27:51 +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);
|
|
|
|
|
2011-04-17 10:35:21 +00:00
|
|
|
$this->Task = $this->getMock('TestTask',
|
2010-06-10 00:15:37 +00:00
|
|
|
array('in', 'err', 'createFile', '_stop', 'isLoadableClass'),
|
2010-10-24 19:27:04 +00:00
|
|
|
array($out, $out, $in)
|
2010-06-10 00:15:37 +00:00
|
|
|
);
|
2010-10-19 03:09:23 +00:00
|
|
|
$this->Task->name = 'Test';
|
2010-10-24 19:27:04 +00:00
|
|
|
$this->Task->Template = new TemplateTask($out, $out, $in);
|
2009-03-13 16:06:18 +00:00
|
|
|
}
|
2009-07-26 09:59:51 +00:00
|
|
|
|
2009-03-13 16:06:18 +00:00
|
|
|
/**
|
2012-04-11 14:50:54 +00:00
|
|
|
* tearDown method
|
2009-03-13 16:06:18 +00:00
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
2022-12-28 07:03:39 +00:00
|
|
|
public function tearDown() : void {
|
2010-10-07 02:52:42 +00:00
|
|
|
parent::tearDown();
|
2010-10-24 19:27:04 +00:00
|
|
|
unset($this->Task);
|
2011-05-12 04:22:09 +00:00
|
|
|
CakePlugin::unload();
|
2009-02-13 14:22:11 +00:00
|
|
|
}
|
2009-07-26 09:59:51 +00:00
|
|
|
|
2009-02-13 14:22:11 +00:00
|
|
|
/**
|
|
|
|
* Test that file path generation doesn't continuously append paths.
|
2009-03-13 16:06:18 +00:00
|
|
|
*
|
2009-02-13 14:22:11 +00:00
|
|
|
* @return void
|
|
|
|
*/
|
2010-06-10 00:15:37 +00:00
|
|
|
public function testFilePathGenerationModelRepeated() {
|
2010-10-24 19:27:04 +00:00
|
|
|
$this->Task->expects($this->never())->method('err');
|
|
|
|
$this->Task->expects($this->never())->method('_stop');
|
2009-02-13 14:22:11 +00:00
|
|
|
|
2011-04-11 01:19:16 +00:00
|
|
|
$file = TESTS . 'Case' . DS . 'Model' . DS . 'MyClassTest.php';
|
2009-03-13 16:06:18 +00:00
|
|
|
|
2010-06-10 00:15:37 +00:00
|
|
|
$this->Task->expects($this->at(1))->method('createFile')
|
2011-10-03 01:46:35 +00:00
|
|
|
->with($file, $this->anything());
|
2009-03-13 16:06:18 +00:00
|
|
|
|
2010-06-10 00:15:37 +00:00
|
|
|
$this->Task->expects($this->at(3))->method('createFile')
|
2011-10-03 01:46:35 +00:00
|
|
|
->with($file, $this->anything());
|
2009-05-26 03:57:15 +00:00
|
|
|
|
2011-04-11 01:19:16 +00:00
|
|
|
$file = TESTS . 'Case' . DS . 'Controller' . DS . 'CommentsControllerTest.php';
|
2010-06-10 00:15:37 +00:00
|
|
|
$this->Task->expects($this->at(5))->method('createFile')
|
2011-10-03 01:46:35 +00:00
|
|
|
->with($file, $this->anything());
|
2010-06-10 00:15:37 +00:00
|
|
|
|
|
|
|
$this->Task->bake('Model', 'MyClass');
|
|
|
|
$this->Task->bake('Model', 'MyClass');
|
2009-05-26 03:57:15 +00:00
|
|
|
$this->Task->bake('Controller', 'Comments');
|
2009-02-13 14:22:11 +00:00
|
|
|
}
|
2009-07-26 09:59:51 +00:00
|
|
|
|
2009-05-24 03:48:25 +00:00
|
|
|
/**
|
2009-07-26 09:59:51 +00:00
|
|
|
* Test that method introspection pulls all relevant non parent class
|
2009-05-24 03:48:25 +00:00
|
|
|
* methods into the test case.
|
|
|
|
*
|
|
|
|
* @return void
|
2009-11-14 12:18:31 +00:00
|
|
|
*/
|
2011-05-30 20:02:32 +00:00
|
|
|
public function testMethodIntrospection() {
|
2009-05-25 03:50:21 +00:00
|
|
|
$result = $this->Task->getTestableMethods('TestTaskArticle');
|
2009-08-02 22:17:31 +00:00
|
|
|
$expected = array('dosomething', 'dosomethingelse');
|
2011-10-23 14:44:19 +00:00
|
|
|
$this->assertEquals($expected, array_map('strtolower', $result));
|
2009-05-24 05:15:31 +00:00
|
|
|
}
|
2009-07-26 09:59:51 +00:00
|
|
|
|
2009-05-24 05:15:31 +00:00
|
|
|
/**
|
|
|
|
* test that the generation of fixtures works correctly.
|
|
|
|
*
|
|
|
|
* @return void
|
2009-11-14 12:18:31 +00:00
|
|
|
*/
|
2010-09-25 04:56:46 +00:00
|
|
|
public function testFixtureArrayGenerationFromModel() {
|
2009-05-24 05:15:31 +00:00
|
|
|
$subject = ClassRegistry::init('TestTaskArticle');
|
|
|
|
$result = $this->Task->generateFixtureList($subject);
|
2009-07-26 09:59:51 +00:00
|
|
|
$expected = array('plugin.test_task.test_task_comment', 'app.articles_tags',
|
2009-05-24 05:15:31 +00:00
|
|
|
'app.test_task_article', 'app.test_task_tag');
|
|
|
|
|
2011-10-23 14:44:19 +00:00
|
|
|
$this->assertEquals(sort($expected), sort($result));
|
2009-05-24 03:48:25 +00:00
|
|
|
}
|
2009-07-26 09:59:51 +00:00
|
|
|
|
2009-05-24 05:30:04 +00:00
|
|
|
/**
|
|
|
|
* test that the generation of fixtures works correctly.
|
|
|
|
*
|
|
|
|
* @return void
|
2009-11-14 12:18:31 +00:00
|
|
|
*/
|
2010-09-25 04:56:46 +00:00
|
|
|
public function testFixtureArrayGenerationFromController() {
|
2009-05-24 05:30:04 +00:00
|
|
|
$subject = new TestTaskCommentsController();
|
|
|
|
$result = $this->Task->generateFixtureList($subject);
|
2009-07-26 09:59:51 +00:00
|
|
|
$expected = array('plugin.test_task.test_task_comment', 'app.articles_tags',
|
2009-05-24 05:30:04 +00:00
|
|
|
'app.test_task_article', 'app.test_task_tag');
|
|
|
|
|
2012-03-23 06:37:12 +00:00
|
|
|
$this->assertEquals(sort($expected), sort($result));
|
2009-05-25 00:12:17 +00:00
|
|
|
}
|
2009-07-26 09:59:51 +00:00
|
|
|
|
2009-05-25 00:12:17 +00:00
|
|
|
/**
|
|
|
|
* test user interaction to get object type
|
|
|
|
*
|
|
|
|
* @return void
|
2009-11-14 12:18:31 +00:00
|
|
|
*/
|
2010-09-25 04:56:46 +00:00
|
|
|
public function testGetObjectType() {
|
2010-06-10 00:15:37 +00:00
|
|
|
$this->Task->expects($this->once())->method('_stop');
|
|
|
|
$this->Task->expects($this->at(0))->method('in')->will($this->returnValue('q'));
|
|
|
|
$this->Task->expects($this->at(2))->method('in')->will($this->returnValue(2));
|
|
|
|
|
2009-05-25 00:12:17 +00:00
|
|
|
$this->Task->getObjectType();
|
|
|
|
|
|
|
|
$result = $this->Task->getObjectType();
|
2011-10-23 14:44:19 +00:00
|
|
|
$this->assertEquals($this->Task->classTypes['Controller'], $result);
|
2009-05-25 03:50:21 +00:00
|
|
|
}
|
2009-07-26 09:59:51 +00:00
|
|
|
|
2009-05-26 04:36:25 +00:00
|
|
|
/**
|
|
|
|
* creating test subjects should clear the registry so the registry is always fresh
|
|
|
|
*
|
|
|
|
* @return void
|
2009-11-14 12:18:31 +00:00
|
|
|
*/
|
2010-09-25 04:56:46 +00:00
|
|
|
public function testRegistryClearWhenBuildingTestObjects() {
|
2009-05-26 04:36:25 +00:00
|
|
|
ClassRegistry::flush();
|
|
|
|
$model = ClassRegistry::init('TestTaskComment');
|
|
|
|
$model->bindModel(array(
|
|
|
|
'belongsTo' => array(
|
|
|
|
'Random' => array(
|
|
|
|
'className' => 'TestTaskArticle',
|
|
|
|
'foreignKey' => 'article_id',
|
|
|
|
)
|
|
|
|
)
|
|
|
|
));
|
|
|
|
$keys = ClassRegistry::keys();
|
2010-09-08 03:51:39 +00:00
|
|
|
$this->assertTrue(in_array('test_task_comment', $keys));
|
2013-01-23 12:45:50 +00:00
|
|
|
$this->Task->buildTestSubject('Model', 'TestTaskComment');
|
2009-05-26 04:36:25 +00:00
|
|
|
|
|
|
|
$keys = ClassRegistry::keys();
|
|
|
|
$this->assertFalse(in_array('random', $keys));
|
|
|
|
}
|
2009-07-26 09:59:51 +00:00
|
|
|
|
2009-05-25 03:50:21 +00:00
|
|
|
/**
|
2013-10-23 02:59:50 +00:00
|
|
|
* test that getClassName returns the user choice as a class name.
|
2009-05-25 03:50:21 +00:00
|
|
|
*
|
|
|
|
* @return void
|
2009-11-14 12:18:31 +00:00
|
|
|
*/
|
2010-09-25 04:56:46 +00:00
|
|
|
public function testGetClassName() {
|
2009-08-08 02:45:48 +00:00
|
|
|
$objects = App::objects('model');
|
2011-05-31 00:49:46 +00:00
|
|
|
$this->skipIf(empty($objects), 'No models in app.');
|
|
|
|
|
2010-06-10 00:15:37 +00:00
|
|
|
$this->Task->expects($this->at(0))->method('in')->will($this->returnValue('MyCustomClass'));
|
|
|
|
$this->Task->expects($this->at(1))->method('in')->will($this->returnValue(1));
|
|
|
|
|
2009-05-25 03:50:21 +00:00
|
|
|
$result = $this->Task->getClassName('Model');
|
2012-03-23 06:37:12 +00:00
|
|
|
$this->assertEquals('MyCustomClass', $result);
|
2009-05-25 03:50:21 +00:00
|
|
|
|
|
|
|
$result = $this->Task->getClassName('Model');
|
2009-08-08 02:45:48 +00:00
|
|
|
$options = App::objects('model');
|
2011-10-23 14:44:19 +00:00
|
|
|
$this->assertEquals($options[0], $result);
|
2009-05-25 03:50:21 +00:00
|
|
|
}
|
2009-07-26 09:59:51 +00:00
|
|
|
|
2009-05-25 03:50:21 +00:00
|
|
|
/**
|
|
|
|
* Test the user interaction for defining additional fixtures.
|
|
|
|
*
|
|
|
|
* @return void
|
2009-11-14 12:18:31 +00:00
|
|
|
*/
|
2010-09-25 04:56:46 +00:00
|
|
|
public function testGetUserFixtures() {
|
2010-06-10 00:15:37 +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('app.pizza, app.topping, app.side_dish'));
|
|
|
|
|
2009-05-25 03:50:21 +00:00
|
|
|
$result = $this->Task->getUserFixtures();
|
|
|
|
$expected = array('app.pizza', 'app.topping', 'app.side_dish');
|
2011-10-23 14:44:19 +00:00
|
|
|
$this->assertEquals($expected, $result);
|
2009-05-25 03:50:21 +00:00
|
|
|
}
|
2009-07-26 09:59:51 +00:00
|
|
|
|
2009-05-25 03:50:21 +00:00
|
|
|
/**
|
2013-10-23 02:59:50 +00:00
|
|
|
* test that resolving class names works
|
2009-05-25 03:50:21 +00:00
|
|
|
*
|
|
|
|
* @return void
|
2009-11-14 12:18:31 +00:00
|
|
|
*/
|
2010-09-25 04:56:46 +00:00
|
|
|
public function testGetRealClassname() {
|
2009-05-25 03:50:21 +00:00
|
|
|
$result = $this->Task->getRealClassname('Model', 'Post');
|
2011-10-23 14:44:19 +00:00
|
|
|
$this->assertEquals('Post', $result);
|
2009-05-25 03:50:21 +00:00
|
|
|
|
|
|
|
$result = $this->Task->getRealClassname('Controller', 'Posts');
|
2011-10-23 14:44:19 +00:00
|
|
|
$this->assertEquals('PostsController', $result);
|
2009-05-25 03:50:21 +00:00
|
|
|
|
2011-10-03 01:46:35 +00:00
|
|
|
$result = $this->Task->getRealClassname('Controller', 'PostsController');
|
2011-10-23 14:44:19 +00:00
|
|
|
$this->assertEquals('PostsController', $result);
|
2012-03-11 04:32:02 +00:00
|
|
|
|
2012-02-28 14:58:28 +00:00
|
|
|
$result = $this->Task->getRealClassname('Controller', 'AlertTypes');
|
|
|
|
$this->assertEquals('AlertTypesController', $result);
|
2011-10-03 01:46:35 +00:00
|
|
|
|
2009-05-25 03:50:21 +00:00
|
|
|
$result = $this->Task->getRealClassname('Helper', 'Form');
|
2011-10-23 14:44:19 +00:00
|
|
|
$this->assertEquals('FormHelper', $result);
|
2009-05-25 03:50:21 +00:00
|
|
|
|
2011-10-03 01:46:35 +00:00
|
|
|
$result = $this->Task->getRealClassname('Helper', 'FormHelper');
|
2011-10-23 14:44:19 +00:00
|
|
|
$this->assertEquals('FormHelper', $result);
|
2011-10-03 01:46:35 +00:00
|
|
|
|
2009-05-25 03:50:21 +00:00
|
|
|
$result = $this->Task->getRealClassname('Behavior', 'Containable');
|
2011-10-23 14:44:19 +00:00
|
|
|
$this->assertEquals('ContainableBehavior', $result);
|
2009-05-25 03:50:21 +00:00
|
|
|
|
2011-10-03 01:46:35 +00:00
|
|
|
$result = $this->Task->getRealClassname('Behavior', 'ContainableBehavior');
|
2011-10-23 14:44:19 +00:00
|
|
|
$this->assertEquals('ContainableBehavior', $result);
|
2011-10-03 01:46:35 +00:00
|
|
|
|
2009-05-25 03:50:21 +00:00
|
|
|
$result = $this->Task->getRealClassname('Component', 'Auth');
|
2011-10-23 14:44:19 +00:00
|
|
|
$this->assertEquals('AuthComponent', $result);
|
2009-05-25 03:50:21 +00:00
|
|
|
}
|
2009-07-26 09:59:51 +00:00
|
|
|
|
2009-05-25 03:50:21 +00:00
|
|
|
/**
|
2012-12-22 22:48:15 +00:00
|
|
|
* test baking files. The conditionally run tests are known to fail in PHP4
|
2013-10-23 02:59:50 +00:00
|
|
|
* as PHP4 class names are all lower case, breaking the plugin path inflection.
|
2009-05-25 03:50:21 +00:00
|
|
|
*
|
|
|
|
* @return void
|
2009-11-14 12:18:31 +00:00
|
|
|
*/
|
2010-09-25 04:56:46 +00:00
|
|
|
public function testBakeModelTest() {
|
2010-06-10 00:15:37 +00:00
|
|
|
$this->Task->expects($this->once())->method('createFile')->will($this->returnValue(true));
|
|
|
|
$this->Task->expects($this->once())->method('isLoadableClass')->will($this->returnValue(true));
|
2009-05-25 03:50:21 +00:00
|
|
|
|
|
|
|
$result = $this->Task->bake('Model', 'TestTaskArticle');
|
|
|
|
|
2022-12-30 08:53:58 +00:00
|
|
|
$this->assertStringContainsString("App::uses('TestTaskArticle', 'Model')", $result);
|
|
|
|
$this->assertStringContainsString('class TestTaskArticleTest extends CakeTestCase', $result);
|
2009-05-25 04:54:23 +00:00
|
|
|
|
2022-12-30 08:53:58 +00:00
|
|
|
$this->assertStringContainsString('function setUp()', $result);
|
|
|
|
$this->assertStringContainsString("\$this->TestTaskArticle = ClassRegistry::init('TestTaskArticle')", $result);
|
2009-05-25 04:54:23 +00:00
|
|
|
|
2022-12-30 08:53:58 +00:00
|
|
|
$this->assertStringContainsString('function tearDown()', $result);
|
|
|
|
$this->assertStringContainsString('unset($this->TestTaskArticle)', $result);
|
2009-05-25 04:54:23 +00:00
|
|
|
|
2022-12-30 08:53:58 +00:00
|
|
|
$this->assertStringContainsString('function testDoSomething()', $result);
|
|
|
|
$this->assertStringContainsString('function testDoSomethingElse()', $result);
|
|
|
|
$this->assertStringContainsString('$this->markTestIncomplete(\'testDoSomething not implemented.\')', $result);
|
|
|
|
$this->assertStringContainsString('$this->markTestIncomplete(\'testDoSomethingElse not implemented.\')', $result);
|
2009-05-25 03:50:21 +00:00
|
|
|
|
2022-12-30 08:53:58 +00:00
|
|
|
$this->assertStringContainsString("'app.test_task_article'", $result);
|
|
|
|
$this->assertStringContainsString("'app.test_task_comment'", $result);
|
|
|
|
$this->assertStringContainsString("'app.test_task_tag'", $result);
|
|
|
|
$this->assertStringContainsString("'app.articles_tag'", $result);
|
2009-05-24 05:30:04 +00:00
|
|
|
}
|
2009-07-26 09:59:51 +00:00
|
|
|
|
2009-05-26 03:48:41 +00:00
|
|
|
/**
|
2012-05-11 18:28:01 +00:00
|
|
|
* test baking controller test files
|
2009-05-26 03:48:41 +00:00
|
|
|
*
|
|
|
|
* @return void
|
2009-11-14 12:18:31 +00:00
|
|
|
*/
|
2010-09-25 04:56:46 +00:00
|
|
|
public function testBakeControllerTest() {
|
2010-06-10 00:15:37 +00:00
|
|
|
$this->Task->expects($this->once())->method('createFile')->will($this->returnValue(true));
|
|
|
|
$this->Task->expects($this->once())->method('isLoadableClass')->will($this->returnValue(true));
|
2009-05-26 03:48:41 +00:00
|
|
|
|
|
|
|
$result = $this->Task->bake('Controller', 'TestTaskComments');
|
|
|
|
|
2022-12-30 08:53:58 +00:00
|
|
|
$this->assertStringContainsString("App::uses('TestTaskCommentsController', 'Controller')", $result);
|
|
|
|
$this->assertStringContainsString('class TestTaskCommentsControllerTest extends ControllerTestCase', $result);
|
2009-05-26 03:48:41 +00:00
|
|
|
|
2012-06-06 21:04:18 +00:00
|
|
|
$this->assertNotContains('function setUp()', $result);
|
|
|
|
$this->assertNotContains("\$this->TestTaskComments = new TestTaskCommentsController()", $result);
|
|
|
|
$this->assertNotContains("\$this->TestTaskComments->constructClasses()", $result);
|
2009-05-26 03:48:41 +00:00
|
|
|
|
2012-06-06 21:04:18 +00:00
|
|
|
$this->assertNotContains('function tearDown()', $result);
|
|
|
|
$this->assertNotContains('unset($this->TestTaskComments)', $result);
|
2009-05-26 03:48:41 +00:00
|
|
|
|
2022-12-30 08:53:58 +00:00
|
|
|
$this->assertStringContainsString("'app.test_task_article'", $result);
|
|
|
|
$this->assertStringContainsString("'app.test_task_comment'", $result);
|
|
|
|
$this->assertStringContainsString("'app.test_task_tag'", $result);
|
|
|
|
$this->assertStringContainsString("'app.articles_tag'", $result);
|
2009-05-26 03:48:41 +00:00
|
|
|
}
|
2009-07-26 09:59:51 +00:00
|
|
|
|
2012-04-29 14:44:58 +00:00
|
|
|
/**
|
|
|
|
* test baking component test files,
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function testBakeComponentTest() {
|
|
|
|
$this->Task->expects($this->once())->method('createFile')->will($this->returnValue(true));
|
|
|
|
|
|
|
|
$result = $this->Task->bake('Component', 'Example');
|
|
|
|
|
2022-12-30 08:53:58 +00:00
|
|
|
$this->assertStringContainsString("App::uses('Component', 'Controller')", $result);
|
|
|
|
$this->assertStringContainsString("App::uses('ComponentCollection', 'Controller')", $result);
|
|
|
|
$this->assertStringContainsString("App::uses('ExampleComponent', 'Controller/Component')", $result);
|
|
|
|
$this->assertStringContainsString('class ExampleComponentTest extends CakeTestCase', $result);
|
2012-04-29 14:44:58 +00:00
|
|
|
|
2022-12-30 08:53:58 +00:00
|
|
|
$this->assertStringContainsString('function setUp()', $result);
|
|
|
|
$this->assertStringContainsString("\$Collection = new ComponentCollection()", $result);
|
|
|
|
$this->assertStringContainsString("\$this->Example = new ExampleComponent(\$Collection)", $result);
|
2012-04-29 14:44:58 +00:00
|
|
|
|
2022-12-30 08:53:58 +00:00
|
|
|
$this->assertStringContainsString('function tearDown()', $result);
|
|
|
|
$this->assertStringContainsString('unset($this->Example)', $result);
|
2012-04-29 14:44:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* test baking behavior test files,
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function testBakeBehaviorTest() {
|
|
|
|
$this->Task->expects($this->once())->method('createFile')->will($this->returnValue(true));
|
|
|
|
|
|
|
|
$result = $this->Task->bake('Behavior', 'Example');
|
|
|
|
|
2022-12-30 08:53:58 +00:00
|
|
|
$this->assertStringContainsString("App::uses('ExampleBehavior', 'Model/Behavior')", $result);
|
|
|
|
$this->assertStringContainsString('class ExampleBehaviorTest extends CakeTestCase', $result);
|
2012-04-29 14:44:58 +00:00
|
|
|
|
2022-12-30 08:53:58 +00:00
|
|
|
$this->assertStringContainsString('function setUp()', $result);
|
|
|
|
$this->assertStringContainsString("\$this->Example = new ExampleBehavior()", $result);
|
2012-04-29 14:44:58 +00:00
|
|
|
|
2022-12-30 08:53:58 +00:00
|
|
|
$this->assertStringContainsString('function tearDown()', $result);
|
|
|
|
$this->assertStringContainsString('unset($this->Example)', $result);
|
2012-04-29 14:44:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* test baking helper test files,
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function testBakeHelperTest() {
|
|
|
|
$this->Task->expects($this->once())->method('createFile')->will($this->returnValue(true));
|
|
|
|
|
|
|
|
$result = $this->Task->bake('Helper', 'Example');
|
|
|
|
|
2022-12-30 08:53:58 +00:00
|
|
|
$this->assertStringContainsString("App::uses('ExampleHelper', 'View/Helper')", $result);
|
|
|
|
$this->assertStringContainsString('class ExampleHelperTest extends CakeTestCase', $result);
|
2012-04-29 14:44:58 +00:00
|
|
|
|
2022-12-30 08:53:58 +00:00
|
|
|
$this->assertStringContainsString('function setUp()', $result);
|
|
|
|
$this->assertStringContainsString("\$View = new View()", $result);
|
|
|
|
$this->assertStringContainsString("\$this->Example = new ExampleHelper(\$View)", $result);
|
2012-04-29 14:44:58 +00:00
|
|
|
|
2022-12-30 08:53:58 +00:00
|
|
|
$this->assertStringContainsString('function tearDown()', $result);
|
|
|
|
$this->assertStringContainsString('unset($this->Example)', $result);
|
2012-04-29 14:44:58 +00:00
|
|
|
}
|
|
|
|
|
2009-05-25 04:54:23 +00:00
|
|
|
/**
|
|
|
|
* test Constructor generation ensure that constructClasses is called for controllers
|
|
|
|
*
|
|
|
|
* @return void
|
2009-11-14 12:18:31 +00:00
|
|
|
*/
|
2010-09-25 04:56:46 +00:00
|
|
|
public function testGenerateConstructor() {
|
2012-05-10 22:33:10 +00:00
|
|
|
$result = $this->Task->generateConstructor('controller', 'PostsController', null);
|
2012-06-06 21:04:18 +00:00
|
|
|
$expected = array('', '', '');
|
2011-10-23 14:44:19 +00:00
|
|
|
$this->assertEquals($expected, $result);
|
2009-05-25 05:02:59 +00:00
|
|
|
|
2012-05-10 22:33:10 +00:00
|
|
|
$result = $this->Task->generateConstructor('model', 'Post', null);
|
2012-01-27 03:44:01 +00:00
|
|
|
$expected = array('', "ClassRegistry::init('Post');\n", '');
|
2011-10-23 14:44:19 +00:00
|
|
|
$this->assertEquals($expected, $result);
|
2009-05-25 05:02:59 +00:00
|
|
|
|
2012-05-10 22:33:10 +00:00
|
|
|
$result = $this->Task->generateConstructor('helper', 'FormHelper', null);
|
2012-01-27 03:44:01 +00:00
|
|
|
$expected = array("\$View = new View();\n", "new FormHelper(\$View);\n", '');
|
2011-10-23 14:44:19 +00:00
|
|
|
$this->assertEquals($expected, $result);
|
2009-05-25 04:54:23 +00:00
|
|
|
}
|
2009-07-26 09:59:51 +00:00
|
|
|
|
2012-01-27 03:50:25 +00:00
|
|
|
/**
|
|
|
|
* Test generateUses()
|
2014-04-02 01:02:37 +00:00
|
|
|
*
|
|
|
|
* @return void
|
2012-01-27 03:50:25 +00:00
|
|
|
*/
|
|
|
|
public function testGenerateUses() {
|
|
|
|
$result = $this->Task->generateUses('model', 'Model', 'Post');
|
|
|
|
$expected = array(
|
|
|
|
array('Post', 'Model')
|
|
|
|
);
|
|
|
|
$this->assertEquals($expected, $result);
|
|
|
|
|
|
|
|
$result = $this->Task->generateUses('controller', 'Controller', 'PostsController');
|
|
|
|
$expected = array(
|
|
|
|
array('PostsController', 'Controller')
|
|
|
|
);
|
|
|
|
$this->assertEquals($expected, $result);
|
|
|
|
|
|
|
|
$result = $this->Task->generateUses('helper', 'View/Helper', 'FormHelper');
|
|
|
|
$expected = array(
|
|
|
|
array('View', 'View'),
|
|
|
|
array('Helper', 'View'),
|
|
|
|
array('FormHelper', 'View/Helper'),
|
|
|
|
);
|
|
|
|
$this->assertEquals($expected, $result);
|
|
|
|
|
|
|
|
$result = $this->Task->generateUses('component', 'Controller/Component', 'AuthComponent');
|
|
|
|
$expected = array(
|
|
|
|
array('ComponentCollection', 'Controller'),
|
|
|
|
array('Component', 'Controller'),
|
|
|
|
array('AuthComponent', 'Controller/Component')
|
|
|
|
);
|
|
|
|
$this->assertEquals($expected, $result);
|
|
|
|
}
|
|
|
|
|
2009-05-26 03:48:41 +00:00
|
|
|
/**
|
|
|
|
* Test that mock class generation works for the appropriate classes
|
|
|
|
*
|
|
|
|
* @return void
|
2009-11-14 12:18:31 +00:00
|
|
|
*/
|
2010-09-25 04:56:46 +00:00
|
|
|
public function testMockClassGeneration() {
|
2009-05-26 03:48:41 +00:00
|
|
|
$result = $this->Task->hasMockClass('controller');
|
|
|
|
$this->assertTrue($result);
|
|
|
|
}
|
2009-07-26 09:59:51 +00:00
|
|
|
|
2009-06-07 01:03:26 +00:00
|
|
|
/**
|
|
|
|
* test bake() with a -plugin param
|
|
|
|
*
|
|
|
|
* @return void
|
2009-11-14 12:18:31 +00:00
|
|
|
*/
|
2010-09-25 04:56:46 +00:00
|
|
|
public function testBakeWithPlugin() {
|
2009-06-07 01:03:26 +00:00
|
|
|
$this->Task->plugin = 'TestTest';
|
|
|
|
|
2011-05-12 04:22:09 +00:00
|
|
|
//fake plugin path
|
2012-03-11 04:32:02 +00:00
|
|
|
CakePlugin::load('TestTest', array('path' => APP . 'Plugin' . DS . 'TestTest' . DS));
|
|
|
|
$path = APP . 'Plugin' . DS . 'TestTest' . DS . 'Test' . DS . 'Case' . DS . 'View' . DS . 'Helper' . DS . 'FormHelperTest.php';
|
2010-06-10 00:15:37 +00:00
|
|
|
$this->Task->expects($this->once())->method('createFile')
|
2011-10-03 01:46:35 +00:00
|
|
|
->with($path, $this->anything());
|
2010-06-10 00:15:37 +00:00
|
|
|
|
2009-06-07 01:03:26 +00:00
|
|
|
$this->Task->bake('Helper', 'Form');
|
2011-05-12 04:22:09 +00:00
|
|
|
CakePlugin::unload();
|
2009-06-07 01:03:26 +00:00
|
|
|
}
|
2009-07-26 09:59:51 +00:00
|
|
|
|
2010-12-14 03:00:37 +00:00
|
|
|
/**
|
|
|
|
* test interactive with plugins lists from the plugin
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
2011-05-30 20:02:32 +00:00
|
|
|
public function testInteractiveWithPlugin() {
|
2011-04-17 10:35:21 +00:00
|
|
|
$testApp = CAKE . 'Test' . DS . 'test_app' . DS . 'Plugin' . DS;
|
2010-12-14 03:00:37 +00:00
|
|
|
App::build(array(
|
2012-02-18 12:31:29 +00:00
|
|
|
'Plugin' => array($testApp)
|
2012-02-18 12:04:54 +00:00
|
|
|
), App::RESET);
|
2011-05-12 04:22:09 +00:00
|
|
|
CakePlugin::load('TestPlugin');
|
2010-12-14 03:00:37 +00:00
|
|
|
|
|
|
|
$this->Task->plugin = 'TestPlugin';
|
2011-10-03 16:24:40 +00:00
|
|
|
$path = $testApp . 'TestPlugin' . DS . 'Test' . DS . 'Case' . DS . 'View' . DS . 'Helper' . DS . 'OtherHelperTest.php';
|
2011-01-09 04:49:19 +00:00
|
|
|
$this->Task->expects($this->any())
|
|
|
|
->method('in')
|
|
|
|
->will($this->onConsecutiveCalls(
|
|
|
|
5, //helper
|
|
|
|
1 //OtherHelper
|
2011-04-17 10:35:21 +00:00
|
|
|
));
|
|
|
|
|
2011-01-09 04:49:19 +00:00
|
|
|
$this->Task->expects($this->once())
|
|
|
|
->method('createFile')
|
|
|
|
->with($path, $this->anything());
|
|
|
|
|
|
|
|
$this->Task->stdout->expects($this->at(21))
|
|
|
|
->method('write')
|
2011-03-07 05:27:21 +00:00
|
|
|
->with('1. OtherHelperHelper');
|
2011-04-17 10:35:21 +00:00
|
|
|
|
2010-12-14 03:00:37 +00:00
|
|
|
$this->Task->execute();
|
|
|
|
}
|
|
|
|
|
2011-10-23 15:11:07 +00:00
|
|
|
public static function caseFileNameProvider() {
|
|
|
|
return array(
|
|
|
|
array('Model', 'Post', 'Case' . DS . 'Model' . DS . 'PostTest.php'),
|
|
|
|
array('Helper', 'Form', 'Case' . DS . 'View' . DS . 'Helper' . DS . 'FormHelperTest.php'),
|
|
|
|
array('Controller', 'Posts', 'Case' . DS . 'Controller' . DS . 'PostsControllerTest.php'),
|
|
|
|
array('Behavior', 'Containable', 'Case' . DS . 'Model' . DS . 'Behavior' . DS . 'ContainableBehaviorTest.php'),
|
|
|
|
array('Component', 'Auth', 'Case' . DS . 'Controller' . DS . 'Component' . DS . 'AuthComponentTest.php'),
|
|
|
|
array('model', 'Post', 'Case' . DS . 'Model' . DS . 'PostTest.php'),
|
|
|
|
array('helper', 'Form', 'Case' . DS . 'View' . DS . 'Helper' . DS . 'FormHelperTest.php'),
|
|
|
|
array('controller', 'Posts', 'Case' . DS . 'Controller' . DS . 'PostsControllerTest.php'),
|
|
|
|
array('behavior', 'Containable', 'Case' . DS . 'Model' . DS . 'Behavior' . DS . 'ContainableBehaviorTest.php'),
|
|
|
|
array('component', 'Auth', 'Case' . DS . 'Controller' . DS . 'Component' . DS . 'AuthComponentTest.php'),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2009-06-07 01:09:56 +00:00
|
|
|
/**
|
|
|
|
* Test filename generation for each type + plugins
|
|
|
|
*
|
2011-10-23 15:11:07 +00:00
|
|
|
* @dataProvider caseFileNameProvider
|
2009-06-07 01:09:56 +00:00
|
|
|
* @return void
|
2009-11-14 12:18:31 +00:00
|
|
|
*/
|
2011-10-23 15:11:07 +00:00
|
|
|
public function testTestCaseFileName($type, $class, $expected) {
|
2011-06-21 15:54:59 +00:00
|
|
|
$this->Task->path = DS . 'my' . DS . 'path' . DS . 'tests' . DS;
|
2009-06-07 01:09:56 +00:00
|
|
|
|
2011-10-23 15:11:07 +00:00
|
|
|
$result = $this->Task->testCaseFileName($type, $class);
|
|
|
|
$expected = $this->Task->path . $expected;
|
2011-10-23 14:44:19 +00:00
|
|
|
$this->assertEquals($expected, $result);
|
2011-10-23 15:11:07 +00:00
|
|
|
}
|
2009-06-07 01:09:56 +00:00
|
|
|
|
2011-10-23 15:11:07 +00:00
|
|
|
/**
|
|
|
|
* Test filename generation for plugins.
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function testTestCaseFileNamePlugin() {
|
|
|
|
$this->Task->path = DS . 'my' . DS . 'path' . DS . 'tests' . DS;
|
2009-06-07 01:09:56 +00:00
|
|
|
|
2012-09-28 11:49:51 +00:00
|
|
|
CakePlugin::load('TestTest', array('path' => APP . 'Plugin' . DS . 'TestTest' . DS));
|
2009-06-07 01:09:56 +00:00
|
|
|
$this->Task->plugin = 'TestTest';
|
|
|
|
$result = $this->Task->testCaseFileName('Model', 'Post');
|
2012-03-11 04:32:02 +00:00
|
|
|
$expected = APP . 'Plugin' . DS . 'TestTest' . DS . 'Test' . DS . 'Case' . DS . 'Model' . DS . 'PostTest.php';
|
2011-10-23 14:44:19 +00:00
|
|
|
$this->assertEquals($expected, $result);
|
2009-06-07 01:09:56 +00:00
|
|
|
}
|
2009-07-26 09:59:51 +00:00
|
|
|
|
2009-05-30 04:14:57 +00:00
|
|
|
/**
|
|
|
|
* test execute with a type defined
|
|
|
|
*
|
|
|
|
* @return void
|
2009-11-14 12:18:31 +00:00
|
|
|
*/
|
2010-09-25 04:56:46 +00:00
|
|
|
public function testExecuteWithOneArg() {
|
2009-05-30 04:14:57 +00:00
|
|
|
$this->Task->args[0] = 'Model';
|
2010-06-10 00:15:37 +00:00
|
|
|
$this->Task->expects($this->at(0))->method('in')->will($this->returnValue('TestTaskTag'));
|
|
|
|
$this->Task->expects($this->once())->method('isLoadableClass')->will($this->returnValue(true));
|
|
|
|
$this->Task->expects($this->once())->method('createFile')
|
|
|
|
->with(
|
2011-10-03 01:46:35 +00:00
|
|
|
$this->anything(),
|
2012-04-21 13:02:35 +00:00
|
|
|
$this->stringContains('class TestTaskTagTest extends CakeTestCase')
|
2010-06-10 00:15:37 +00:00
|
|
|
);
|
2009-05-30 04:14:57 +00:00
|
|
|
$this->Task->execute();
|
|
|
|
}
|
2009-07-26 09:59:51 +00:00
|
|
|
|
2009-05-30 04:14:57 +00:00
|
|
|
/**
|
|
|
|
* test execute with type and class name defined
|
|
|
|
*
|
|
|
|
* @return void
|
2009-11-14 12:18:31 +00:00
|
|
|
*/
|
2010-09-25 04:56:46 +00:00
|
|
|
public function testExecuteWithTwoArgs() {
|
2009-05-30 04:14:57 +00:00
|
|
|
$this->Task->args = array('Model', 'TestTaskTag');
|
2010-06-10 00:15:37 +00:00
|
|
|
$this->Task->expects($this->at(0))->method('in')->will($this->returnValue('TestTaskTag'));
|
|
|
|
$this->Task->expects($this->once())->method('createFile')
|
|
|
|
->with(
|
2011-10-03 01:46:35 +00:00
|
|
|
$this->anything(),
|
2012-04-21 13:02:35 +00:00
|
|
|
$this->stringContains('class TestTaskTagTest extends CakeTestCase')
|
2011-10-23 15:11:07 +00:00
|
|
|
);
|
|
|
|
$this->Task->expects($this->any())->method('isLoadableClass')->will($this->returnValue(true));
|
|
|
|
$this->Task->execute();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* test execute with type and class name defined and lower case.
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function testExecuteWithTwoArgsLowerCase() {
|
|
|
|
$this->Task->args = array('model', 'TestTaskTag');
|
|
|
|
$this->Task->expects($this->at(0))->method('in')->will($this->returnValue('TestTaskTag'));
|
|
|
|
$this->Task->expects($this->once())->method('createFile')
|
|
|
|
->with(
|
|
|
|
$this->anything(),
|
2012-04-21 13:02:35 +00:00
|
|
|
$this->stringContains('class TestTaskTagTest extends CakeTestCase')
|
2010-06-10 00:15:37 +00:00
|
|
|
);
|
|
|
|
$this->Task->expects($this->any())->method('isLoadableClass')->will($this->returnValue(true));
|
2009-05-30 04:14:57 +00:00
|
|
|
$this->Task->execute();
|
|
|
|
}
|
2011-10-03 01:46:35 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Data provider for mapType() tests.
|
|
|
|
*
|
|
|
|
* @return array
|
|
|
|
*/
|
|
|
|
public static function mapTypeProvider() {
|
|
|
|
return array(
|
|
|
|
array('controller', null, 'Controller'),
|
|
|
|
array('Controller', null, 'Controller'),
|
|
|
|
array('component', null, 'Controller/Component'),
|
|
|
|
array('Component', null, 'Controller/Component'),
|
|
|
|
array('model', null, 'Model'),
|
|
|
|
array('Model', null, 'Model'),
|
|
|
|
array('behavior', null, 'Model/Behavior'),
|
|
|
|
array('Behavior', null, 'Model/Behavior'),
|
|
|
|
array('helper', null, 'View/Helper'),
|
|
|
|
array('Helper', null, 'View/Helper'),
|
|
|
|
array('Helper', 'DebugKit', 'DebugKit.View/Helper'),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Test that mapType returns the correct package names.
|
|
|
|
*
|
|
|
|
* @dataProvider mapTypeProvider
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function testMapType($original, $plugin, $expected) {
|
|
|
|
$this->assertEquals($expected, $this->Task->mapType($original, $plugin));
|
|
|
|
}
|
2009-02-13 14:22:11 +00:00
|
|
|
}
|