1
0
mirror of synced 2025-01-18 14:31:40 +03:00

tests for default strategy

This commit is contained in:
Fabio B. Silva 2012-05-30 15:28:03 -03:00
parent 9f297c3140
commit 2b4c29e4f2
2 changed files with 80 additions and 15 deletions

View File

@ -32,17 +32,31 @@ namespace Doctrine\ORM\Mapping;
class DefaultQuoteStrategy extends QuoteStrategy class DefaultQuoteStrategy extends QuoteStrategy
{ {
/**
* Checks if the given identifier is quoted
*
* @param string $identifier
* @return string
*/
public function isQuotedIdentifier($identifier) public function isQuotedIdentifier($identifier)
{ {
return strlen($identifier) > 0 && $identifier[0] === '`'; return strlen($identifier) > 0 && $identifier[0] === '`';
} }
/**
* Gets the uquoted column name.
*
* @param string $identifier
* @return string
*/
public function getUnquotedIdentifier($identifier) public function getUnquotedIdentifier($identifier)
{ {
return trim($identifier, '`'); return trim($identifier, '`');
} }
/** /**
* Gets the (possibly quoted) column name for safe use in an SQL statement.
*
* @param string $fieldName * @param string $fieldName
* @param ClassMetadata $class * @param ClassMetadata $class
* @return string * @return string
@ -55,8 +69,7 @@ class DefaultQuoteStrategy extends QuoteStrategy
} }
/** /**
* Gets the (possibly quoted) primary table name of this class for safe use * Gets the (possibly quoted) primary table name for safe use in an SQL statement.
* in an SQL statement.
* *
* @param ClassMetadata $class * @param ClassMetadata $class
* @return string * @return string
@ -93,7 +106,7 @@ class DefaultQuoteStrategy extends QuoteStrategy
$quotedColumnNames = array(); $quotedColumnNames = array();
foreach ($class->identifier as $fieldName) { foreach ($class->identifier as $fieldName) {
if (isset($this->fieldMappings[$fieldName])) { if (isset($class->fieldMappings[$fieldName])) {
$quotedColumnNames[] = $this->getColumnName($fieldName, $class); $quotedColumnNames[] = $this->getColumnName($fieldName, $class);
continue; continue;
@ -118,8 +131,10 @@ class DefaultQuoteStrategy extends QuoteStrategy
} }
/** /**
* Gets the column alias.
*
* @param string $columnName * @param string $columnName
* @param string $counter * @param integer $counter
* @param ClassMetadata $class * @param ClassMetadata $class
* @return string * @return string
*/ */

View File

@ -9,7 +9,7 @@ use Doctrine\ORM\Mapping\ClassMetadata;
require_once __DIR__ . '/../../TestInit.php'; require_once __DIR__ . '/../../TestInit.php';
/** /**
* @group DDC-1719 * @group DDC-1845
*/ */
class QuoteStrategyTest extends \Doctrine\Tests\OrmTestCase class QuoteStrategyTest extends \Doctrine\Tests\OrmTestCase
{ {
@ -78,20 +78,19 @@ class QuoteStrategyTest extends \Doctrine\Tests\OrmTestCase
public function testJoinTableName() public function testJoinTableName()
{ {
$cm = $this->createClassMetadata('Doctrine\Tests\Models\CMS\CmsAddress'); $cm1 = $this->createClassMetadata('Doctrine\Tests\Models\CMS\CmsAddress');
$cm->mapManyToMany(array( $cm2 = $this->createClassMetadata('Doctrine\Tests\Models\CMS\CmsAddress');
$cm1->mapManyToMany(array(
'fieldName' => 'user', 'fieldName' => 'user',
'targetEntity' => 'CmsUser', 'targetEntity' => 'CmsUser',
'inversedBy' => 'users', 'inversedBy' => 'users',
'joinTable' => array( 'joinTable' => array(
'name' => '`cmsaddress_cmsuser`' 'name' => '`cmsaddress_cmsuser`'
) )
) ));
);
$this->assertEquals('"cmsaddress_cmsuser"', $this->strategy->getJoinTableName('user', $cm));
$cm = $this->createClassMetadata('Doctrine\Tests\Models\CMS\CmsAddress'); $cm2->mapManyToMany(array(
$cm->mapManyToMany(array(
'fieldName' => 'user', 'fieldName' => 'user',
'targetEntity' => 'CmsUser', 'targetEntity' => 'CmsUser',
'inversedBy' => 'users', 'inversedBy' => 'users',
@ -100,7 +99,58 @@ class QuoteStrategyTest extends \Doctrine\Tests\OrmTestCase
) )
) )
); );
$this->assertEquals('cmsaddress_cmsuser', $this->strategy->getJoinTableName('user', $cm));
$this->assertEquals('"cmsaddress_cmsuser"', $this->strategy->getJoinTableName('user', $cm1));
$this->assertEquals('cmsaddress_cmsuser', $this->strategy->getJoinTableName('user', $cm2));
} }
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',
));
$this->assertEquals(array('"id"'), $this->strategy->getIdentifierColumnNames($cm1));
$this->assertEquals(array('id'), $this->strategy->getIdentifierColumnNames($cm2));
}
public function testColumnAlias()
{
$i = 0;
$this->assertEquals('columnName0', $this->strategy->getColumnAlias('columnName', $i++));
$this->assertEquals('column_name1', $this->strategy->getColumnAlias('column_name', $i++));
$this->assertEquals('COLUMN_NAME2', $this->strategy->getColumnAlias('COLUMN_NAME', $i++));
$this->assertEquals('COLUMNNAME3', $this->strategy->getColumnAlias('COLUMN-NAME-', $i++));
}
public function testQuoteJoinColumnNames()
{
$this->markTestIncomplete();
$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`'
)),
));
$this->assertEquals(array('"article"'), $this->strategy->getIdentifierColumnNames($cm));
}
} }