From 94039ba5c11dffa1a7bd3f7d89a1c52d7bebc9a3 Mon Sep 17 00:00:00 2001 From: Jose Lorenzo Rodriguez Date: Wed, 4 Nov 2015 13:50:14 +0100 Subject: [PATCH] Added tests for PR #7646 --- tests/TestCase/Validation/ValidatorTest.php | 32 +++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/tests/TestCase/Validation/ValidatorTest.php b/tests/TestCase/Validation/ValidatorTest.php index 8f6a61e4cfe..34b65009a04 100644 --- a/tests/TestCase/Validation/ValidatorTest.php +++ b/tests/TestCase/Validation/ValidatorTest.php @@ -1015,4 +1015,36 @@ public function testDebugInfo() ]; $this->assertEquals($expected, $result); } + + /** + * Tests that the 'create' and 'update' modes are preserved when using + * nested validators + * + * @return void + */ + public function testNestedValidatorCreate() + { + $validator = new Validator(); + $inner = new Validator(); + $inner->add('username', 'email', ['rule' => 'email', 'on' => 'create']); + $validator->addNested('user', $inner); + $this->assertNotEmpty($validator->errors(['user' => ['username' => 'example']], true)); + $this->assertEmpty($validator->errors(['user' => ['username' => 'a']], false)); + } + + /** + * Tests that the 'create' and 'update' modes are preserved when using + * nested validators + * + * @return void + */ + public function testNestedManyValidatorCreate() + { + $validator = new Validator(); + $inner = new Validator(); + $inner->add('username', 'email', ['rule' => 'email', 'on' => 'create']); + $validator->addNestedMany('user', $inner); + $this->assertNotEmpty($validator->errors(['user' => [['username' => 'example']]], true)); + $this->assertEmpty($validator->errors(['user' => [['username' => 'a']]], false)); + } }