2010-02-02 00:48:27 +03:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace Doctrine\Tests\ORM\Mapping;
|
|
|
|
|
2014-06-19 17:53:11 +04:00
|
|
|
use Doctrine\ORM\Mapping\ClassMetadata;
|
|
|
|
use Doctrine\ORM\Mapping\ClassMetadataFactory;
|
|
|
|
use Doctrine\ORM\Mapping\Driver\XmlDriver;
|
2010-02-02 00:48:27 +03:00
|
|
|
|
|
|
|
class XmlMappingDriverTest extends AbstractMappingDriverTest
|
|
|
|
{
|
|
|
|
protected function _loadDriver()
|
|
|
|
{
|
|
|
|
return new XmlDriver(__DIR__ . DIRECTORY_SEPARATOR . 'xml');
|
|
|
|
}
|
2010-02-24 22:31:53 +03:00
|
|
|
|
|
|
|
public function testClassTableInheritanceDiscriminatorMap()
|
|
|
|
{
|
|
|
|
$className = 'Doctrine\Tests\ORM\Mapping\CTI';
|
|
|
|
$mappingDriver = $this->_loadDriver();
|
|
|
|
|
|
|
|
$class = new ClassMetadata($className);
|
2012-01-02 20:06:22 +04:00
|
|
|
$class->initializeReflection(new \Doctrine\Common\Persistence\Mapping\RuntimeReflectionService);
|
2010-02-24 22:31:53 +03:00
|
|
|
$mappingDriver->loadMetadataForClass($className, $class);
|
|
|
|
|
|
|
|
$expectedMap = array(
|
2014-06-19 17:54:43 +04:00
|
|
|
'foo' => 'Doctrine\Tests\ORM\Mapping\CTIFoo',
|
|
|
|
'bar' => 'Doctrine\Tests\ORM\Mapping\CTIBar',
|
|
|
|
'baz' => 'Doctrine\Tests\ORM\Mapping\CTIBaz',
|
2010-02-24 22:31:53 +03:00
|
|
|
);
|
|
|
|
|
|
|
|
$this->assertEquals(3, count($class->discriminatorMap));
|
|
|
|
$this->assertEquals($expectedMap, $class->discriminatorMap);
|
|
|
|
}
|
2010-06-13 19:21:14 +04:00
|
|
|
|
2011-12-11 17:24:38 +04:00
|
|
|
public function testIdentifierWithAssociationKey()
|
|
|
|
{
|
|
|
|
$driver = $this->_loadDriver();
|
|
|
|
$em = $this->_getTestEntityManager();
|
2013-12-07 19:40:54 +04:00
|
|
|
$factory = new ClassMetadataFactory();
|
2011-12-11 17:24:38 +04:00
|
|
|
|
|
|
|
$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']);
|
|
|
|
}
|
|
|
|
|
2013-12-07 19:40:54 +04:00
|
|
|
public function testEmbeddableMapping()
|
|
|
|
{
|
|
|
|
$class = $this->createClassMetadata('Doctrine\Tests\Models\ValueObjects\Name');
|
|
|
|
|
|
|
|
$this->assertEquals(true, $class->isEmbeddedClass);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testEmbeddedMapping()
|
|
|
|
{
|
|
|
|
$class = $this->createClassMetadata('Doctrine\Tests\Models\ValueObjects\Person');
|
|
|
|
|
|
|
|
$this->assertEquals(
|
|
|
|
array(
|
|
|
|
'name' => array(
|
|
|
|
'class' => 'Doctrine\Tests\Models\ValueObjects\Name',
|
|
|
|
'columnPrefix' => 'nm_'
|
|
|
|
)
|
|
|
|
),
|
|
|
|
$class->embeddedClasses
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2011-12-15 23:12:01 +04:00
|
|
|
/**
|
|
|
|
* @group DDC-1468
|
2011-12-20 01:56:19 +04:00
|
|
|
*
|
2012-01-17 18:39:52 +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');
|
|
|
|
}
|
|
|
|
|
2010-09-15 23:51:44 +04:00
|
|
|
/**
|
|
|
|
* @param string $xmlMappingFile
|
|
|
|
* @dataProvider dataValidSchema
|
2013-05-13 18:04:36 +04:00
|
|
|
* @group DDC-2429
|
2010-09-15 23:51:44 +04:00
|
|
|
*/
|
|
|
|
public function testValidateXmlSchema($xmlMappingFile)
|
2010-06-13 19:21:14 +04:00
|
|
|
{
|
2013-05-13 18:04:36 +04:00
|
|
|
$xsdSchemaFile = __DIR__ . '/../../../../../doctrine-mapping.xsd';
|
|
|
|
$dom = new \DOMDocument('UTF-8');
|
2010-06-13 19:21:14 +04:00
|
|
|
|
2010-09-15 23:51:44 +04:00
|
|
|
$dom->load($xmlMappingFile);
|
2013-05-13 18:04:36 +04:00
|
|
|
|
2010-06-13 19:21:14 +04:00
|
|
|
$this->assertTrue($dom->schemaValidate($xsdSchemaFile));
|
|
|
|
}
|
2010-09-15 23:51:44 +04:00
|
|
|
|
|
|
|
static public function dataValidSchema()
|
|
|
|
{
|
2013-05-13 18:04:36 +04:00
|
|
|
$list = glob(__DIR__ . '/xml/*.xml');
|
|
|
|
$invalid = array(
|
|
|
|
'Doctrine.Tests.Models.DDC889.DDC889Class.dcm'
|
2010-09-15 23:51:44 +04:00
|
|
|
);
|
2013-05-13 18:04:36 +04:00
|
|
|
|
|
|
|
$list = array_filter($list, function($item) use ($invalid){
|
|
|
|
return ! in_array(pathinfo($item, PATHINFO_FILENAME), $invalid);
|
|
|
|
});
|
|
|
|
|
|
|
|
return array_map(function($item){
|
|
|
|
return array($item);
|
|
|
|
}, $list);
|
2010-09-15 23:51:44 +04:00
|
|
|
}
|
2012-03-25 19:54:09 +04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @group DDC-889
|
2014-06-19 17:53:37 +04:00
|
|
|
* @expectedException \Doctrine\Common\Persistence\Mapping\MappingException
|
2012-03-25 19:54:09 +04:00
|
|
|
* @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');
|
|
|
|
}
|
2010-02-24 22:31:53 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
class CTI
|
|
|
|
{
|
|
|
|
public $id;
|
|
|
|
}
|
|
|
|
|
|
|
|
class CTIFoo extends CTI {}
|
|
|
|
class CTIBar extends CTI {}
|
2012-01-02 20:06:22 +04:00
|
|
|
class CTIBaz extends CTI {}
|