[TASK] Tests for Persistence\Generic\Backend::getIdentifierByObject 40/24440/4
authorStefan Neufeind <typo3.neufeind@speedpartner.de>
Sun, 6 Oct 2013 23:13:28 +0000 (01:13 +0200)
committerChristian Kuhn <lolli@schwarzbu.ch>
Thu, 17 Oct 2013 19:53:52 +0000 (21:53 +0200)
Change-Id: Idb00a92469672e907286024ec461f0b8ee98c6c9
Resolves: #52570
Releases: 6.1, 6.2
Reviewed-on: https://review.typo3.org/24440
Reviewed-by: Marc Bastian Heinrichs
Tested-by: Marc Bastian Heinrichs
Reviewed-by: Christian Kuhn
Tested-by: Christian Kuhn
typo3/sysext/extbase/Tests/Unit/Persistence/Generic/BackendTest.php

index 5a477e1..8935e99 100644 (file)
@@ -96,4 +96,43 @@ class BackendTest extends \TYPO3\CMS\Extbase\Tests\Unit\BaseTestCase {
                $this->assertEquals('2013-04-15', $fixture->_call('getPlainValue', $input, $columnMap));
        }
 
+       /**
+        * @test
+        */
+       public function getIdentifierByObjectReturnsIdentifierForNonlazyObject() {
+               $fakeUuid = 'fakeUuid';
+               $configurationManager = $this->getMock('TYPO3\\CMS\\Extbase\\Configuration\\ConfigurationManagerInterface');
+               $session = $this->getMock('stdClass', array('getIdentifierByObject'), array(), '', FALSE);
+               $object = new \stdClass();
+
+               $session->expects($this->once())->method('getIdentifierByObject')->with($object)->will($this->returnValue($fakeUuid));
+
+               /** @var \TYPO3\CMS\Extbase\Persistence\Generic\Backend $backend */
+               $backend = $this->getAccessibleMock('TYPO3\\CMS\\Extbase\\Persistence\\Generic\\Backend', array('dummy'), array($configurationManager));
+               $backend->_set('session', $session);
+
+               $this->assertEquals($backend->getIdentifierByObject($object), $fakeUuid);
+       }
+
+       /**
+        * @test
+        */
+       public function getIdentifierByObjectReturnsIdentifierForLazyObject() {
+               $fakeUuid = 'fakeUuid';
+               $configurationManager = $this->getMock('TYPO3\\CMS\\Extbase\\Configuration\\ConfigurationManagerInterface');
+               $parentObject = new \stdClass();
+               $proxy = $this->getMock('TYPO3\CMS\Extbase\Persistence\Generic\LazyLoadingProxy', array('_loadRealInstance'), array($parentObject, 'y', 'z'), '', FALSE);
+               $session = $this->getMock('stdClass', array('getIdentifierByObject'), array(), '', FALSE);
+               $object = new \stdClass();
+
+               $proxy->expects($this->once())->method('_loadRealInstance')->will($this->returnValue($object));
+               $session->expects($this->once())->method('getIdentifierByObject')->with($object)->will($this->returnValue($fakeUuid));
+
+               /** @var \TYPO3\CMS\Extbase\Persistence\Generic\Backend $backend */
+               $backend = $this->getAccessibleMock('TYPO3\\CMS\\Extbase\\Persistence\\Generic\\Backend', array('dummy'), array($configurationManager));
+               $backend->_set('session', $session);
+
+               $this->assertEquals($backend->getIdentifierByObject($proxy), $fakeUuid);
+       }
+
 }