Fixing docbloc and adding tests for FormHelper::tagIsInvalid(). Refs #2562

This commit is contained in:
ADmad 2012-02-11 06:09:58 +05:30
parent 9c1fa28d60
commit 83e8d436f8
2 changed files with 32 additions and 7 deletions

View file

@ -1434,6 +1434,31 @@ class FormHelperTest extends CakeTestCase {
$this->assertEquals(array(), $this->Form->fields);
}
/**
* testTagIsInvalid method
*
* @return void
*/
public function testTagIsInvalid() {
$Contact = ClassRegistry::getObject('Contact');
$Contact->validationErrors[0]['email'] = array('Please provide an email');
$this->Form->setEntity('Contact.0.email');
$result = $this->Form->tagIsInvalid();
$expected = array('Please provide an email');
$this->assertEquals($expected, $result);
$this->Form->setEntity('Contact.1.email');
$result = $this->Form->tagIsInvalid();
$expected = false;
$this->assertIdentical($expected, $result);
$this->Form->setEntity('Contact.0.name');
$result = $this->Form->tagIsInvalid();
$expected = false;
$this->assertIdentical($expected, $result);
}
/**
* testPasswordValidation method
*

View file

@ -272,8 +272,8 @@ class FormHelper extends AppHelper {
* Returns false if given form field described by the current entity has no errors.
* Otherwise it returns the validation message
*
* @return mixed Either false when there or no errors, or the error
* string. The error string could be ''.
* @return mixed Either false when there or no errors, or an array of error
* strings. An error string could be ''.
* @link http://book.cakephp.org/2.0/en/core-libraries/helpers/form.html#FormHelper::tagIsInvalid
*/
public function tagIsInvalid() {
@ -289,8 +289,8 @@ class FormHelper extends AppHelper {
if (empty($errors)) {
return false;
}
$error = Set::classicExtract($errors, join('.', $entity));
return $error === null ? false : $error;
$errors = Set::classicExtract($errors, join('.', $entity));
return $errors === null ? false : $errors;
}
/**