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)
|
2010-01-14 04:47:14 +00:00
|
|
|
* Copyright 2006-2010, 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.
|
|
|
|
*
|
2010-01-14 04:47:14 +00:00
|
|
|
* @copyright Copyright 2006-2010, Cake Software Foundation, Inc.
|
2009-11-06 06:00:11 +00:00
|
|
|
* @link http://cakephp.org CakePHP Project
|
2009-03-19 21:10:13 +00:00
|
|
|
* @package cake
|
2009-03-13 16:06:18 +00:00
|
|
|
* @subpackage cake.tests.cases.console.libs.tasks
|
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
|
|
|
*/
|
2009-07-26 01:27:02 +00:00
|
|
|
App::import('Shell', 'Shell', false);
|
|
|
|
App::import('Controller', 'Controller', false);
|
|
|
|
App::import('Model', 'Model', false);
|
2009-02-13 14:22:11 +00:00
|
|
|
|
2010-10-03 05:53:42 +00:00
|
|
|
require_once CAKE . 'console' . DS . 'shell_dispatcher.php';
|
2010-01-17 00:41:52 +00:00
|
|
|
require_once CAKE . 'console' . DS . 'libs' . DS . 'tasks' . DS . 'test.php';
|
|
|
|
require_once CAKE . 'console' . DS . 'libs' . DS . 'tasks' . DS . 'template.php';
|
|
|
|
|
2009-05-24 05:15:31 +00:00
|
|
|
/**
|
2009-11-14 12:18:31 +00:00
|
|
|
* Test Article model
|
|
|
|
*
|
|
|
|
* @package cake
|
|
|
|
* @subpackage cake.tests.cases.console.libs.tasks
|
|
|
|
*/
|
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
|
|
|
|
*
|
|
|
|
* @package cake
|
|
|
|
* @subpackage cake.tests.cases.console.libs.tasks
|
|
|
|
*/
|
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
|
|
|
|
*
|
|
|
|
* @package cake
|
|
|
|
* @subpackage cake.tests.cases.console.libs.tasks
|
|
|
|
*/
|
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)
|
|
|
|
*
|
|
|
|
* @package cake
|
|
|
|
* @subpackage cake.tests.cases.console.libs.tasks
|
|
|
|
*/
|
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
|
|
|
|
*
|
|
|
|
* @package cake
|
|
|
|
* @subpackage cake.tests.cases.console.libs.tasks
|
|
|
|
*/
|
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
|
|
|
|
*
|
2009-03-19 21:10:13 +00:00
|
|
|
* @package cake
|
2009-03-13 16:06:18 +00:00
|
|
|
* @subpackage cake.tests.cases.console.libs.tasks
|
|
|
|
*/
|
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);
|
|
|
|
|
|
|
|
$this->Dispatcher = $this->getMock('ShellDispatcher', array('_stop', '_initEnvironment'));
|
2010-06-10 00:15:37 +00:00
|
|
|
$this->Task = $this->getMock('TestTask',
|
|
|
|
array('in', 'err', 'createFile', '_stop', 'isLoadableClass'),
|
2010-10-07 02:52:42 +00:00
|
|
|
array(&$this->Dispatcher, $out, $out, $in)
|
2010-06-10 00:15:37 +00:00
|
|
|
);
|
2009-07-07 03:11:57 +00:00
|
|
|
$this->Dispatcher->shellPaths = App::path('shells');
|
2010-03-05 02:57:48 +00:00
|
|
|
$this->Task->name = 'TestTask';
|
2010-10-07 02:52:42 +00:00
|
|
|
$this->Task->Template = new TemplateTask($this->Dispatcher, $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();
|
|
|
|
unset($this->Task, $this->Dispatcher);
|
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-09-25 04:47:32 +00:00
|
|
|
$this->Dispatcher->expects($this->never())->method('stderr');
|
|
|
|
$this->Dispatcher->expects($this->never())->method('_stop');
|
2009-02-13 14:22:11 +00:00
|
|
|
|
2010-06-10 00:15:37 +00:00
|
|
|
$file = TESTS . 'cases' . DS . 'models' . DS . 'my_class.test.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
|
|
|
|
|
|
|
$file = TESTS . 'cases' . DS . 'controllers' . DS . 'comments_controller.test.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
|
|
|
*/
|
2010-09-25 04:56:46 +00:00
|
|
|
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();
|
2009-05-25 03:50:21 +00:00
|
|
|
$this->assertEqual($result, $this->Task->classTypes[1]);
|
|
|
|
}
|
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));
|
2009-05-26 04:36:25 +00:00
|
|
|
$object =& $this->Task->buildTestSubject('Model', 'TestTaskComment');
|
|
|
|
|
|
|
|
$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');
|
2009-07-01 01:22:10 +00:00
|
|
|
$skip = $this->skipIf(empty($objects), 'No models in app, this test will fail. %s');
|
|
|
|
if ($skip) {
|
|
|
|
return;
|
|
|
|
}
|
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');
|
|
|
|
$this->assertEqual($result, $expected);
|
|
|
|
}
|
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');
|
|
|
|
|
2010-09-25 04:56:46 +00:00
|
|
|
$this->assertContains("App::import('Model', 'TestTaskArticle')", $result);
|
|
|
|
$this->assertContains('class TestTaskArticleTestCase extends CakeTestCase', $result);
|
2009-05-25 04:54:23 +00:00
|
|
|
|
2010-09-25 04:56:46 +00:00
|
|
|
$this->assertContains('function startTest()', $result);
|
|
|
|
$this->assertContains("\$this->TestTaskArticle =& ClassRegistry::init('TestTaskArticle')", $result);
|
2009-05-25 04:54:23 +00:00
|
|
|
|
2010-09-25 04:56:46 +00:00
|
|
|
$this->assertContains('function endTest()', $result);
|
|
|
|
$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');
|
|
|
|
|
2010-09-25 04:56:46 +00:00
|
|
|
$this->assertContains("App::import('Controller', 'TestTaskComments')", $result);
|
|
|
|
$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
|
|
|
|
2010-09-25 04:56:46 +00:00
|
|
|
$this->assertContains('function startTest()', $result);
|
|
|
|
$this->assertContains("\$this->TestTaskComments =& new TestTestTaskCommentsController()", $result);
|
|
|
|
$this->assertContains("\$this->TestTaskComments->constructClasses()", $result);
|
2009-05-26 03:48:41 +00:00
|
|
|
|
2010-09-25 04:56:46 +00:00
|
|
|
$this->assertContains('function endTest()', $result);
|
|
|
|
$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";
|
2009-05-25 05:02:59 +00:00
|
|
|
$this->assertEqual($result, $expected);
|
|
|
|
|
|
|
|
$result = $this->Task->generateConstructor('model', 'Post');
|
|
|
|
$expected = "ClassRegistry::init('Post');\n";
|
|
|
|
$this->assertEqual($result, $expected);
|
|
|
|
|
|
|
|
$result = $this->Task->generateConstructor('helper', 'FormHelper');
|
2010-02-13 19:42:16 +00:00
|
|
|
$expected = "new FormHelper();\n";
|
2009-05-25 04:54:23 +00:00
|
|
|
$this->assertEqual($result, $expected);
|
|
|
|
}
|
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';
|
|
|
|
|
|
|
|
$path = APP . 'plugins' . DS . 'test_test' . DS . 'tests' . DS . 'cases' . DS . 'helpers' . DS . 'form.test.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');
|
|
|
|
}
|
2009-07-26 09:59:51 +00:00
|
|
|
|
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() {
|
2009-06-07 01:09:56 +00:00
|
|
|
$this->Task->path = '/my/path/tests/';
|
|
|
|
|
|
|
|
$result = $this->Task->testCaseFileName('Model', 'Post');
|
|
|
|
$expected = $this->Task->path . 'cases' . DS . 'models' . DS . 'post.test.php';
|
|
|
|
$this->assertEqual($result, $expected);
|
|
|
|
|
|
|
|
$result = $this->Task->testCaseFileName('Helper', 'Form');
|
|
|
|
$expected = $this->Task->path . 'cases' . DS . 'helpers' . DS . 'form.test.php';
|
|
|
|
$this->assertEqual($result, $expected);
|
|
|
|
|
|
|
|
$result = $this->Task->testCaseFileName('Controller', 'Posts');
|
|
|
|
$expected = $this->Task->path . 'cases' . DS . 'controllers' . DS . 'posts_controller.test.php';
|
|
|
|
$this->assertEqual($result, $expected);
|
|
|
|
|
|
|
|
$result = $this->Task->testCaseFileName('Behavior', 'Containable');
|
|
|
|
$expected = $this->Task->path . 'cases' . DS . 'behaviors' . DS . 'containable.test.php';
|
|
|
|
$this->assertEqual($result, $expected);
|
|
|
|
|
|
|
|
$result = $this->Task->testCaseFileName('Component', 'Auth');
|
|
|
|
$expected = $this->Task->path . 'cases' . DS . 'components' . DS . 'auth.test.php';
|
|
|
|
$this->assertEqual($result, $expected);
|
|
|
|
|
|
|
|
$this->Task->plugin = 'TestTest';
|
|
|
|
$result = $this->Task->testCaseFileName('Model', 'Post');
|
|
|
|
$expected = APP . 'plugins' . DS . 'test_test' . DS . 'tests' . DS . 'cases' . DS . 'models' . DS . 'post.test.php';
|
|
|
|
$this->assertEqual($result, $expected);
|
|
|
|
}
|
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
|
|
|
}
|