class XmlFileLoaderTest

Hierarchy

  • class \Symfony\Component\Validator\Tests\Mapping\Loader\XmlFileLoaderTest extends \Symfony\Component\Validator\Tests\Mapping\Loader\PHPUnit_Framework_TestCase

Expanded class hierarchy of XmlFileLoaderTest

File

drupal/core/vendor/symfony/validator/Symfony/Component/Validator/Tests/Mapping/Loader/XmlFileLoaderTest.php, line 24

Namespace

Symfony\Component\Validator\Tests\Mapping\Loader
View source
class XmlFileLoaderTest extends \PHPUnit_Framework_TestCase {
  public function testLoadClassMetadataReturnsTrueIfSuccessful() {
    $loader = new XmlFileLoader(__DIR__ . '/constraint-mapping.xml');
    $metadata = new ClassMetadata('Symfony\\Component\\Validator\\Tests\\Fixtures\\Entity');
    $this
      ->assertTrue($loader
      ->loadClassMetadata($metadata));
  }
  public function testLoadClassMetadataReturnsFalseIfNotSuccessful() {
    $loader = new XmlFileLoader(__DIR__ . '/constraint-mapping.xml');
    $metadata = new ClassMetadata('\\stdClass');
    $this
      ->assertFalse($loader
      ->loadClassMetadata($metadata));
  }
  public function testLoadClassMetadata() {
    $loader = new XmlFileLoader(__DIR__ . '/constraint-mapping.xml');
    $metadata = new ClassMetadata('Symfony\\Component\\Validator\\Tests\\Fixtures\\Entity');
    $loader
      ->loadClassMetadata($metadata);
    $expected = new ClassMetadata('Symfony\\Component\\Validator\\Tests\\Fixtures\\Entity');
    $expected
      ->setGroupSequence(array(
      'Foo',
      'Entity',
    ));
    $expected
      ->addConstraint(new ConstraintA());
    $expected
      ->addConstraint(new ConstraintB());
    $expected
      ->addPropertyConstraint('firstName', new NotNull());
    $expected
      ->addPropertyConstraint('firstName', new Range(array(
      'min' => 3,
    )));
    $expected
      ->addPropertyConstraint('firstName', new Choice(array(
      'A',
      'B',
    )));
    $expected
      ->addPropertyConstraint('firstName', new All(array(
      new NotNull(),
      new Range(array(
        'min' => 3,
      )),
    )));
    $expected
      ->addPropertyConstraint('firstName', new All(array(
      'constraints' => array(
        new NotNull(),
        new Range(array(
          'min' => 3,
        )),
      ),
    )));
    $expected
      ->addPropertyConstraint('firstName', new Collection(array(
      'fields' => array(
        'foo' => array(
          new NotNull(),
          new Range(array(
            'min' => 3,
          )),
        ),
        'bar' => array(
          new Range(array(
            'min' => 5,
          )),
        ),
      ),
    )));
    $expected
      ->addPropertyConstraint('firstName', new Choice(array(
      'message' => 'Must be one of %choices%',
      'choices' => array(
        'A',
        'B',
      ),
    )));
    $expected
      ->addGetterConstraint('lastName', new NotNull());
    $this
      ->assertEquals($expected, $metadata);
  }
  public function testLoadGroupSequenceProvider() {
    $loader = new XmlFileLoader(__DIR__ . '/constraint-mapping.xml');
    $metadata = new ClassMetadata('Symfony\\Component\\Validator\\Tests\\Fixtures\\GroupSequenceProviderEntity');
    $loader
      ->loadClassMetadata($metadata);
    $expected = new ClassMetadata('Symfony\\Component\\Validator\\Tests\\Fixtures\\GroupSequenceProviderEntity');
    $expected
      ->setGroupSequenceProvider(true);
    $this
      ->assertEquals($expected, $metadata);
  }

  /**
   * @expectedException        \Symfony\Component\Validator\Exception\MappingException
   * @expectedExceptionMessage Document types are not allowed.
   */
  public function testDocTypeIsNotAllowed() {
    $loader = new XmlFileLoader(__DIR__ . '/withdoctype.xml');
    $metadata = new ClassMetadata('Symfony\\Component\\Validator\\Tests\\Fixtures\\Entity');
    $loader
      ->loadClassMetadata($metadata);
  }

}

Members