f4cde163a085b156f34451a42fe3cdf4a8ff51ba
[Packages/TYPO3.CMS.git] / typo3 / sysext / extbase / Tests / Unit / Persistence / PersistenceManagerTest.php
1 <?php
2 namespace TYPO3\CMS\Extbase\Tests\Unit\Persistence;
3
4 /***************************************************************
5 * Copyright notice
6 *
7 * (c) 2012 Nico de Haen
8 * All rights reserved
9 *
10 * This class is a backport of the corresponding class of FLOW3.
11 * All credits go to the v5 team.
12 *
13 * This script is part of the TYPO3 project. The TYPO3 project is
14 * free software; you can redistribute it and/or modify
15 * it under the terms of the GNU General Public License as published by
16 * the Free Software Foundation; either version 2 of the License, or
17 * (at your option) any later version.
18 *
19 * The GNU General Public License can be found at
20 * http://www.gnu.org/copyleft/gpl.html.
21 *
22 * This script is distributed in the hope that it will be useful,
23 * but WITHOUT ANY WARRANTY; without even the implied warranty of
24 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
25 * GNU General Public License for more details.
26 *
27 * This copyright notice MUST APPEAR in all copies of the script!
28 ***************************************************************/
29
30 class PersistenceManagerTest extends \TYPO3\CMS\Extbase\Tests\Unit\BaseTestCase {
31
32 /**
33 * @test
34 *
35 * This test and the related Fixtures TxDomainModelTestEntity and
36 * TxDomainRepositoryTestEntityRepository can be removed if we do not need to support
37 * underscore class names instead of namespaced class names
38 */
39 public function persistAllAddsReconstitutedObjectFromSessionToBackendsAggregateRootObjects() {
40 eval ('
41 class Foo_Bar_Domain_Model_BazFixture extends \\TYPO3\\CMS\\Extbase\\DomainObject\\AbstractEntity {}
42 ');
43 eval ('
44 class Foo_Bar_Domain_Repository_BazFixtureRepository {}
45 ');
46
47 $persistenceSession = new \TYPO3\CMS\Extbase\Persistence\Generic\Session();
48 $aggregateRootObjects = new \TYPO3\CMS\Extbase\Persistence\ObjectStorage();
49 $entity1 = new \Foo_Bar_Domain_Model_BazFixture();
50 $aggregateRootObjects->attach($entity1);
51 $persistenceSession->registerReconstitutedObject($entity1);
52 $mockTypo3DbBackend = $this->getMock($this->buildAccessibleProxy('TYPO3\\CMS\\Extbase\\Persistence\\Generic\\Storage\\Typo3DbBackend'), array('commit','setAggregateRootObjects','setDeletedObjects'), array(), '', FALSE);
53 $persistenceManager = $this->getMock($this->buildAccessibleProxy('TYPO3\\CMS\\Extbase\\Persistence\\Generic\\PersistenceManager'), array('dummy'),array(), '', FALSE);
54 $mockTypo3DbBackend->expects($this->once())
55 ->method('setAggregateRootObjects')
56 ->with($this->equalTo($aggregateRootObjects));
57 $persistenceManager->_set('backend',$mockTypo3DbBackend);
58 $persistenceManager->injectSession($persistenceSession);
59 $persistenceManager->persistAll();
60 }
61
62 /**
63 * @test
64 */
65 public function persistAllAddsNamespacedReconstitutedObjectFromSessionToBackendsAggregateRootObjects() {
66 eval ('
67 namespace Foo\\Bar\\Domain\\Model;
68 class BazFixture extends \\TYPO3\\CMS\\Extbase\\DomainObject\\AbstractEntity {}
69 ');
70 eval ('
71 namespace Foo\\Bar\\Domain\\Repository;
72 class BazFixtureRepository {}
73 ');
74
75 $persistenceSession = new \TYPO3\CMS\Extbase\Persistence\Generic\Session();
76 $aggregateRootObjects = new \TYPO3\CMS\Extbase\Persistence\ObjectStorage();
77 $entity1 = new \Foo\Bar\Domain\Model\BazFixture();
78 $aggregateRootObjects->attach($entity1);
79 $persistenceSession->registerReconstitutedObject($entity1);
80 $mockTypo3DbBackend = $this->getMock($this->buildAccessibleProxy('TYPO3\\CMS\\Extbase\\Persistence\\Generic\\Storage\\Typo3DbBackend'), array('commit','setAggregateRootObjects','setDeletedObjects'), array(), '', FALSE);
81 $persistenceManager = $this->getMock($this->buildAccessibleProxy('TYPO3\\CMS\\Extbase\\Persistence\\Generic\\PersistenceManager'), array('dummy'),array(), '', FALSE);
82 $mockTypo3DbBackend->expects($this->once())
83 ->method('setAggregateRootObjects')
84 ->with($this->equalTo($aggregateRootObjects));
85 $persistenceManager->_set('backend',$mockTypo3DbBackend);
86 $persistenceManager->injectSession($persistenceSession);
87 $persistenceManager->persistAll();
88 }
89
90 /**
91 * @test
92 */
93 public function persistAllAddsRemovedObjectsFromRepositoriesToBackendsDeletedObjects() {
94 $this->markTestIncomplete();
95 }
96
97 /**
98 * @test
99 */
100 public function persistAllAddsAddedObjectsFromRepositoriesToBackendsAggregateRootObjects() {
101 $this->markTestIncomplete();
102 }
103
104 }
105 ?>