1
0
mirror of synced 2024-12-13 22:56:04 +03:00
doctrine2/tests/Doctrine/Tests/ORM/Mapping/QuoteStrategyTest.php

197 lines
7.0 KiB
PHP
Raw Normal View History

2012-05-11 04:18:09 +04:00
<?php
namespace Doctrine\Tests\ORM\Mapping;
use Doctrine\ORM\Mapping\DefaultQuoteStrategy;
use Doctrine\ORM\Mapping\QuoteStrategy;
use Doctrine\ORM\Mapping\ClassMetadata;
require_once __DIR__ . '/../../TestInit.php';
/**
2012-05-30 22:28:03 +04:00
* @group DDC-1845
2012-05-11 04:18:09 +04:00
*/
class QuoteStrategyTest extends \Doctrine\Tests\OrmTestCase
{
/**
* @var \Doctrine\ORM\Mapping\DefaultQuoteStrategy
*/
private $strategy;
2012-06-12 03:14:17 +04:00
/**
* @var \Doctrine\DBAL\Platforms\AbstractPlatform
*/
private $platform;
2012-05-11 04:18:09 +04:00
protected function setUp()
{
parent::setUp();
$em = $this->_getTestEntityManager();
2012-06-12 03:14:17 +04:00
$this->platform = $em->getConnection()->getDatabasePlatform();
$this->strategy = new DefaultQuoteStrategy();
2012-05-11 04:18:09 +04:00
}
/**
* @param string $className
* @return \Doctrine\ORM\Mapping\ClassMetadata
*/
private function createClassMetadata($className)
{
$cm = new ClassMetadata($className);
$cm->initializeReflection(new \Doctrine\Common\Persistence\Mapping\RuntimeReflectionService);
return $cm;
}
2012-06-12 16:47:40 +04:00
public function testConfiguration()
{
$em = $this->_getTestEntityManager();
$config = $em->getConfiguration();
$this->assertInstanceOf('Doctrine\ORM\Mapping\QuoteStrategy', $config->getQuoteStrategy());
$this->assertInstanceOf('Doctrine\ORM\Mapping\DefaultQuoteStrategy', $config->getQuoteStrategy());
$config->setQuoteStrategy(new MyQuoteStrategy());
$this->assertInstanceOf('Doctrine\ORM\Mapping\QuoteStrategy', $config->getQuoteStrategy());
$this->assertInstanceOf('Doctrine\Tests\ORM\Mapping\MyQuoteStrategy', $config->getQuoteStrategy());
}
2012-05-11 04:18:09 +04:00
public function testGetColumnName()
{
$cm = $this->createClassMetadata('Doctrine\Tests\Models\CMS\CmsUser');
$cm->mapField(array('fieldName' => 'name', 'columnName' => '`name`'));
$cm->mapField(array('fieldName' => 'id', 'columnName' => 'id'));
2012-06-12 03:14:17 +04:00
$this->assertEquals('id' ,$this->strategy->getColumnName('id', $cm, $this->platform));
$this->assertEquals('"name"' ,$this->strategy->getColumnName('name', $cm, $this->platform));
2012-05-11 04:18:09 +04:00
}
public function testGetTableName()
{
$cm = $this->createClassMetadata('Doctrine\Tests\Models\CMS\CmsUser');
$cm->setPrimaryTable(array('name'=>'`cms_user`'));
2012-06-12 03:14:17 +04:00
$this->assertEquals('"cms_user"' ,$this->strategy->getTableName($cm, $this->platform));
2012-05-11 04:18:09 +04:00
$cm = new ClassMetadata('Doctrine\Tests\Models\CMS\CmsUser');
$cm->initializeReflection(new \Doctrine\Common\Persistence\Mapping\RuntimeReflectionService);
$cm->setPrimaryTable(array('name'=>'cms_user'));
2012-06-12 03:14:17 +04:00
$this->assertEquals('cms_user' ,$this->strategy->getTableName($cm, $this->platform));
2012-05-11 04:18:09 +04:00
}
public function testJoinTableName()
{
2012-05-30 22:28:03 +04:00
$cm1 = $this->createClassMetadata('Doctrine\Tests\Models\CMS\CmsAddress');
$cm2 = $this->createClassMetadata('Doctrine\Tests\Models\CMS\CmsAddress');
$cm1->mapManyToMany(array(
2012-05-11 04:18:09 +04:00
'fieldName' => 'user',
'targetEntity' => 'CmsUser',
'inversedBy' => 'users',
'joinTable' => array(
2012-05-30 22:28:03 +04:00
'name' => '`cmsaddress_cmsuser`'
2012-05-11 04:18:09 +04:00
)
2012-05-30 22:28:03 +04:00
));
2012-05-11 04:18:09 +04:00
2012-05-30 22:28:03 +04:00
$cm2->mapManyToMany(array(
2012-05-11 04:18:09 +04:00
'fieldName' => 'user',
'targetEntity' => 'CmsUser',
'inversedBy' => 'users',
'joinTable' => array(
'name' => 'cmsaddress_cmsuser'
)
)
);
2012-06-12 03:14:17 +04:00
$this->assertEquals('"cmsaddress_cmsuser"', $this->strategy->getJoinTableName($cm1->associationMappings['user'], $cm1, $this->platform));
$this->assertEquals('cmsaddress_cmsuser', $this->strategy->getJoinTableName($cm2->associationMappings['user'], $cm2, $this->platform));
2012-05-30 22:28:03 +04:00
}
public function testIdentifierColumnNames()
{
$cm1 = $this->createClassMetadata('Doctrine\Tests\Models\CMS\CmsAddress');
$cm2 = $this->createClassMetadata('Doctrine\Tests\Models\CMS\CmsAddress');
$cm1->mapField(array(
'id' => true,
'fieldName' => 'id',
'columnName' => '`id`',
));
$cm2->mapField(array(
'id' => true,
'fieldName' => 'id',
'columnName' => 'id',
));
2012-06-12 03:14:17 +04:00
$this->assertEquals(array('"id"'), $this->strategy->getIdentifierColumnNames($cm1, $this->platform));
$this->assertEquals(array('id'), $this->strategy->getIdentifierColumnNames($cm2, $this->platform));
2012-05-30 22:28:03 +04:00
}
public function testColumnAlias()
{
$i = 0;
2012-06-12 03:14:17 +04:00
$this->assertEquals('columnName0', $this->strategy->getColumnAlias('columnName', $i++, $this->platform));
$this->assertEquals('column_name1', $this->strategy->getColumnAlias('column_name', $i++, $this->platform));
$this->assertEquals('COLUMN_NAME2', $this->strategy->getColumnAlias('COLUMN_NAME', $i++, $this->platform));
$this->assertEquals('COLUMNNAME3', $this->strategy->getColumnAlias('COLUMN-NAME-', $i++, $this->platform));
2012-05-30 22:28:03 +04:00
}
public function testQuoteIdentifierJoinColumns()
2012-05-30 22:28:03 +04:00
{
$cm = $this->createClassMetadata('Doctrine\Tests\Models\DDC117\DDC117ArticleDetails');
$cm->mapOneToOne(array(
'id' => true,
'fieldName' => 'article',
'targetEntity' => 'Doctrine\Tests\Models\DDC117\DDC117Article',
'joinColumns' => array(array(
'name' => '`article`'
)),
));
2012-06-12 03:14:17 +04:00
$this->assertEquals(array('"article"'), $this->strategy->getIdentifierColumnNames($cm, $this->platform));
2012-05-11 04:18:09 +04:00
}
public function testJoinColumnName()
{
$cm = $this->createClassMetadata('Doctrine\Tests\Models\DDC117\DDC117ArticleDetails');
$cm->mapOneToOne(array(
'id' => true,
'fieldName' => 'article',
'targetEntity' => 'Doctrine\Tests\Models\DDC117\DDC117Article',
'joinColumns' => array(array(
'name' => '`article`'
)),
));
$joinColumn = $cm->associationMappings['article']['joinColumns'][0];
2012-06-12 03:14:17 +04:00
$this->assertEquals('"article"',$this->strategy->getJoinColumnName($joinColumn, $cm, $this->platform));
}
public function testReferencedJoinColumnName()
{
$cm = $this->createClassMetadata('Doctrine\Tests\Models\DDC117\DDC117ArticleDetails');
$cm->mapOneToOne(array(
'id' => true,
'fieldName' => 'article',
'targetEntity' => 'Doctrine\Tests\Models\DDC117\DDC117Article',
'joinColumns' => array(array(
'name' => '`article`'
)),
));
$joinColumn = $cm->associationMappings['article']['joinColumns'][0];
2012-06-12 03:14:17 +04:00
$this->assertEquals('"id"',$this->strategy->getReferencedJoinColumnName($joinColumn, $cm, $this->platform));
}
2012-06-12 16:47:40 +04:00
}
class MyQuoteStrategy extends \Doctrine\ORM\Mapping\DefaultQuoteStrategy
{
2012-05-11 04:18:09 +04:00
}