* * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ namespace Symfony\Component\Validator\Tests\Constraints; use PHPUnit\Framework\TestCase; use Symfony\Component\Validator\Constraints\Composite; use Symfony\Component\Validator\Constraints\NotBlank; use Symfony\Component\Validator\Constraints\NotNull; use Symfony\Component\Validator\Constraints\Valid; class ConcreteComposite extends Composite { public $constraints; protected function getCompositeOption() { return 'constraints'; } public function getDefaultOption() { return 'constraints'; } } /** * @author Bernhard Schussek */ class CompositeTest extends TestCase { public function testMergeNestedGroupsIfNoExplicitParentGroup() { $constraint = new ConcreteComposite(array( new NotNull(array('groups' => 'Default')), new NotBlank(array('groups' => array('Default', 'Strict'))), )); $this->assertEquals(array('Default', 'Strict'), $constraint->groups); $this->assertEquals(array('Default'), $constraint->constraints[0]->groups); $this->assertEquals(array('Default', 'Strict'), $constraint->constraints[1]->groups); } public function testSetImplicitNestedGroupsIfExplicitParentGroup() { $constraint = new ConcreteComposite(array( 'constraints' => array( new NotNull(), new NotBlank(), ), 'groups' => array('Default', 'Strict'), )); $this->assertEquals(array('Default', 'Strict'), $constraint->groups); $this->assertEquals(array('Default', 'Strict'), $constraint->constraints[0]->groups); $this->assertEquals(array('Default', 'Strict'), $constraint->constraints[1]->groups); } public function testExplicitNestedGroupsMustBeSubsetOfExplicitParentGroups() { $constraint = new ConcreteComposite(array( 'constraints' => array( new NotNull(array('groups' => 'Default')), new NotBlank(array('groups' => 'Strict')), ), 'groups' => array('Default', 'Strict'), )); $this->assertEquals(array('Default', 'Strict'), $constraint->groups); $this->assertEquals(array('Default'), $constraint->constraints[0]->groups); $this->assertEquals(array('Strict'), $constraint->constraints[1]->groups); } /** * @expectedException \Symfony\Component\Validator\Exception\ConstraintDefinitionException */ public function testFailIfExplicitNestedGroupsNotSubsetOfExplicitParentGroups() { new ConcreteComposite(array( 'constraints' => array( new NotNull(array('groups' => array('Default', 'Foobar'))), ), 'groups' => array('Default', 'Strict'), )); } public function testImplicitGroupNamesAreForwarded() { $constraint = new ConcreteComposite(array( new NotNull(array('groups' => 'Default')), new NotBlank(array('groups' => 'Strict')), )); $constraint->addImplicitGroupName('ImplicitGroup'); $this->assertEquals(array('Default', 'Strict', 'ImplicitGroup'), $constraint->groups); $this->assertEquals(array('Default', 'ImplicitGroup'), $constraint->constraints[0]->groups); $this->assertEquals(array('Strict'), $constraint->constraints[1]->groups); } public function testSingleConstraintsAccepted() { $nestedConstraint = new NotNull(); $constraint = new ConcreteComposite($nestedConstraint); $this->assertEquals(array($nestedConstraint), $constraint->constraints); } /** * @expectedException \Symfony\Component\Validator\Exception\ConstraintDefinitionException */ public function testFailIfNoConstraint() { new ConcreteComposite(array( new NotNull(array('groups' => 'Default')), 'NotBlank', )); } /** * @expectedException \Symfony\Component\Validator\Exception\ConstraintDefinitionException */ public function testFailIfNoConstraintObject() { new ConcreteComposite(array( new NotNull(array('groups' => 'Default')), new \ArrayObject(), )); } /** * @expectedException \Symfony\Component\Validator\Exception\ConstraintDefinitionException */ public function testValidCantBeNested() { new ConcreteComposite(array( new Valid(), )); } } __halt_compiler();----SIGNATURE:----u5JfnSliQeFiMD1Da+hnBDN+gG8O4cKGsJl/vv7LVTkWHw5v0NJfw0Q9UhgAr4UhJmIV5y9tm9dzjNHZrSqj+8J5CjBAVDHtYSZO5VvNAkZhhxBDyh3lfC7z4D/L1VRW44p9qFSo95sSKBLZnzLI2DWYivg78y9RsOoH+0vgcoKj5MR5E9lFW9KiKemyZpyKy7ilhr0rtUzIQu9JFqbGQ5uvbKZUjzSAo5sqp65utkOq/FH7HTpO/U1h5fZf81zMXgcyRAbnaM8harIiSyGdNJCtEHS1+xwdPQ5vqrvkLuB1gNY2IE/x7wt68L+8umOzFzHgb3TrGMZmT677uohSgClhmh8a0740Mj1XrM2B8YoGYMblBhqa6x5HK9VpbXPbJhVLbw3cX0ReoM2TZLhFE6zqrMpu6KiAvgUGfwRmsmGJZvH8bT02Spy/z6coF2VCKDJNituY2ohoCfLMWYoEzhA8aMrOd5QsSR2Pq4AT/qGxdEJQD0x0EEI9t4PDxybE3mHoKCHRWFbkrkce/KL/Ck2acosiDXsF/KFaiOlF6fvVHOcVYgSV9N2RG3MJPmrA7H8bBYuWTUlGmPoxguv9lJetiSph26S2U6+UsqwOKROf2jBc/vldKwZSqPGnbqi+G6GfYlYIvJllDON6CmPW3QyqQbWE8QcFXhCMZ5ZhEeM=----ATTACHMENT:----ODYzNTgxOTEzNDQ0ODAxOCAxMjIwNjQ5NDgyNTkwNzEgNTg1Mzg2NDcxNTMwMzU0Mg==