Skip to content
Permalink
Browse files

Adding test case and function for generating

fixture lists from controller objects.
  • Loading branch information...
markstory committed May 24, 2009
1 parent 61191d8 commit 1d6ceffb926898e780ff3702469cb32641c93a6c
Showing with 41 additions and 3 deletions.
  1. +18 −2 cake/console/libs/tasks/test.php
  2. +23 −1 cake/tests/cases/console/libs/tasks/test.test.php
@@ -221,7 +221,7 @@ function getTestableMethods($className) {
}
/**
* Generate the list of fixtures that will be required to run this test based on
* Generate the list of fixtures that will be required to run this test based on
* loaded models.
*
* @param object The object you want to generate fixtures for.
@@ -238,7 +238,7 @@ function generateFixtureList(&$subject) {
}
/**
* Process a model recursively and pull out all the
* Process a model recursively and pull out all the
* model names converting them to fixture names.
*
* @return void
@@ -260,6 +260,22 @@ function _processModel(&$subject) {
}
}
/**
* Process all the models attached to a controller
* and generate a fixture list.
*
* @return void
**/
function _processController(&$subject) {
$subject->constructClasses();
$models = array(Inflector::classify($subject->name));
if (!empty($subject->uses)) {
$models = $subject->uses;
}
foreach ($models as $model) {
$this->_processModel($subject->{$model});
}
}
/**
* Add classname to the fixture list.
* Sets the app. or plugin.plugin_name. prefix.
@@ -25,6 +25,7 @@
* @license http://www.opensource.org/licenses/mit-license.php The MIT License
*/
App::import('Core', 'Shell');
App::import('Core', array('Controller', 'Model'));
if (!defined('DISABLE_AUTO_DISPATCH')) {
define('DISABLE_AUTO_DISPATCH', true);
@@ -49,6 +50,7 @@
'TestTask', 'MockTestTask',
array('in', 'out', 'createFile')
);
/**
* Test subject for method extraction
*
@@ -109,6 +111,11 @@ class TestTaskComment extends TestTaskAppModel {
);
}
class TestTaskCommentsController extends Controller {
var $name = 'TestTaskComments';
var $uses = array('TestTaskComment', 'TestTaskTag');
}
/**
* TestTaskTest class
*
@@ -178,7 +185,7 @@ function testMethodIntrospection() {
*
* @return void
**/
function testFixtureArrayGeneration() {
function testFixtureArrayGenerationFromModel() {
$subject = ClassRegistry::init('TestTaskArticle');
$result = $this->Task->generateFixtureList($subject);
$expected = array('plugin.test_task.test_task_comment', 'app.articles_tags',
@@ -187,5 +194,20 @@ function testFixtureArrayGeneration() {
$this->assertEqual(sort($result), sort($expected));
}
/**
* test that the generation of fixtures works correctly.
*
* @return void
**/
function testFixtureArrayGenerationFromController() {
$subject = new TestTaskCommentsController();
$result = $this->Task->generateFixtureList($subject);
$expected = array('plugin.test_task.test_task_comment', 'app.articles_tags',
'app.test_task_article', 'app.test_task_tag');
$this->assertEqual(sort($result), sort($expected));
}
}
?>

0 comments on commit 1d6ceff

Please sign in to comment.
You can’t perform that action at this time.