[BUGFIX] Namespaced domain models are not updated
authorNico de Haen <mail@ndh-websolutions.de>
Tue, 16 Oct 2012 19:44:37 +0000 (21:44 +0200)
committerHelmut Hummel <helmut.hummel@typo3.org>
Wed, 7 Nov 2012 14:36:13 +0000 (15:36 +0100)
The check to see if the session's reconstituted objects are
aggregate roots doesn't support namespaced domain models.

Fixes: #42028
Change-Id: If9ad7569087a073471522036f645a039a869e682
Reviewed-on: http://review.typo3.org/15747
Reviewed-by: Helmut Hummel
Tested-by: Helmut Hummel
typo3/sysext/extbase/Classes/Persistence/Generic/PersistenceManager.php
typo3/sysext/extbase/Tests/Unit/Persistence/PersistenceManagerTest.php [new file with mode: 0644]

index 986a746..de9ba74 100644 (file)
@@ -164,7 +164,10 @@ class PersistenceManager implements \TYPO3\CMS\Extbase\Persistence\PersistenceMa
                        $removedObjects->addAll($repository->getRemovedObjects());
                }
                foreach ($this->session->getReconstitutedObjects() as $reconstitutedObject) {
-                       if (class_exists(str_replace('_Model_', '_Repository_', get_class($reconstitutedObject)) . 'Repository')) {
+                       $className = get_class($reconstitutedObject);
+                       $delimiter = strpos($className, '_') !== FALSE ? '_' : '\\';
+                       $possibleRepositoryClassName = str_replace($delimiter . 'Model' . $delimiter, $delimiter . 'Repository' . $delimiter, $className) . 'Repository';
+                       if (class_exists($possibleRepositoryClassName)) {
                                $aggregateRootObjects->attach($reconstitutedObject);
                        }
                }
@@ -306,6 +309,4 @@ class PersistenceManager implements \TYPO3\CMS\Extbase\Persistence\PersistenceMa
                throw new \TYPO3\CMS\Extbase\Persistence\Generic\Exception\NotImplementedException(__METHOD__);
        }
 }
-
-
 ?>
\ No newline at end of file
diff --git a/typo3/sysext/extbase/Tests/Unit/Persistence/PersistenceManagerTest.php b/typo3/sysext/extbase/Tests/Unit/Persistence/PersistenceManagerTest.php
new file mode 100644 (file)
index 0000000..f4cde16
--- /dev/null
@@ -0,0 +1,105 @@
+<?php
+namespace TYPO3\CMS\Extbase\Tests\Unit\Persistence;
+
+/***************************************************************
+ *  Copyright notice
+ *
+ *  (c) 2012 Nico de Haen
+ *  All rights reserved
+ *
+ *  This class is a backport of the corresponding class of FLOW3.
+ *  All credits go to the v5 team.
+ *
+ *  This script is part of the TYPO3 project. The TYPO3 project is
+ *  free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation; either version 2 of the License, or
+ *  (at your option) any later version.
+ *
+ *  The GNU General Public License can be found at
+ *  http://www.gnu.org/copyleft/gpl.html.
+ *
+ *  This script is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *  This copyright notice MUST APPEAR in all copies of the script!
+ ***************************************************************/
+
+class PersistenceManagerTest extends \TYPO3\CMS\Extbase\Tests\Unit\BaseTestCase {
+
+       /**
+        * @test
+        *
+        * This test and the related Fixtures TxDomainModelTestEntity and
+        * TxDomainRepositoryTestEntityRepository can be removed if we do not need to support
+        * underscore class names instead of namespaced class names
+        */
+       public function persistAllAddsReconstitutedObjectFromSessionToBackendsAggregateRootObjects() {
+               eval ('
+                       class Foo_Bar_Domain_Model_BazFixture extends \\TYPO3\\CMS\\Extbase\\DomainObject\\AbstractEntity {}
+               ');
+               eval ('
+                       class Foo_Bar_Domain_Repository_BazFixtureRepository {}
+               ');
+
+               $persistenceSession = new \TYPO3\CMS\Extbase\Persistence\Generic\Session();
+               $aggregateRootObjects = new \TYPO3\CMS\Extbase\Persistence\ObjectStorage();
+               $entity1 = new \Foo_Bar_Domain_Model_BazFixture();
+               $aggregateRootObjects->attach($entity1);
+               $persistenceSession->registerReconstitutedObject($entity1);
+               $mockTypo3DbBackend = $this->getMock($this->buildAccessibleProxy('TYPO3\\CMS\\Extbase\\Persistence\\Generic\\Storage\\Typo3DbBackend'), array('commit','setAggregateRootObjects','setDeletedObjects'), array(), '', FALSE);
+               $persistenceManager = $this->getMock($this->buildAccessibleProxy('TYPO3\\CMS\\Extbase\\Persistence\\Generic\\PersistenceManager'), array('dummy'),array(), '', FALSE);
+               $mockTypo3DbBackend->expects($this->once())
+                                                ->method('setAggregateRootObjects')
+                                                ->with($this->equalTo($aggregateRootObjects));
+               $persistenceManager->_set('backend',$mockTypo3DbBackend);
+               $persistenceManager->injectSession($persistenceSession);
+               $persistenceManager->persistAll();
+       }
+
+       /**
+        * @test
+        */
+       public function persistAllAddsNamespacedReconstitutedObjectFromSessionToBackendsAggregateRootObjects() {
+               eval ('
+                       namespace Foo\\Bar\\Domain\\Model;
+                       class BazFixture extends \\TYPO3\\CMS\\Extbase\\DomainObject\\AbstractEntity {}
+               ');
+               eval ('
+                       namespace Foo\\Bar\\Domain\\Repository;
+                       class BazFixtureRepository {}
+               ');
+
+               $persistenceSession = new \TYPO3\CMS\Extbase\Persistence\Generic\Session();
+               $aggregateRootObjects = new \TYPO3\CMS\Extbase\Persistence\ObjectStorage();
+               $entity1 = new \Foo\Bar\Domain\Model\BazFixture();
+               $aggregateRootObjects->attach($entity1);
+               $persistenceSession->registerReconstitutedObject($entity1);
+               $mockTypo3DbBackend = $this->getMock($this->buildAccessibleProxy('TYPO3\\CMS\\Extbase\\Persistence\\Generic\\Storage\\Typo3DbBackend'), array('commit','setAggregateRootObjects','setDeletedObjects'), array(), '', FALSE);
+               $persistenceManager = $this->getMock($this->buildAccessibleProxy('TYPO3\\CMS\\Extbase\\Persistence\\Generic\\PersistenceManager'), array('dummy'),array(), '', FALSE);
+               $mockTypo3DbBackend->expects($this->once())
+                                                ->method('setAggregateRootObjects')
+                                                ->with($this->equalTo($aggregateRootObjects));
+               $persistenceManager->_set('backend',$mockTypo3DbBackend);
+               $persistenceManager->injectSession($persistenceSession);
+               $persistenceManager->persistAll();
+       }
+
+       /**
+        * @test
+        */
+       public function persistAllAddsRemovedObjectsFromRepositoriesToBackendsDeletedObjects() {
+               $this->markTestIncomplete();
+       }
+
+       /**
+        * @test
+        */
+       public function persistAllAddsAddedObjectsFromRepositoriesToBackendsAggregateRootObjects() {
+               $this->markTestIncomplete();
+       }
+
+}
+?>
\ No newline at end of file