Rajout de doctrine/orm
[zf2.biz/galerie.git] / vendor / doctrine / orm / tests / Doctrine / Tests / ORM / Persisters / BasicEntityPersisterTypeValueSqlTest.php
1 <?php
2
3 namespace Doctrine\Tests\ORM\Persisters;
4
5 use Doctrine\DBAL\Types\Type as DBALType;
6 use Doctrine\ORM\Persisters\BasicEntityPersister;
7 use Doctrine\Tests\Models\CustomType\CustomTypeParent;
8 use Doctrine\Tests\Models\CustomType\CustomTypeChild;
9 use Doctrine\Tests\Models\CustomType\CustomTypeFriend;
10
11 require_once __DIR__ . '/../../TestInit.php';
12
13 class BasicEntityPersisterTypeValueSqlTest extends \Doctrine\Tests\OrmTestCase
14 {
15     protected $_persister;
16     protected $_em;
17
18     protected function setUp()
19     {
20         parent::setUp();
21
22         if (DBALType::hasType('negative_to_positive')) {
23             DBALType::overrideType('negative_to_positive', '\Doctrine\Tests\DbalTypes\NegativeToPositiveType');
24         } else {
25             DBALType::addType('negative_to_positive', '\Doctrine\Tests\DbalTypes\NegativeToPositiveType');
26         }
27
28         if (DBALType::hasType('upper_case_string')) {
29             DBALType::overrideType('upper_case_string', '\Doctrine\Tests\DbalTypes\UpperCaseStringType');
30         } else {
31             DBALType::addType('upper_case_string', '\Doctrine\Tests\DbalTypes\UpperCaseStringType');
32         }
33
34         $this->_em = $this->_getTestEntityManager();
35
36         $this->_persister = new BasicEntityPersister($this->_em, $this->_em->getClassMetadata("Doctrine\Tests\Models\CustomType\CustomTypeParent"));
37     }
38
39     public function testGetInsertSQLUsesTypeValuesSQL()
40     {
41         $method = new \ReflectionMethod($this->_persister, '_getInsertSQL');
42         $method->setAccessible(true);
43
44         $sql = $method->invoke($this->_persister);
45
46         $this->assertEquals('INSERT INTO customtype_parents (customInteger, child_id) VALUES (ABS(?), ?)', $sql);
47     }
48
49     public function testUpdateUsesTypeValuesSQL()
50     {
51         $child = new CustomTypeChild();
52
53         $parent = new CustomTypeParent();
54         $parent->customInteger = 1;
55         $parent->child = $child;
56
57         $this->_em->getUnitOfWork()->registerManaged($parent, array('id' => 1), array('customInteger' => 0, 'child' => null));
58         $this->_em->getUnitOfWork()->registerManaged($child, array('id' => 1), array());
59
60         $this->_em->getUnitOfWork()->propertyChanged($parent, 'customInteger', 0, 1);
61         $this->_em->getUnitOfWork()->propertyChanged($parent, 'child', null, $child);
62
63         $this->_persister->update($parent);
64
65         $executeUpdates = $this->_em->getConnection()->getExecuteUpdates();
66
67         $this->assertEquals('UPDATE customtype_parents SET customInteger = ABS(?), child_id = ? WHERE id = ?', $executeUpdates[0]['query']);
68     }
69
70     public function testGetSelectConditionSQLUsesTypeValuesSQL()
71     {
72         $method = new \ReflectionMethod($this->_persister, '_getSelectConditionSQL');
73         $method->setAccessible(true);
74
75         $sql = $method->invoke($this->_persister,  array('customInteger' => 1, 'child' => 1));
76
77         $this->assertEquals('t0.customInteger = ABS(?) AND t0.child_id = ?', $sql);
78     }
79
80     /**
81      * @group DDC-1719
82      */
83     public function testStripNonAlphanumericCharactersFromSelectColumnListSQL()
84     {
85         $persister  = new BasicEntityPersister($this->_em, $this->_em->getClassMetadata('Doctrine\Tests\Models\Quote\SimpleEntity'));
86         $method     = new \ReflectionMethod($persister, '_getSelectColumnListSQL');
87         $method->setAccessible(true);
88
89         $this->assertEquals('t0."simple-entity-id" AS simpleentityid1, t0."simple-entity-value" AS simpleentityvalue2', $method->invoke($persister));
90     }
91 }