Browse Source

Add test to cover allowEmptyString with when callback.

Refs cakephp/docs#6307
Mark Story 6 years ago
parent
commit
1bd4859170
1 changed files with 28 additions and 0 deletions
  1. 28 0
      tests/TestCase/Validation/ValidatorTest.php

+ 28 - 0
tests/TestCase/Validation/ValidatorTest.php

@@ -822,6 +822,34 @@ class ValidatorTest extends TestCase
     }
 
     /**
+     * Test allowEmptyString with callback
+     *
+     */
+    public function testAllowEmptyStringCallbackWhen()
+    {
+        $validator = new Validator();
+        $validator->allowEmptyString(
+            'title',
+            'very required',
+            function ($context) {
+                return $context['data']['otherField'] === true;
+            })
+            ->scalar('title');
+
+        $data = [
+            'title' => '',
+            'otherField' => false,
+        ];
+        $this->assertNotEmpty($validator->errors($data));
+
+        $data = [
+            'title' => '',
+            'otherField' => true,
+        ];
+        $this->assertEmpty($validator->errors($data));
+    }
+
+    /**
      * Same as testAllowEmptyDateUpdateDeprecatedArguments but without message
      *
      * @return void