Browse Source

Merge pull request #12612 from inoas/Form-Form-getErrors

Form/Form::getErrors - re-add old test
saeideng 7 years ago
parent
commit
63e92c4b98
1 changed files with 22 additions and 2 deletions
  1. 22 2
      tests/TestCase/Form/FormTest.php

+ 22 - 2
tests/TestCase/Form/FormTest.php

@@ -148,11 +148,31 @@ class FormTest extends TestCase
      * Test the errors methods.
      *
      * @return void
-     * @deprecated 3.7.0 Use Form::testGetErrors() instead.
      */
     public function testErrors()
     {
-        $this->testGetErrors();
+        $this->deprecated(function () {
+            $form = new Form();
+            $form->getValidator()
+                ->add('email', 'format', [
+                    'message' => 'Must be a valid email',
+                    'rule' => 'email'
+                ])
+                ->add('body', 'length', [
+                    'message' => 'Must be so long',
+                    'rule' => ['minLength', 12],
+                ]);
+
+            $data = [
+                'email' => 'rong',
+                'body' => 'too short'
+            ];
+            $form->validate($data);
+            $errors = $form->errors();
+            $this->assertCount(2, $errors);
+            $this->assertEquals('Must be a valid email', $errors['email']['format']);
+            $this->assertEquals('Must be so long', $errors['body']['length']);
+        });
     }
 
     /**