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
|
|
|
*
|
2010-10-03 16:31:21 +00:00
|
|
|
* PHP 5
|
2009-02-13 14:22:11 +00:00
|
|
|
*
|
2010-01-26 22:15:15 +00:00
|
|
|
* CakePHP : Rapid Development Framework (http://cakephp.org)
|
2011-05-29 21:31:39 +00:00
|
|
|
* Copyright 2005-2011, Cake Software Foundation, Inc.
|
2009-02-13 14:22:11 +00:00
|
|
|
*
|
|
|
|
* Licensed under The MIT License
|
|
|
|
* Redistributions of files must retain the above copyright notice.
|
|
|
|
*
|
2011-05-29 21:31:39 +00:00
|
|
|
* @copyright Copyright 2005-2011, Cake Software Foundation, Inc.
|
2009-11-06 06:00:11 +00:00
|
|
|
* @link http://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
|
2009-11-06 06:51:51 +00:00
|
|
|
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
|
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
|
|
|
|
* @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
|
|
|
|
|
|
|
/**
|
|
|
|
* Model name
|
|
|
|
*
|
|
|
|
* @var string
|
|
|
|
* @access public
|
|
|
|
*/
|
2010-04-04 07:14:00 +00:00
|
|
|
public $name = 'TestTaskArticle';
|
2009-11-14 12:18:31 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Table name to use
|
|
|
|
*
|
|
|
|
* @var string
|
|
|
|
* @access public
|
|
|
|
*/
|
2010-04-04 07:14:00 +00:00
|
|
|
public $useTable = 'articles';
|
2009-11-14 12:18:31 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* HasMany Associations
|
|
|
|
*
|
|
|
|
* @var array
|
|
|
|
* @access public
|
|
|
|
*/
|
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
|
|
|
|
* @access public
|
|
|
|
*/
|
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
|
|
|
}
|
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
|
|
|
|
* @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
|
|
|
|
|
|
|
/**
|
|
|
|
* Model name
|
|
|
|
*
|
|
|
|
* @var string
|
|
|
|
* @access public
|
|
|
|
*/
|
2010-04-04 07:14:00 +00:00
|
|
|
public $name = 'TestTaskTag';
|
2009-11-14 12:18:31 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Table name
|
|
|
|
*
|
|
|
|
* @var string
|
|
|
|
* @access public
|
|
|
|
*/
|
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
|
|
|
|
* @access public
|
|
|
|
*/
|
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
|
|
|
|
* @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
|
|
|
|
* @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
|
|
|
|
|
|
|
/**
|
|
|
|
* Model name
|
|
|
|
*
|
|
|
|
* @var string
|
|
|
|
* @access public
|
|
|
|
*/
|
2010-04-04 07:14:00 +00:00
|
|
|
public $name = 'TestTaskComment';
|
2009-11-14 12:18:31 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Table name
|
|
|
|
*
|
|
|
|
* @var string
|
|
|
|
* @access public
|
|
|
|
*/
|
2010-04-04 07:14:00 +00:00
|
|
|
public $useTable = 'comments';
|
2009-11-14 12:18:31 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Belongs To Associations
|
|
|
|
*
|
|
|
|
* @var array
|
|
|
|
* @access public
|
|
|
|
*/
|
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
|
|
|
|
* @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
|
|
|
|
|
|
|
/**
|
|
|
|
* Controller Name
|
|
|
|
*
|
|
|
|
* @var string
|
|
|
|
* @access public
|
|
|
|
*/
|
2010-04-04 07:14:00 +00:00
|
|
|
public $name = 'TestTaskComments';
|
2009-11-14 12:18:31 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Models to use
|
|
|
|
*
|
|
|
|
* @var array
|
|
|
|
* @access public
|
|
|
|
*/
|
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
|
|
|
|
* @access public
|
|
|
|
*/
|
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
|
|
|
/**
|
2010-09-25 04:47:32 +00:00
|
|
|
* setup method
|
2009-03-13 16:06:18 +00:00
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
2010-09-25 04:47:32 +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);
|
|
|
|
|
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
|
|
|
/**
|
2009-07-17 03:55:41 +00:00
|
|
|
* endTest method
|
2009-03-13 16:06:18 +00:00
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
2010-10-07 02:52:42 +00:00
|
|
|
public function tearDown() {
|
|
|
|
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')
|
|
|
|
->with($file, new PHPUnit_Framework_Constraint_IsAnything());
|
2009-03-13 16:06:18 +00:00
|
|
|
|
2010-06-10 00:15:37 +00:00
|
|
|
$this->Task->expects($this->at(3))->method('createFile')
|
|
|
|
->with($file, new PHPUnit_Framework_Constraint_IsAnything());
|
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')
|
|
|
|
->with($file, new PHPUnit_Framework_Constraint_IsAnything());
|
|
|
|
|
|
|
|
$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');
|
|
|
|
$this->assertEqual(array_map('strtolower', $result), $expected);
|
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');
|
|
|
|
|
|
|
|
$this->assertEqual(sort($result), sort($expected));
|
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');
|
|
|
|
|
|
|
|
$this->assertEqual(sort($result), sort($expected));
|
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-04-11 01:19:16 +00:00
|
|
|
$this->assertEqual($result, $this->Task->classTypes['Controller']);
|
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));
|
2010-11-13 04:22:48 +00:00
|
|
|
$object = $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
|
|
|
/**
|
|
|
|
* test that getClassName returns the user choice as a classname.
|
|
|
|
*
|
|
|
|
* @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');
|
|
|
|
$this->assertEqual($result, 'MyCustomClass');
|
|
|
|
|
|
|
|
$result = $this->Task->getClassName('Model');
|
2009-08-08 02:45:48 +00:00
|
|
|
$options = App::objects('model');
|
2009-05-25 03:50:21 +00:00
|
|
|
$this->assertEqual($result, $options[0]);
|
|
|
|
}
|
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-05-16 22:49:00 +00:00
|
|
|
$this->assertEqual($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
|
|
|
/**
|
|
|
|
* test that resolving classnames works
|
|
|
|
*
|
|
|
|
* @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');
|
|
|
|
$this->assertEqual($result, 'Post');
|
|
|
|
|
|
|
|
$result = $this->Task->getRealClassname('Controller', 'Posts');
|
|
|
|
$this->assertEqual($result, 'PostsController');
|
|
|
|
|
|
|
|
$result = $this->Task->getRealClassname('Helper', 'Form');
|
|
|
|
$this->assertEqual($result, 'FormHelper');
|
|
|
|
|
|
|
|
$result = $this->Task->getRealClassname('Behavior', 'Containable');
|
|
|
|
$this->assertEqual($result, 'ContainableBehavior');
|
|
|
|
|
|
|
|
$result = $this->Task->getRealClassname('Component', 'Auth');
|
|
|
|
$this->assertEqual($result, 'AuthComponent');
|
|
|
|
}
|
2009-07-26 09:59:51 +00:00
|
|
|
|
2009-05-25 03:50:21 +00:00
|
|
|
/**
|
2009-08-02 22:17:31 +00:00
|
|
|
* test baking files. The conditionally run tests are known to fail in PHP4
|
|
|
|
* as PHP4 classnames 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');
|
|
|
|
|
2011-03-16 02:59:18 +00:00
|
|
|
$this->assertContains("App::uses('TestTaskArticle', 'Model')", $result);
|
2010-09-25 04:56:46 +00:00
|
|
|
$this->assertContains('class TestTaskArticleTestCase extends CakeTestCase', $result);
|
2009-05-25 04:54:23 +00:00
|
|
|
|
2011-02-05 06:40:14 +00:00
|
|
|
$this->assertContains('function setUp()', $result);
|
2010-11-13 04:22:48 +00:00
|
|
|
$this->assertContains("\$this->TestTaskArticle = ClassRegistry::init('TestTaskArticle')", $result);
|
2009-05-25 04:54:23 +00:00
|
|
|
|
2011-02-05 06:40:14 +00:00
|
|
|
$this->assertContains('function tearDown()', $result);
|
2010-09-25 04:56:46 +00:00
|
|
|
$this->assertContains('unset($this->TestTaskArticle)', $result);
|
2009-05-25 04:54:23 +00:00
|
|
|
|
2010-09-25 04:56:46 +00:00
|
|
|
$this->assertContains('function testDoSomething()', $result);
|
|
|
|
$this->assertContains('function testDoSomethingElse()', $result);
|
2009-05-25 03:50:21 +00:00
|
|
|
|
2010-09-25 04:56:46 +00:00
|
|
|
$this->assertContains("'app.test_task_article'", $result);
|
|
|
|
$this->assertContains("'plugin.test_task.test_task_comment'", $result);
|
|
|
|
$this->assertContains("'app.test_task_tag'", $result);
|
|
|
|
$this->assertContains("'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
|
|
|
/**
|
|
|
|
* test baking controller test files, ensure that the stub class is generated.
|
2009-08-02 22:17:31 +00:00
|
|
|
* Conditional assertion is known to fail on PHP4 as classnames are all lower case
|
|
|
|
* causing issues with inflection of path name from classname.
|
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');
|
|
|
|
|
2011-03-16 02:59:18 +00:00
|
|
|
$this->assertContains("App::uses('TestTaskCommentsController', 'Controller')", $result);
|
2010-09-25 04:56:46 +00:00
|
|
|
$this->assertContains('class TestTaskCommentsControllerTestCase extends CakeTestCase', $result);
|
2009-05-26 03:48:41 +00:00
|
|
|
|
2010-09-25 04:56:46 +00:00
|
|
|
$this->assertContains('class TestTestTaskCommentsController extends TestTaskCommentsController', $result);
|
|
|
|
$this->assertContains('public $autoRender = false', $result);
|
|
|
|
$this->assertContains('function redirect($url, $status = null, $exit = true)', $result);
|
2009-05-26 03:48:41 +00:00
|
|
|
|
2011-02-05 06:40:14 +00:00
|
|
|
$this->assertContains('function setUp()', $result);
|
2010-11-13 04:05:44 +00:00
|
|
|
$this->assertContains("\$this->TestTaskComments = new TestTestTaskCommentsController()", $result);
|
2010-09-25 04:56:46 +00:00
|
|
|
$this->assertContains("\$this->TestTaskComments->constructClasses()", $result);
|
2009-05-26 03:48:41 +00:00
|
|
|
|
2011-02-05 06:40:14 +00:00
|
|
|
$this->assertContains('function tearDown()', $result);
|
2010-09-25 04:56:46 +00:00
|
|
|
$this->assertContains('unset($this->TestTaskComments)', $result);
|
2009-05-26 03:48:41 +00:00
|
|
|
|
2010-09-25 04:56:46 +00:00
|
|
|
$this->assertContains("'app.test_task_article'", $result);
|
|
|
|
$this->assertContains("'plugin.test_task.test_task_comment'", $result);
|
|
|
|
$this->assertContains("'app.test_task_tag'", $result);
|
|
|
|
$this->assertContains("'app.articles_tag'", $result);
|
2009-05-26 03:48:41 +00:00
|
|
|
}
|
2009-07-26 09:59:51 +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() {
|
2009-05-25 04:54:23 +00:00
|
|
|
$result = $this->Task->generateConstructor('controller', 'PostsController');
|
2009-08-06 00:45:54 +00:00
|
|
|
$expected = "new TestPostsController();\n\t\t\$this->Posts->constructClasses();\n";
|
2011-05-16 22:49:00 +00:00
|
|
|
$this->assertEqual($expected, $result);
|
2009-05-25 05:02:59 +00:00
|
|
|
|
|
|
|
$result = $this->Task->generateConstructor('model', 'Post');
|
|
|
|
$expected = "ClassRegistry::init('Post');\n";
|
2011-05-16 22:49:00 +00:00
|
|
|
$this->assertEqual($expected, $result);
|
2009-05-25 05:02:59 +00:00
|
|
|
|
|
|
|
$result = $this->Task->generateConstructor('helper', 'FormHelper');
|
2010-02-13 19:42:16 +00:00
|
|
|
$expected = "new FormHelper();\n";
|
2011-05-16 22:49:00 +00:00
|
|
|
$this->assertEqual($expected, $result);
|
2009-05-25 04:54:23 +00:00
|
|
|
}
|
2009-07-26 09:59:51 +00:00
|
|
|
|
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
|
2011-05-13 07:53:53 +00:00
|
|
|
CakePlugin::load('TestTest', array('path' => APP . 'Plugin' . DS . 'TestTest' . DS));
|
2011-05-29 17:42:13 +00:00
|
|
|
$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')
|
|
|
|
->with($path, new PHPUnit_Framework_Constraint_IsAnything());
|
|
|
|
|
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(
|
|
|
|
'plugins' => array($testApp)
|
|
|
|
), true);
|
2011-05-12 04:22:09 +00:00
|
|
|
CakePlugin::load('TestPlugin');
|
2010-12-14 03:00:37 +00:00
|
|
|
|
|
|
|
$this->Task->plugin = 'TestPlugin';
|
2011-05-29 17:42:13 +00:00
|
|
|
$path = $testApp . 'TestPlugin' . DS . 'Test' . DS . 'Case' . DS . 'View' . DS . 'Helper' . DS . 'OtherHelperHelperTest.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();
|
|
|
|
}
|
|
|
|
|
2009-06-07 01:09:56 +00:00
|
|
|
/**
|
|
|
|
* Test filename generation for each type + plugins
|
|
|
|
*
|
|
|
|
* @return void
|
2009-11-14 12:18:31 +00:00
|
|
|
*/
|
2010-09-25 04:56:46 +00:00
|
|
|
public function testTestCaseFileName() {
|
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
|
|
|
|
|
|
|
$result = $this->Task->testCaseFileName('Model', 'Post');
|
2011-04-11 01:19:16 +00:00
|
|
|
$expected = $this->Task->path . 'Case' . DS . 'Model' . DS . 'PostTest.php';
|
2011-05-16 22:49:00 +00:00
|
|
|
$this->assertEqual($expected, $result);
|
2009-06-07 01:09:56 +00:00
|
|
|
|
|
|
|
$result = $this->Task->testCaseFileName('Helper', 'Form');
|
2011-04-11 01:19:16 +00:00
|
|
|
$expected = $this->Task->path . 'Case' . DS . 'View' . DS . 'Helper' . DS . 'FormHelperTest.php';
|
2011-05-16 22:49:00 +00:00
|
|
|
$this->assertEqual($expected, $result);
|
2009-06-07 01:09:56 +00:00
|
|
|
|
|
|
|
$result = $this->Task->testCaseFileName('Controller', 'Posts');
|
2011-04-11 01:19:16 +00:00
|
|
|
$expected = $this->Task->path . 'Case' . DS . 'Controller' . DS . 'PostsControllerTest.php';
|
2011-05-16 22:49:00 +00:00
|
|
|
$this->assertEqual($expected, $result);
|
2009-06-07 01:09:56 +00:00
|
|
|
|
|
|
|
$result = $this->Task->testCaseFileName('Behavior', 'Containable');
|
2011-04-11 01:19:16 +00:00
|
|
|
$expected = $this->Task->path . 'Case' . DS . 'Model' . DS . 'Behavior' . DS . 'ContainableBehaviorTest.php';
|
2011-05-16 22:49:00 +00:00
|
|
|
$this->assertEqual($expected, $result);
|
2009-06-07 01:09:56 +00:00
|
|
|
|
|
|
|
$result = $this->Task->testCaseFileName('Component', 'Auth');
|
2011-04-11 01:19:16 +00:00
|
|
|
$expected = $this->Task->path . 'Case' . DS . 'Controller' . DS . 'Component' . DS . 'AuthComponentTest.php';
|
2011-05-16 22:49:00 +00:00
|
|
|
$this->assertEqual($expected, $result);
|
2009-06-07 01:09:56 +00:00
|
|
|
|
2011-05-13 07:53:53 +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');
|
2011-05-29 17:42:13 +00:00
|
|
|
$expected = APP . 'Plugin' . DS . 'TestTest' . DS . 'Test' . DS . 'Case' . DS . 'Model' . DS . 'PostTest.php';
|
2011-05-16 22:49:00 +00:00
|
|
|
$this->assertEqual($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(
|
|
|
|
new PHPUnit_Framework_Constraint_IsAnything(),
|
|
|
|
new PHPUnit_Framework_Constraint_PCREMatch('/class TestTaskTagTestCase extends CakeTestCase/')
|
|
|
|
);
|
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(
|
|
|
|
new PHPUnit_Framework_Constraint_IsAnything(),
|
|
|
|
new PHPUnit_Framework_Constraint_PCREMatch('/class TestTaskTagTestCase extends CakeTestCase/')
|
|
|
|
);
|
|
|
|
$this->Task->expects($this->any())->method('isLoadableClass')->will($this->returnValue(true));
|
2009-05-30 04:14:57 +00:00
|
|
|
$this->Task->execute();
|
|
|
|
}
|
2009-02-13 14:22:11 +00:00
|
|
|
}
|