Files
Xes 73154ae174
Behat tests 1.11.x 🐞 / PHP 7.4 Test on ubuntu-latest (push) Canceled after 0s
PHP-CS-Fixer / composer_install (7.4) (push) Canceled after 0s
Chamilo 1.11.40 (ZIP oficial v1.11.40)
Fuente: https://github.com/chamilo/chamilo-lms/releases/download/v1.11.40/chamilo-1.11.40.zip
sha256: 1cf4bf2cc7bae1ef1a1eff643235db1d552f78ddf4b6dd1e2d2dac9868679439
Snapshot independiente (rama huerfana); diffable vs 1.11.38. vendor incluido.
2026-08-06 17:59:45 +02:00

149 lines
4.6 KiB
PHP

<?php
/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* 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 <bschussek@gmail.com>
*/
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(),
));
}
}