Skip to content
Permalink
Browse files

extracting out object type interaction.

test case added.
  • Loading branch information...
markstory committed May 25, 2009
1 parent 1d6ceff commit eb9f40c6f4faea75522b291f8e9c2085112d9535
Showing with 63 additions and 25 deletions.
  1. +48 −23 cake/console/libs/tasks/test.php
  2. +15 −2 cake/tests/cases/console/libs/tasks/test.test.php
@@ -45,6 +45,14 @@ class TestTask extends Shell {
* @access public
*/
var $path = TESTS;
/**
* class types that methods can be generated for
*
* @var array
**/
var $classTypes = array('Model', 'Controller', 'Component', 'Behavior', 'Helper');
/**
* Execution method always used for tasks
*
@@ -66,40 +74,31 @@ function execute() {
}
}
}
/**
* Handles interactive baking
*
* @access private
*/
function __interactive($class = null) {
function __interactive($type = null) {
$this->hr();
$this->out(sprintf("Bake Tests\nPath: %s", $this->path));
$this->out(__('Bake Tests', true));
$this->out(sprintf(__("Path: %s", true), $this->path));
$this->hr();
$key = null;
$options = array('Behavior', 'Helper', 'Component', 'Model', 'Controller');
if ($class !== null) {
$class = Inflector::camelize($class);
if (in_array($class, $options)) {
$key = array_search($class);
$selection = null;
if ($type) {
$type = Inflector::camelize($type);
if (in_array($type, $this->classTypes)) {
$selection = array_search($type);
}
}
if (!$selection) {
$selection = $this->getObjectType();
}
/*
while ($class == null) {
$cases = array();
$this->hr();
$this->out("Select a class:");
$this->hr();
$keys = array();
foreach ($options as $key => $option) {
$this->out(++$key . '. ' . $option);
$keys[] = $key;
}
$keys[] = 'q';
$key = $this->in(__("Enter the class to test or (q)uit", true), $keys, 'q');
$key = $this->in(__("Enter the class to bake a test for or (q)uit", true), $keys, 'q');
if ($key != 'q') {
if (isset($options[--$key])) {
@@ -127,7 +126,32 @@ function __interactive($class = null) {
$this->_stop();
}
}
*/
}
/**
* Interact with the user and get their chosen type. Can exit the script.
*
* @return int Index of users chosen object type.
**/
function getObjectType() {
$this->hr();
$this->out(__("Select an object type:", true));
$this->hr();
$keys = array();
foreach ($this->classTypes as $key => $option) {
$this->out(++$key . '. ' . $option);
$keys[] = $key;
}
$keys[] = 'q';
$selection = $this->in(__("Enter the type of object to bake a test for or (q)uit", true), $keys, 'q');
if ($selection == 'q') {
$this->_stop();
}
return $selection;
}
/**
* Writes File
*
@@ -276,6 +300,7 @@ function _processController(&$subject) {
$this->_processModel($subject->{$model});
}
}
/**
* Add classname to the fixture list.
* Sets the app. or plugin.plugin_name. prefix.
@@ -48,7 +48,7 @@
);
Mock::generatePartial(
'TestTask', 'MockTestTask',
array('in', 'out', 'createFile')
array('in', '_stop', 'err', 'out', 'createFile')
);
/**
@@ -192,7 +192,6 @@ function testFixtureArrayGenerationFromModel() {
'app.test_task_article', 'app.test_task_tag');
$this->assertEqual(sort($result), sort($expected));
}
/**
@@ -207,7 +206,21 @@ function testFixtureArrayGenerationFromController() {
'app.test_task_article', 'app.test_task_tag');
$this->assertEqual(sort($result), sort($expected));
}
/**
* 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();
$this->assertEqual($result, 2);
}
}
?>

0 comments on commit eb9f40c

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