Browse Source

Rename isValid to validate.

This makes it more consistent with Table::validate().
mark_story 11 years ago
parent
commit
94fedf0b26
2 changed files with 8 additions and 8 deletions
  1. 3 3
      src/Form/Form.php
  2. 5 5
      tests/TestCase/Form/FormTest.php

+ 3 - 3
src/Form/Form.php

@@ -131,7 +131,7 @@ class Form {
  * @param array $data The data to check.
  * @return bool Whether or not the data is valid.
  */
-	public function isValid(array $data) {
+	public function validate(array $data) {
 		$validator = $this->validator();
 		$this->_errors = $validator->errors($data);
 		return count($this->_errors) === 0;
@@ -141,7 +141,7 @@ class Form {
  * Get the errors in the form
  *
  * Will return the errors from the last call
- * to `isValid()` or `execute()`.
+ * to `validate()` or `execute()`.
  *
  * @return array Last set validation errors.
  */
@@ -162,7 +162,7 @@ class Form {
  *   result of the `_execute()` method.
  */
 	public function execute(array $data) {
-		if (!$this->isValid($data)) {
+		if (!$this->validate($data)) {
 			return false;
 		}
 		return $this->_execute($data);

+ 5 - 5
tests/TestCase/Form/FormTest.php

@@ -57,11 +57,11 @@ class FormTest extends TestCase {
 	}
 
 /**
- * Test isValid method.
+ * Test validate method.
  *
  * @return void
  */
-	public function testIsValid() {
+	public function testValidate() {
 		$form = new Form();
 		$form->validator()
 			->add('email', 'format', ['rule' => 'email'])
@@ -71,14 +71,14 @@ class FormTest extends TestCase {
 			'email' => 'rong',
 			'body' => 'too short'
 		];
-		$this->assertFalse($form->isValid($data));
+		$this->assertFalse($form->validate($data));
 		$this->assertCount(2, $form->errors());
 
 		$data = [
 			'email' => 'test@example.com',
 			'body' => 'Some content goes here'
 		];
-		$this->assertTrue($form->isValid($data));
+		$this->assertTrue($form->validate($data));
 		$this->assertCount(0, $form->errors());
 	}
 
@@ -103,7 +103,7 @@ class FormTest extends TestCase {
 			'email' => 'rong',
 			'body' => 'too short'
 		];
-		$form->isValid($data);
+		$form->validate($data);
 		$errors = $form->errors();
 		$this->assertCount(2, $errors);
 		$this->assertEquals('Must be a valid email', $errors['email']['format']);