Skip to content
Permalink
Browse files

Adding displayField detection and interaction to ModelTask. Test Case…

…s added.
  • Loading branch information...
markstory committed Jul 8, 2009
1 parent dc98184 commit d671056044ae65b713625c578a99a565867f110d
Showing with 44 additions and 4 deletions.
  1. +23 −4 cake/console/libs/tasks/model.php
  2. +21 −0 cake/tests/cases/console/libs/tasks/model.test.php
@@ -198,6 +198,10 @@ function __interactive() {
$primaryKey = $this->findPrimaryKey($fields);
}
}
$displayField = $tempModel->hasField(array('name', 'title'));
if (!$displayField) {
$displayField = $this->findDisplayField($tempModel->schema());
}
$prompt = __("Would you like to supply validation criteria \nfor the fields in your model?", true);
$wannaDoValidation = $this->in($prompt, array('y','n'), 'y');
@@ -285,13 +289,28 @@ function findPrimaryKey($fields) {
}
return $this->in(__('What is the primaryKey?', true), null, $name);
}
/**
* interact with the user to find the displayField value for a model.
*
* @param array $fields Array of fields to look for and choose as a displayField
* @return mixed Name of field to use for displayField or false if the user declines to choose
**/
function findDisplayField($fields) {
$fieldNames = array_keys($fields);
$prompt = __("A displayField could not be automatically detected\nwould you like to choose one?", true);
$continue = $this->in($prompt, array('y', 'n'));
if (strtolower($continue) == 'n') {
return false;
}
$prompt = __('Choose a field from the options above:', true);
$choice = $this->inOptions($fieldNames, $prompt);
return $fieldNames[$choice];
}
/**
* Handles Generation and user interaction for creating validation.
*
* @param object $model
* @param boolean $interactive
* @return array $validate
* @param object $model Model to have validations generated for.
* @return array $validate Array of user selected validations.
* @access public
*/
function doValidation(&$model) {
@@ -307,6 +307,26 @@ function testFindPrimaryKey() {
$this->assertEqual($result, $expected);
}
/**
* test finding Display field
*
* @return void
**/
function testFindDisplayField() {
$fields = array('id' => array(), 'tagname' => array(), 'body' => array(),
'created' => array(), 'modified' => array());
$this->Task->setReturnValue('in', 'n');
$this->Task->setReturnValueAt(0, 'in', 'n');
$result = $this->Task->findDisplayField($fields);
$this->assertFalse($result);
$this->Task->setReturnValueAt(1, 'in', 'y');
$this->Task->setReturnValueAt(2, 'in', 2);
$result = $this->Task->findDisplayField($fields);
$this->assertEqual($result, 'tagname');
}
/**
* test that belongsTo generation works.
*
@@ -680,6 +700,7 @@ function testExecuteIntoInteractive() {
$this->Task->path = '/my/path/';
$this->Task->setReturnValueAt(0, 'in', '1'); //choose article
// $this->Task->setReturnValueAt(2, 'in', 'n'); //no validation
$this->Task->setReturnValueAt(1, 'in', 'n'); //no validation
$this->Task->setReturnValueAt(2, 'in', 'y'); //yes to associations
$this->Task->setReturnValueAt(3, 'in', 'y'); //yes to comment relation

0 comments on commit d671056

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