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
|
|
|
*
|
|
|
|
* PHP versions 4 and 5
|
|
|
|
*
|
2009-11-06 06:46:59 +00:00
|
|
|
* CakePHP : Rapid Development Framework (http://cakephp.org)
|
2009-07-17 03:55:41 +00:00
|
|
|
* Copyright 2006-2009, 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.
|
|
|
|
*
|
2009-07-17 03:55:41 +00:00
|
|
|
* @copyright Copyright 2006-2009, 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
|
|
|
|
|
|
|
if (!defined('DISABLE_AUTO_DISPATCH')) {
|
|
|
|
define('DISABLE_AUTO_DISPATCH', true);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!class_exists('ShellDispatcher')) {
|
|
|
|
ob_start();
|
|
|
|
$argv = false;
|
|
|
|
require CAKE . 'console' . DS . 'cake.php';
|
|
|
|
ob_end_clean();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!class_exists('TestTask')) {
|
|
|
|
require CAKE . 'console' . DS . 'libs' . DS . 'tasks' . DS . 'test.php';
|
2009-05-25 03:50:21 +00:00
|
|
|
require CAKE . 'console' . DS . 'libs' . DS . 'tasks' . DS . 'template.php';
|
2009-02-13 14:22:11 +00:00
|
|
|
}
|
|
|
|
|
2009-03-13 16:06:18 +00:00
|
|
|
Mock::generatePartial(
|
2009-05-24 03:48:25 +00:00
|
|
|
'ShellDispatcher', 'TestTestTaskMockShellDispatcher',
|
|
|
|
array('getInput', 'stdout', 'stderr', '_stop', '_initEnvironment')
|
|
|
|
);
|
2009-03-13 16:06:18 +00:00
|
|
|
Mock::generatePartial(
|
2009-05-24 03:48:25 +00:00
|
|
|
'TestTask', 'MockTestTask',
|
2009-05-25 03:50:21 +00:00
|
|
|
array('in', '_stop', 'err', 'out', 'createFile', 'isLoadableClass')
|
2009-05-24 03:48:25 +00:00
|
|
|
);
|
2009-05-24 05:30:04 +00:00
|
|
|
|
2009-05-24 05:15:31 +00:00
|
|
|
/**
|
|
|
|
* Test subject models for fixture generation
|
|
|
|
**/
|
|
|
|
class TestTaskArticle extends Model {
|
|
|
|
var $name = 'TestTaskArticle';
|
|
|
|
var $useTable = 'articles';
|
|
|
|
var $hasMany = array(
|
|
|
|
'Comment' => array(
|
|
|
|
'className' => 'TestTask.TestTaskComment',
|
|
|
|
'foreignKey' => 'article_id',
|
|
|
|
)
|
|
|
|
);
|
|
|
|
var $hasAndBelongsToMany = array(
|
|
|
|
'Tag' => array(
|
|
|
|
'className' => 'TestTaskTag',
|
|
|
|
'joinTable' => 'articles_tags',
|
|
|
|
'foreignKey' => 'article_id',
|
|
|
|
'associationForeignKey' => 'tag_id'
|
|
|
|
)
|
|
|
|
);
|
2009-05-25 03:50:21 +00:00
|
|
|
function doSomething() {
|
|
|
|
|
|
|
|
}
|
|
|
|
function doSomethingElse() {
|
|
|
|
|
|
|
|
}
|
|
|
|
function _innerMethod() {
|
|
|
|
|
|
|
|
}
|
2009-05-24 05:15:31 +00:00
|
|
|
}
|
|
|
|
class TestTaskTag extends Model {
|
|
|
|
var $name = 'TestTaskTag';
|
|
|
|
var $useTable = 'tags';
|
|
|
|
var $hasAndBelongsToMany = array(
|
|
|
|
'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
|
|
|
/**
|
|
|
|
* Simulated Plugin
|
|
|
|
**/
|
|
|
|
class TestTaskAppModel extends Model {
|
2009-07-26 09:59:51 +00:00
|
|
|
|
2009-05-24 03:48:25 +00:00
|
|
|
}
|
2009-05-24 05:15:31 +00:00
|
|
|
class TestTaskComment extends TestTaskAppModel {
|
|
|
|
var $name = 'TestTaskComment';
|
|
|
|
var $useTable = 'comments';
|
|
|
|
var $belongsTo = array(
|
|
|
|
'Article' => array(
|
|
|
|
'className' => 'TestTaskArticle',
|
|
|
|
'foreignKey' => 'article_id',
|
|
|
|
)
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2009-05-24 05:30:04 +00:00
|
|
|
class TestTaskCommentsController extends Controller {
|
|
|
|
var $name = 'TestTaskComments';
|
|
|
|
var $uses = array('TestTaskComment', 'TestTaskTag');
|
|
|
|
}
|
|
|
|
|
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
|
|
|
|
|
|
|
var $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
|
|
|
/**
|
2009-07-17 03:55:41 +00:00
|
|
|
* startTest method
|
2009-03-13 16:06:18 +00:00
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
* @access public
|
|
|
|
*/
|
2009-05-25 03:50:21 +00:00
|
|
|
function startTest() {
|
2009-03-13 16:06:18 +00:00
|
|
|
$this->Dispatcher =& new TestTestTaskMockShellDispatcher();
|
2009-07-07 03:11:57 +00:00
|
|
|
$this->Dispatcher->shellPaths = App::path('shells');
|
2009-03-13 16:06:18 +00:00
|
|
|
$this->Task =& new MockTestTask($this->Dispatcher);
|
2009-05-25 03:50:21 +00:00
|
|
|
$this->Task->Dispatch =& $this->Dispatcher;
|
|
|
|
$this->Task->Template =& new TemplateTask($this->Dispatcher);
|
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
|
|
|
|
* @access public
|
|
|
|
*/
|
2009-05-25 03:50:21 +00:00
|
|
|
function endTest() {
|
2009-03-13 16:06:18 +00:00
|
|
|
ClassRegistry::flush();
|
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
|
|
|
* @access public
|
|
|
|
* @return void
|
|
|
|
*/
|
2009-07-26 09:59:51 +00:00
|
|
|
function testFilePathGeneration() {
|
2009-03-13 16:06:18 +00:00
|
|
|
$file = TESTS . 'cases' . DS . 'models' . DS . 'my_class.test.php';
|
2009-02-13 14:22:11 +00:00
|
|
|
|
2009-03-13 16:06:18 +00:00
|
|
|
$this->Task->Dispatch->expectNever('stderr');
|
|
|
|
$this->Task->Dispatch->expectNever('_stop');
|
|
|
|
|
2009-05-26 03:57:15 +00:00
|
|
|
$this->Task->setReturnValue('in', 'y');
|
2009-03-13 16:06:18 +00:00
|
|
|
$this->Task->expectAt(0, 'createFile', array($file, '*'));
|
|
|
|
$this->Task->bake('Model', 'MyClass');
|
|
|
|
|
|
|
|
$this->Task->expectAt(1, 'createFile', array($file, '*'));
|
|
|
|
$this->Task->bake('Model', 'MyClass');
|
2009-05-26 03:57:15 +00:00
|
|
|
|
|
|
|
$file = TESTS . 'cases' . DS . 'controllers' . DS . 'comments_controller.test.php';
|
|
|
|
$this->Task->expectAt(2, 'createFile', array($file, '*'));
|
|
|
|
$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
|
|
|
|
**/
|
|
|
|
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-05-24 05:30:04 +00:00
|
|
|
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
|
|
|
|
**/
|
|
|
|
function testFixtureArrayGenerationFromController() {
|
|
|
|
$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
|
|
|
|
**/
|
|
|
|
function testGetObjectType() {
|
|
|
|
$this->Task->expectOnce('_stop');
|
|
|
|
$this->Task->setReturnValueAt(0, 'in', 'q');
|
|
|
|
$this->Task->getObjectType();
|
|
|
|
|
|
|
|
$this->Task->setReturnValueAt(1, 'in', 2);
|
|
|
|
$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
|
|
|
|
**/
|
|
|
|
function testRegistryClearWhenBuildingTestObjects() {
|
|
|
|
ClassRegistry::flush();
|
|
|
|
$model = ClassRegistry::init('TestTaskComment');
|
|
|
|
$model->bindModel(array(
|
|
|
|
'belongsTo' => array(
|
|
|
|
'Random' => array(
|
|
|
|
'className' => 'TestTaskArticle',
|
|
|
|
'foreignKey' => 'article_id',
|
|
|
|
)
|
|
|
|
)
|
|
|
|
));
|
|
|
|
$keys = ClassRegistry::keys();
|
|
|
|
$this->assertTrue(in_array('random', $keys));
|
|
|
|
$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
|
|
|
|
**/
|
|
|
|
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;
|
|
|
|
}
|
2009-05-25 03:50:21 +00:00
|
|
|
$this->Task->setReturnValueAt(0, 'in', 'MyCustomClass');
|
|
|
|
$result = $this->Task->getClassName('Model');
|
|
|
|
$this->assertEqual($result, 'MyCustomClass');
|
|
|
|
|
|
|
|
$this->Task->setReturnValueAt(1, 'in', 1);
|
|
|
|
$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
|
|
|
|
**/
|
|
|
|
function testGetUserFixtures() {
|
|
|
|
$this->Task->setReturnValueAt(0, 'in', 'y');
|
|
|
|
$this->Task->setReturnValueAt(1, 'in', 'app.pizza, app.topping, app.side_dish');
|
|
|
|
$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
|
|
|
|
**/
|
|
|
|
function testGetRealClassname() {
|
|
|
|
$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-05-26 03:48:41 +00:00
|
|
|
function testBakeModelTest() {
|
2009-05-25 03:50:21 +00:00
|
|
|
$this->Task->setReturnValue('createFile', true);
|
|
|
|
$this->Task->setReturnValue('isLoadableClass', true);
|
|
|
|
|
|
|
|
$result = $this->Task->bake('Model', 'TestTaskArticle');
|
|
|
|
|
|
|
|
$this->assertPattern('/App::import\(\'Model\', \'TestTaskArticle\'\)/', $result);
|
|
|
|
$this->assertPattern('/class TestTaskArticleTestCase extends CakeTestCase/', $result);
|
2009-05-25 04:54:23 +00:00
|
|
|
|
|
|
|
$this->assertPattern('/function startTest\(\)/', $result);
|
|
|
|
$this->assertPattern("/\\\$this->TestTaskArticle \=\& ClassRegistry::init\('TestTaskArticle'\)/", $result);
|
|
|
|
|
|
|
|
$this->assertPattern('/function endTest\(\)/', $result);
|
|
|
|
$this->assertPattern('/unset\(\$this->TestTaskArticle\)/', $result);
|
|
|
|
|
2009-08-02 22:17:31 +00:00
|
|
|
$this->assertPattern('/function testDoSomething\(\)/i', $result);
|
|
|
|
$this->assertPattern('/function testDoSomethingElse\(\)/i', $result);
|
2009-05-25 03:50:21 +00:00
|
|
|
|
|
|
|
$this->assertPattern("/'app\.test_task_article'/", $result);
|
2009-08-02 22:17:31 +00:00
|
|
|
if (PHP5) {
|
|
|
|
$this->assertPattern("/'plugin\.test_task\.test_task_comment'/", $result);
|
|
|
|
}
|
2009-05-25 03:50:21 +00:00
|
|
|
$this->assertPattern("/'app\.test_task_tag'/", $result);
|
|
|
|
$this->assertPattern("/'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
|
|
|
|
**/
|
|
|
|
function testBakeControllerTest() {
|
|
|
|
$this->Task->setReturnValue('createFile', true);
|
|
|
|
$this->Task->setReturnValue('isLoadableClass', true);
|
|
|
|
|
|
|
|
$result = $this->Task->bake('Controller', 'TestTaskComments');
|
|
|
|
|
|
|
|
$this->assertPattern('/App::import\(\'Controller\', \'TestTaskComments\'\)/', $result);
|
|
|
|
$this->assertPattern('/class TestTaskCommentsControllerTestCase extends CakeTestCase/', $result);
|
|
|
|
|
|
|
|
$this->assertPattern('/class TestTestTaskCommentsController extends TestTaskCommentsController/', $result);
|
|
|
|
$this->assertPattern('/var \$autoRender = false/', $result);
|
|
|
|
$this->assertPattern('/function redirect\(\$url, \$status = null, \$exit = true\)/', $result);
|
|
|
|
|
|
|
|
$this->assertPattern('/function startTest\(\)/', $result);
|
2009-08-06 00:45:54 +00:00
|
|
|
$this->assertPattern("/\\\$this->TestTaskComments \=\& new TestTestTaskCommentsController\(\)/", $result);
|
|
|
|
$this->assertPattern("/\\\$this->TestTaskComments->constructClasses\(\)/", $result);
|
2009-05-26 03:48:41 +00:00
|
|
|
|
|
|
|
$this->assertPattern('/function endTest\(\)/', $result);
|
|
|
|
$this->assertPattern('/unset\(\$this->TestTaskComments\)/', $result);
|
|
|
|
|
|
|
|
$this->assertPattern("/'app\.test_task_article'/", $result);
|
2009-08-02 22:17:31 +00:00
|
|
|
if (PHP5) {
|
|
|
|
$this->assertPattern("/'plugin\.test_task\.test_task_comment'/", $result);
|
|
|
|
}
|
2009-05-26 03:48:41 +00:00
|
|
|
$this->assertPattern("/'app\.test_task_tag'/", $result);
|
|
|
|
$this->assertPattern("/'app\.articles_tag'/", $result);
|
|
|
|
}
|
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
|
|
|
|
**/
|
|
|
|
function testGenerateContsructor() {
|
|
|
|
$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');
|
|
|
|
$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
|
|
|
|
**/
|
|
|
|
function testMockClassGeneration() {
|
|
|
|
$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
|
|
|
|
**/
|
|
|
|
function testBakeWithPlugin() {
|
|
|
|
$this->Task->plugin = 'TestTest';
|
|
|
|
|
|
|
|
$path = APP . 'plugins' . DS . 'test_test' . DS . 'tests' . DS . 'cases' . DS . 'helpers' . DS . 'form.test.php';
|
|
|
|
$this->Task->expectAt(0, 'createFile', array($path, '*'));
|
|
|
|
$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
|
|
|
|
**/
|
|
|
|
function testTestCaseFileName() {
|
|
|
|
$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
|
|
|
|
**/
|
|
|
|
function testExecuteWithOneArg() {
|
|
|
|
$this->Task->args[0] = 'Model';
|
|
|
|
$this->Task->setReturnValueAt(0, 'in', 'TestTaskTag');
|
|
|
|
$this->Task->setReturnValue('isLoadableClass', true);
|
|
|
|
$this->Task->expectAt(0, 'createFile', array('*', new PatternExpectation('/class TestTaskTagTestCase extends CakeTestCase/')));
|
|
|
|
$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
|
|
|
|
**/
|
|
|
|
function testExecuteWithTwoArgs() {
|
|
|
|
$this->Task->args = array('Model', 'TestTaskTag');
|
|
|
|
$this->Task->setReturnValueAt(0, 'in', 'TestTaskTag');
|
|
|
|
$this->Task->setReturnValue('isLoadableClass', true);
|
|
|
|
$this->Task->expectAt(0, 'createFile', array('*', new PatternExpectation('/class TestTaskTagTestCase extends CakeTestCase/')));
|
|
|
|
$this->Task->execute();
|
|
|
|
}
|
2009-02-13 14:22:11 +00:00
|
|
|
}
|
|
|
|
?>
|