Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Fixing the ability to use regular expressions for validation rules. F…

…ixes #453
  • Loading branch information...
commit 49c60658b965da4193d653547535b37746a35f2e 1 parent 688daf2
@markstory markstory authored
View
10 cake/console/libs/tasks/model.php
@@ -410,7 +410,7 @@ function fieldValidation($fieldName, $metaData, $primaryKey = 'id') {
$this->out(__("You have already chosen that validation rule,\nplease choose again", true));
continue;
}
- if (!isset($this->_validations[$choice])) {
+ if (!isset($this->_validations[$choice]) && is_numeric($choice)) {
$this->out(__('Please make a valid selection.', true));
continue;
}
@@ -418,7 +418,13 @@ function fieldValidation($fieldName, $metaData, $primaryKey = 'id') {
} else {
$choice = $guess;
}
- $validatorName = $this->_validations[$choice];
+
+ if (isset($this->_validations[$choice])) {
+ $validatorName = $this->_validations[$choice];
+ } else {
+ $validatorName = Inflector::slug($choice);
+ }
+
if ($choice != $defaultChoice) {
if (is_numeric($choice) && isset($this->_validations[$choice])) {
$validate[$validatorName] = $this->_validations[$choice];
View
18 cake/tests/cases/console/libs/tasks/model.test.php
@@ -241,7 +241,7 @@ function testInteractiveFieldValidation() {
function testInteractiveFieldValidationWithBogusResponse() {
$this->Task->initValidations();
$this->Task->interactive = true;
- $this->Task->setReturnValueAt(0, 'in', '--bogus--');
+ $this->Task->setReturnValueAt(0, 'in', '999999');
$this->Task->setReturnValueAt(1, 'in', '19');
$this->Task->setReturnValueAt(2, 'in', 'n');
$this->Task->expectAt(4, 'out', array(new PatternExpectation('/make a valid/')));
@@ -252,6 +252,22 @@ function testInteractiveFieldValidationWithBogusResponse() {
}
/**
+ * test that a regular expression can be used for validation.
+ *
+ * @return void
+ */
+ function testInteractiveFieldValidationWithRegexp() {
+ $this->Task->initValidations();
+ $this->Task->interactive = true;
+ $this->Task->setReturnValueAt(0, 'in', '/^[a-z]{0,9}$/');
+ $this->Task->setReturnValueAt(1, 'in', 'n');
+
+ $result = $this->Task->fieldValidation('text', array('type' => 'string', 'length' => 10, 'null' => false));
+ $expected = array('a_z_0_9' => '/^[a-z]{0,9}$/');
+ $this->assertEqual($result, $expected);
+ }
+
+/**
* test the validation Generation routine
*
* @return void
Please sign in to comment.
Something went wrong with that request. Please try again.