Permalink
Browse files

Updating multiple validation generation.

Adding test coverage for interactive validations.
  • Loading branch information...
1 parent 103b974 commit 8775f153757ed6e1007f3021da45a28461cbaa9d @markstory markstory committed May 9, 2009
Showing with 16 additions and 3 deletions.
  1. +6 −2 cake/console/libs/tasks/model.php
  2. +10 −1 cake/tests/cases/console/libs/tasks/model.test.php
@@ -311,7 +311,7 @@ function initValidations() {
**/
function fieldValidation($fieldName, $metaData, $primaryKey = 'id') {
$defaultChoice = count($this->__validations);
- $validate = $alredyChosen = array();
+ $validate = $alreadyChosen = array();
$anotherValidator = 'y';
while ($anotherValidator == 'y') {
@@ -351,6 +351,10 @@ function fieldValidation($fieldName, $metaData, $primaryKey = 'id') {
if ($this->interactive === true) {
$choice = $this->in($prompt, null, $guess);
+ if (in_array($choice, $alreadyChosen)) {
+ $this->out(__('You have already chosen that validation rule, please choose again', true));
+ continue;
+ }
$alreadyChosen[] = $choice;
} else {
$choice = $guess;
@@ -363,7 +367,7 @@ function fieldValidation($fieldName, $metaData, $primaryKey = 'id') {
$validate[$validatorName] = $choice;
}
}
- if ($this->interactive == true) {
+ if ($this->interactive == true && $choice != $defaultChoice) {
$anotherValidator = $this->in(__('Would you like to add another validation rule?', true), array('y', 'n'), 'n');
} else {
$anotherValidator = 'n';
@@ -200,7 +200,16 @@ function testFieldValidationGuessing() {
* @return void
**/
function testInteractiveFieldValidation() {
-
+ $this->Task->initValidations();
+ $this->Task->interactive = true;
+ $this->Task->setReturnValueAt(0, 'in', '20');
+ $this->Task->setReturnValueAt(1, 'in', 'y');
+ $this->Task->setReturnValueAt(2, 'in', '16');
+ $this->Task->setReturnValueAt(3, 'in', 'n');
+
+ $result = $this->Task->fieldValidation('text', array('type' => 'string', 'length' => 10, 'null' => false));
+ $expected = array('notempty' => 'notempty', 'maxlength' => 'maxlength');
+ $this->assertEqual($result, $expected);
}
/**

0 comments on commit 8775f15

Please sign in to comment.