Adding test case and function for generating

fixture lists from controller objects.
This commit is contained in:
mark_story 2009-05-24 01:30:04 -04:00
parent 61191d88cd
commit 1d6ceffb92
2 changed files with 41 additions and 3 deletions

View file

@ -221,7 +221,7 @@ class TestTask extends Shell {
}
/**
* 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 @@ class TestTask extends Shell {
}
/**
* 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 @@ class TestTask extends Shell {
}
}
/**
* 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.

View file

@ -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 @@ Mock::generatePartial(
'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 @@ class TestTaskTest extends CakeTestCase {
*
* @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 @@ class TestTaskTest extends CakeTestCase {
$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));
}
}
?>