1
0
mirror of synced 2024-12-16 08:06:02 +03:00
doctrine2/tests/Doctrine/Tests/ORM/Mapping/XmlMappingDriverTest.php

107 lines
3.5 KiB
PHP
Raw Normal View History

<?php
namespace Doctrine\Tests\ORM\Mapping;
use Doctrine\ORM\Mapping\ClassMetadata,
Doctrine\ORM\Mapping\Driver\XmlDriver,
Doctrine\ORM\Mapping\Driver\YamlDriver;
require_once __DIR__ . '/../../TestInit.php';
class XmlMappingDriverTest extends AbstractMappingDriverTest
{
protected function _loadDriver()
{
return new XmlDriver(__DIR__ . DIRECTORY_SEPARATOR . 'xml');
}
public function testClassTableInheritanceDiscriminatorMap()
{
$className = 'Doctrine\Tests\ORM\Mapping\CTI';
$mappingDriver = $this->_loadDriver();
$class = new ClassMetadata($className);
$class->initializeReflection(new \Doctrine\Common\Persistence\Mapping\RuntimeReflectionService);
$mappingDriver->loadMetadataForClass($className, $class);
$expectedMap = array(
"foo" => "Doctrine\Tests\ORM\Mapping\CTIFoo",
"bar" => "Doctrine\Tests\ORM\Mapping\CTIBar",
"baz" => "Doctrine\Tests\ORM\Mapping\CTIBaz",
);
$this->assertEquals(3, count($class->discriminatorMap));
$this->assertEquals($expectedMap, $class->discriminatorMap);
}
2011-12-11 17:24:38 +04:00
public function testIdentifierWithAssociationKey()
{
$driver = $this->_loadDriver();
$em = $this->_getTestEntityManager();
$factory = new \Doctrine\ORM\Mapping\ClassMetadataFactory();
$em->getConfiguration()->setMetadataDriverImpl($driver);
$factory->setEntityManager($em);
$class = $factory->getMetadataFor('Doctrine\Tests\Models\DDC117\DDC117Translation');
$this->assertEquals(array('language', 'article'), $class->identifier);
$this->assertArrayHasKey('article', $class->associationMappings);
$this->assertArrayHasKey('id', $class->associationMappings['article']);
$this->assertTrue($class->associationMappings['article']['id']);
}
2011-12-15 23:12:01 +04:00
/**
* @group DDC-1468
2011-12-20 01:56:19 +04:00
*
* @expectedException Doctrine\Common\Persistence\Mapping\MappingException
2011-12-15 23:12:01 +04:00
* @expectedExceptionMessage Invalid mapping file 'Doctrine.Tests.Models.Generic.SerializationModel.dcm.xml' for class 'Doctrine\Tests\Models\Generic\SerializationModel'.
*/
public function testInvalidMappingFileException()
{
$this->createClassMetadata('Doctrine\Tests\Models\Generic\SerializationModel');
}
/**
* @param string $xmlMappingFile
* @dataProvider dataValidSchema
*/
public function testValidateXmlSchema($xmlMappingFile)
{
$xsdSchemaFile = __DIR__ . "/../../../../../doctrine-mapping.xsd";
$dom = new \DOMDocument('UTF-8');
$dom->load($xmlMappingFile);
$this->assertTrue($dom->schemaValidate($xsdSchemaFile));
}
static public function dataValidSchema()
{
return array(
array(__DIR__ . "/xml/Doctrine.Tests.ORM.Mapping.CTI.dcm.xml"),
array(__DIR__ . "/xml/Doctrine.Tests.ORM.Mapping.User.dcm.xml"),
array(__DIR__ . "/xml/CatNoId.dcm.xml"),
);
}
/**
* @group DDC-889
* @expectedException Doctrine\Common\Persistence\Mapping\MappingException
* @expectedExceptionMessage Invalid mapping file 'Doctrine.Tests.Models.DDC889.DDC889Class.dcm.xml' for class 'Doctrine\Tests\Models\DDC889\DDC889Class'.
*/
public function testinvalidEntityOrMappedSuperClassShouldMentionParentClasses()
{
$this->createClassMetadata('Doctrine\Tests\Models\DDC889\DDC889Class');
}
}
class CTI
{
public $id;
}
class CTIFoo extends CTI {}
class CTIBar extends CTI {}
class CTIBaz extends CTI {}