Rajout de doctrine/orm
[zf2.biz/galerie.git] / vendor / doctrine / orm / tests / Doctrine / Tests / ORM / Functional / CompositePrimaryKeyTest.php
1 <?php
2
3 namespace Doctrine\Tests\ORM\Functional;
4 use Doctrine\Tests\Models\Navigation\NavCountry;
5 use Doctrine\Tests\Models\Navigation\NavPointOfInterest;
6 use Doctrine\Tests\Models\Navigation\NavTour;
7 use Doctrine\Tests\Models\Navigation\NavPhotos;
8 use Doctrine\Tests\Models\Navigation\NavUser;
9
10 require_once __DIR__ . '/../../TestInit.php';
11
12 class CompositePrimaryKeyTest extends \Doctrine\Tests\OrmFunctionalTestCase
13 {
14     public function setUp()
15     {
16         $this->useModelSet('navigation');
17         parent::setUp();
18     }
19
20     public function putGermanysBrandenburderTor()
21     {
22         $country = new NavCountry("Germany");
23         $this->_em->persist($country);
24         $poi = new NavPointOfInterest(100, 200, "Brandenburger Tor", $country);
25         $this->_em->persist($poi);
26         $this->_em->flush();
27         $this->_em->clear();
28     }
29
30     public function putTripAroundEurope()
31     {
32         $poi = $this->_em->find('Doctrine\Tests\Models\Navigation\NavPointOfInterest', array('lat' => 100, 'long' => 200));
33
34         $tour = new NavTour("Trip around Europe");
35         $tour->addPointOfInterest($poi);
36
37         $this->_em->persist($tour);
38         $this->_em->flush();
39         $this->_em->clear();
40
41         return $tour;
42     }
43
44     public function testPersistCompositePkEntity()
45     {
46         $this->putGermanysBrandenburderTor();
47
48         $poi = $this->_em->find('Doctrine\Tests\Models\Navigation\NavPointOfInterest', array('lat' => 100, 'long' => 200));
49
50         $this->assertInstanceOf('Doctrine\Tests\Models\Navigation\NavPointOfInterest', $poi);
51         $this->assertEquals(100, $poi->getLat());
52         $this->assertEquals(200, $poi->getLong());
53         $this->assertEquals('Brandenburger Tor', $poi->getName());
54     }
55
56     /**
57      * @group DDC-1651
58      */
59     public function testSetParameterCompositeKeyObject()
60     {
61         $this->putGermanysBrandenburderTor();
62
63         $poi = $this->_em->find('Doctrine\Tests\Models\Navigation\NavPointOfInterest', array('lat' => 100, 'long' => 200));
64         $photo = new NavPhotos($poi, "asdf");
65         $this->_em->persist($photo);
66         $this->_em->flush();
67         $this->_em->clear();
68
69         $dql = 'SELECT t FROM Doctrine\Tests\Models\Navigation\NavPhotos t WHERE t.poi = ?1';
70
71         $this->setExpectedException('Doctrine\ORM\Query\QueryException', 'A single-valued association path expression to an entity with a composite primary key is not supported.');
72         $sql = $this->_em->createQuery($dql)->getSQL();
73     }
74
75     public function testManyToManyCompositeRelation()
76     {
77         $this->putGermanysBrandenburderTor();
78         $tour = $this->putTripAroundEurope();
79
80         $tour = $this->_em->find('Doctrine\Tests\Models\Navigation\NavTour', $tour->getId());
81
82         $this->assertEquals(1, count($tour->getPointOfInterests()));
83     }
84
85     public function testCompositeDqlEagerFetching()
86     {
87         $this->putGermanysBrandenburderTor();
88         $this->putTripAroundEurope();
89
90         $dql = 'SELECT t, p, c FROM Doctrine\Tests\Models\Navigation\NavTour t ' .
91                'INNER JOIN t.pois p INNER JOIN p.country c';
92         $tours = $this->_em->createQuery($dql)->getResult();
93
94         $this->assertEquals(1, count($tours));
95
96         $pois = $tours[0]->getPointOfInterests();
97
98         $this->assertEquals(1, count($pois));
99         $this->assertEquals('Brandenburger Tor', $pois[0]->getName());
100     }
101
102     public function testCompositeCollectionMemberExpression()
103     {
104         $this->markTestSkipped('How to test this?');
105
106         $this->putGermanysBrandenburderTor();
107         $this->putTripAroundEurope();
108
109         $dql = 'SELECT t FROM Doctrine\Tests\Models\Navigation\NavTour t, Doctrine\Tests\Models\Navigation\NavPointOfInterest p ' .
110                'WHERE p MEMBER OF t.pois';
111         $tours = $this->_em->createQuery($dql)
112                            ->getResult();
113
114         $this->assertEquals(1, count($tours));
115     }
116
117     public function testSpecifiyUnknownIdentifierPrimaryKeyFails()
118     {
119         $this->setExpectedException('Doctrine\ORM\ORMException', 'The identifier long is missing for a query of Doctrine\Tests\Models\Navigation\NavPointOfInterest');
120         $poi = $this->_em->find('Doctrine\Tests\Models\Navigation\NavPointOfInterest', array('key1' => 100));
121     }
122
123     /**
124      * @group DDC-1939
125      */
126     public function testDeleteCompositePersistentCollection()
127     {
128         $this->putGermanysBrandenburderTor();
129
130         $poi = $this->_em->find('Doctrine\Tests\Models\Navigation\NavPointOfInterest', array('lat' => 100, 'long' => 200));
131         $poi->addVisitor(new NavUser("test1"));
132         $poi->addVisitor(new NavUser("test2"));
133
134         $this->_em->flush();
135
136         $poi->getVisitors()->clear();
137
138         $this->_em->flush();
139         $this->_em->clear();
140
141         $poi = $this->_em->find('Doctrine\Tests\Models\Navigation\NavPointOfInterest', array('lat' => 100, 'long' => 200));
142         $this->assertEquals(0, count($poi->getVisitors()));
143     }
144 }