a1b0cf370d26acb13b4c73315e95cf8153f75cf5
[Packages/TYPO3.CMS.git] / typo3 / sysext / extbase / Tests / Unit / Persistence / Generic / BackendTest.php
1 <?php
2 namespace TYPO3\CMS\Extbase\Tests\Unit\Persistence\Generic;
3
4 /**
5 * This file is part of the TYPO3 CMS project.
6 *
7 * It is free software; you can redistribute it and/or modify it under
8 * the terms of the GNU General Public License, either version 2
9 * of the License, or any later version.
10 *
11 * For the full copyright and license information, please read the
12 * LICENSE.txt file that was distributed with this source code.
13 *
14 * The TYPO3 project - inspiring people to share!
15 */
16
17 /**
18 * Test case
19 */
20 class BackendTest extends \TYPO3\CMS\Core\Tests\UnitTestCase {
21
22 /**
23 * @test
24 */
25 public function insertRelationInRelationtableSetsMmMatchFieldsInRow() {
26 /* \TYPO3\CMS\Extbase\Persistence\Generic\Backend|\PHPUnit_Framework_MockObject_MockObject|\TYPO3\CMS\Core\Tests\AccessibleObjectInterface */
27 $fixture = $this->getAccessibleMock('TYPO3\\CMS\\Extbase\\Persistence\\Generic\\Backend', array('dummy'), array(), '', FALSE);
28 /* \TYPO3\CMS\Extbase\Persistence\Generic\Mapper\DataMapper|\PHPUnit_Framework_MockObject_MockObject */
29 $dataMapper = $this->getMock('TYPO3\\CMS\Extbase\\Persistence\\Generic\\Mapper\\DataMapper');
30 /* \TYPO3\CMS\Extbase\Persistence\Generic\Mapper\DataMap|\PHPUnit_Framework_MockObject_MockObject */
31 $dataMap = $this->getMock('TYPO3\\CMS\Extbase\\Persistence\\Generic\\Mapper\\DataMap', array(), array(), '', FALSE);
32 /* \TYPO3\CMS\Extbase\Persistence\Generic\Mapper\ColumnMap|\PHPUnit_Framework_MockObject_MockObject */
33 $columnMap = $this->getMock('TYPO3\\CMS\Extbase\\Persistence\\Generic\\Mapper\\ColumnMap', array(), array(), '', FALSE);
34 /* \TYPO3\CMS\Extbase\Persistence\Generic\Storage\BackendInterface|\PHPUnit_Framework_MockObject_MockObject */
35 $storageBackend = $this->getMock('TYPO3\\CMS\Extbase\\Persistence\\Generic\\Storage\\BackendInterface');
36 /* \TYPO3\CMS\Extbase\DomainObject\DomainObjectInterface|\PHPUnit_Framework_MockObject_MockObject */
37 $domainObject = $this->getMock('TYPO3\\CMS\Extbase\\DomainObject\\DomainObjectInterface');
38
39 $mmMatchFields = array(
40 'identifier' => 'myTable:myField',
41 );
42
43 $expectedRow = array(
44 'identifier' => 'myTable:myField',
45 '' => 0
46 );
47
48 $columnMap
49 ->expects($this->once())
50 ->method('getRelationTableMatchFields')
51 ->will($this->returnValue($mmMatchFields));
52 $columnMap
53 ->expects($this->any())
54 ->method('getChildSortByFieldName')
55 ->will($this->returnValue(''));
56 $dataMap
57 ->expects($this->any())
58 ->method('getColumnMap')
59 ->will($this->returnValue($columnMap));
60 $dataMapper
61 ->expects($this->any())
62 ->method('getDataMap')
63 ->will($this->returnValue($dataMap));
64 $storageBackend
65 ->expects($this->once())
66 ->method('addRow')
67 ->with(NULL, $expectedRow, TRUE);
68
69 $fixture->_set('dataMapper', $dataMapper);
70 $fixture->_set('storageBackend', $storageBackend);
71 $fixture->_call('insertRelationInRelationtable', $domainObject, $domainObject, '');
72 }
73
74 /**
75 * @test
76 */
77 public function getIdentifierByObjectReturnsIdentifierForNonlazyObject() {
78 $fakeUuid = 'fakeUuid';
79 $configurationManager = $this->getMock('TYPO3\\CMS\\Extbase\\Configuration\\ConfigurationManagerInterface');
80 $session = $this->getMock('stdClass', array('getIdentifierByObject'), array(), '', FALSE);
81 $object = new \stdClass();
82
83 $session->expects($this->once())->method('getIdentifierByObject')->with($object)->will($this->returnValue($fakeUuid));
84
85 /** @var \TYPO3\CMS\Extbase\Persistence\Generic\Backend $backend */
86 $backend = $this->getAccessibleMock('TYPO3\\CMS\\Extbase\\Persistence\\Generic\\Backend', array('dummy'), array($configurationManager));
87 $backend->_set('session', $session);
88
89 $this->assertEquals($backend->getIdentifierByObject($object), $fakeUuid);
90 }
91
92 /**
93 * @test
94 */
95 public function getIdentifierByObjectReturnsIdentifierForLazyObject() {
96 $fakeUuid = 'fakeUuid';
97 $configurationManager = $this->getMock('TYPO3\\CMS\\Extbase\\Configuration\\ConfigurationManagerInterface');
98 $parentObject = new \stdClass();
99 $proxy = $this->getMock('TYPO3\CMS\Extbase\Persistence\Generic\LazyLoadingProxy', array('_loadRealInstance'), array($parentObject, 'y', 'z'), '', FALSE);
100 $session = $this->getMock('stdClass', array('getIdentifierByObject'), array(), '', FALSE);
101 $object = new \stdClass();
102
103 $proxy->expects($this->once())->method('_loadRealInstance')->will($this->returnValue($object));
104 $session->expects($this->once())->method('getIdentifierByObject')->with($object)->will($this->returnValue($fakeUuid));
105
106 /** @var \TYPO3\CMS\Extbase\Persistence\Generic\Backend $backend */
107 $backend = $this->getAccessibleMock('TYPO3\\CMS\\Extbase\\Persistence\\Generic\\Backend', array('dummy'), array($configurationManager));
108 $backend->_set('session', $session);
109
110 $this->assertEquals($backend->getIdentifierByObject($proxy), $fakeUuid);
111 }
112
113 }