[Validator] fixed Boolean handling in XML constraint mappings (closes #5603)
This commit is contained in:
parent
2165d5dffb
commit
33b0a177b5
@ -166,7 +166,10 @@ class XmlFileLoader extends FileLoader
|
|||||||
$value = array();
|
$value = array();
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
$value = trim($node);
|
$value = XmlUtils::phpize($node);
|
||||||
|
if (is_string($value)) {
|
||||||
|
$value = trim($value);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$options[(string) $node['name']] = $value;
|
$options[(string) $node['name']] = $value;
|
||||||
|
@ -16,6 +16,7 @@ use Symfony\Component\Validator\Constraints\Collection;
|
|||||||
use Symfony\Component\Validator\Constraints\NotNull;
|
use Symfony\Component\Validator\Constraints\NotNull;
|
||||||
use Symfony\Component\Validator\Constraints\Range;
|
use Symfony\Component\Validator\Constraints\Range;
|
||||||
use Symfony\Component\Validator\Constraints\Choice;
|
use Symfony\Component\Validator\Constraints\Choice;
|
||||||
|
use Symfony\Component\Validator\Constraints\Regex;
|
||||||
use Symfony\Component\Validator\Mapping\ClassMetadata;
|
use Symfony\Component\Validator\Mapping\ClassMetadata;
|
||||||
use Symfony\Component\Validator\Mapping\Loader\XmlFileLoader;
|
use Symfony\Component\Validator\Mapping\Loader\XmlFileLoader;
|
||||||
use Symfony\Component\Validator\Tests\Fixtures\ConstraintA;
|
use Symfony\Component\Validator\Tests\Fixtures\ConstraintA;
|
||||||
@ -68,6 +69,22 @@ class XmlFileLoaderTest extends \PHPUnit_Framework_TestCase
|
|||||||
$this->assertEquals($expected, $metadata);
|
$this->assertEquals($expected, $metadata);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function testLoadClassMetadataWithNonStrings()
|
||||||
|
{
|
||||||
|
$loader = new XmlFileLoader(__DIR__.'/constraint-mapping-non-strings.xml');
|
||||||
|
$metadata = new ClassMetadata('Symfony\Component\Validator\Tests\Fixtures\Entity');
|
||||||
|
|
||||||
|
$loader->loadClassMetadata($metadata);
|
||||||
|
|
||||||
|
$expected = new ClassMetadata('Symfony\Component\Validator\Tests\Fixtures\Entity');
|
||||||
|
$expected->addPropertyConstraint('firstName', new Regex(array('pattern' => '/^1/', 'match' => false)));
|
||||||
|
|
||||||
|
$properties = $metadata->getPropertyMetadata('firstName');
|
||||||
|
$constraints = $properties[0]->getConstraints();
|
||||||
|
|
||||||
|
$this->assertFalse($constraints[0]->match);
|
||||||
|
}
|
||||||
|
|
||||||
public function testLoadGroupSequenceProvider()
|
public function testLoadGroupSequenceProvider()
|
||||||
{
|
{
|
||||||
$loader = new XmlFileLoader(__DIR__.'/constraint-mapping.xml');
|
$loader = new XmlFileLoader(__DIR__.'/constraint-mapping.xml');
|
||||||
|
@ -0,0 +1,19 @@
|
|||||||
|
<?xml version="1.0" ?>
|
||||||
|
|
||||||
|
<constraint-mapping xmlns="http://symfony.com/schema/dic/constraint-mapping"
|
||||||
|
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||||
|
xsi:schemaLocation="http://symfony.com/schema/dic/constraint-mapping http://symfony.com/schema/dic/constraint-mapping/constraint-mapping-1.0.xsd">
|
||||||
|
|
||||||
|
<namespace prefix="custom">Symfony\Component\Validator\Tests\Fixtures\</namespace>
|
||||||
|
|
||||||
|
<class name="Symfony\Component\Validator\Tests\Fixtures\Entity">
|
||||||
|
<property name="firstName">
|
||||||
|
<!-- Constraint with a Boolean -->
|
||||||
|
<constraint name="Regex">
|
||||||
|
<option name="pattern">/^1/</option>
|
||||||
|
<option name="match">false</option>
|
||||||
|
</constraint>
|
||||||
|
</property>
|
||||||
|
</class>
|
||||||
|
|
||||||
|
</constraint-mapping>
|
@ -78,7 +78,7 @@
|
|||||||
<!-- Constraint with options -->
|
<!-- Constraint with options -->
|
||||||
<constraint name="Choice">
|
<constraint name="Choice">
|
||||||
<!-- Option with single value -->
|
<!-- Option with single value -->
|
||||||
<option name="message">Must be one of %choices%</option>
|
<option name="message"> Must be one of %choices% </option>
|
||||||
<!-- Option with multiple values -->
|
<!-- Option with multiple values -->
|
||||||
<option name="choices">
|
<option name="choices">
|
||||||
<value>A</value>
|
<value>A</value>
|
||||||
|
Reference in New Issue
Block a user