XmlMappingDriverTest.php 2.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. <?php
  2. namespace Doctrine\Tests\ORM\Mapping;
  3. use Doctrine\ORM\Mapping\ClassMetadata,
  4. Doctrine\ORM\Mapping\Driver\XmlDriver,
  5. Doctrine\ORM\Mapping\Driver\YamlDriver;
  6. require_once __DIR__ . '/../../TestInit.php';
  7. class XmlMappingDriverTest extends AbstractMappingDriverTest
  8. {
  9. protected function _loadDriver()
  10. {
  11. return new XmlDriver(__DIR__ . DIRECTORY_SEPARATOR . 'xml');
  12. }
  13. public function testClassTableInheritanceDiscriminatorMap()
  14. {
  15. $className = 'Doctrine\Tests\ORM\Mapping\CTI';
  16. $mappingDriver = $this->_loadDriver();
  17. $class = new ClassMetadata($className);
  18. $mappingDriver->loadMetadataForClass($className, $class);
  19. $expectedMap = array(
  20. "foo" => "Doctrine\Tests\ORM\Mapping\CTIFoo",
  21. "bar" => "Doctrine\Tests\ORM\Mapping\CTIBar",
  22. "baz" => "Doctrine\Tests\ORM\Mapping\CTIBaz",
  23. );
  24. $this->assertEquals(3, count($class->discriminatorMap));
  25. $this->assertEquals($expectedMap, $class->discriminatorMap);
  26. }
  27. public function testIdentifierWithAssociationKey()
  28. {
  29. $driver = $this->_loadDriver();
  30. $em = $this->_getTestEntityManager();
  31. $factory = new \Doctrine\ORM\Mapping\ClassMetadataFactory();
  32. $em->getConfiguration()->setMetadataDriverImpl($driver);
  33. $factory->setEntityManager($em);
  34. $class = $factory->getMetadataFor('Doctrine\Tests\Models\DDC117\DDC117Translation');
  35. $this->assertEquals(array('language', 'article'), $class->identifier);
  36. $this->assertArrayHasKey('article', $class->associationMappings);
  37. $this->assertArrayHasKey('id', $class->associationMappings['article']);
  38. $this->assertTrue($class->associationMappings['article']['id']);
  39. }
  40. /**
  41. * @param string $xmlMappingFile
  42. * @dataProvider dataValidSchema
  43. */
  44. public function testValidateXmlSchema($xmlMappingFile)
  45. {
  46. $xsdSchemaFile = __DIR__ . "/../../../../../doctrine-mapping.xsd";
  47. $dom = new \DOMDocument('UTF-8');
  48. $dom->load($xmlMappingFile);
  49. $this->assertTrue($dom->schemaValidate($xsdSchemaFile));
  50. }
  51. static public function dataValidSchema()
  52. {
  53. return array(
  54. array(__DIR__ . "/xml/Doctrine.Tests.ORM.Mapping.CTI.dcm.xml"),
  55. array(__DIR__ . "/xml/Doctrine.Tests.ORM.Mapping.User.dcm.xml"),
  56. array(__DIR__ . "/xml/CatNoId.dcm.xml"),
  57. );
  58. }
  59. }
  60. class CTI
  61. {
  62. public $id;
  63. }
  64. class CTIFoo extends CTI {}
  65. class CTIBar extends CTI {}
  66. class CTIBaz extends CTI {}