From 1d6ceffb926898e780ff3702469cb32641c93a6c Mon Sep 17 00:00:00 2001 From: mark_story Date: Sun, 24 May 2009 01:30:04 -0400 Subject: [PATCH] Adding test case and function for generating fixture lists from controller objects. --- cake/console/libs/tasks/test.php | 20 ++++++++++++++-- .../cases/console/libs/tasks/test.test.php | 24 ++++++++++++++++++- 2 files changed, 41 insertions(+), 3 deletions(-) diff --git a/cake/console/libs/tasks/test.php b/cake/console/libs/tasks/test.php index 3039dec9b..81609be98 100644 --- a/cake/console/libs/tasks/test.php +++ b/cake/console/libs/tasks/test.php @@ -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. diff --git a/cake/tests/cases/console/libs/tasks/test.test.php b/cake/tests/cases/console/libs/tasks/test.test.php index d1a3f0e38..774312756 100644 --- a/cake/tests/cases/console/libs/tasks/test.test.php +++ b/cake/tests/cases/console/libs/tasks/test.test.php @@ -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)); + + } } ?> \ No newline at end of file