‪TYPO3CMS  9.5
BackendTest.php
Go to the documentation of this file.
1 <?php
2 declare(strict_types = 1);
4 
5 /*
6  * This file is part of the TYPO3 CMS project.
7  *
8  * It is free software; you can redistribute it and/or modify it under
9  * the terms of the GNU General Public License, either version 2
10  * of the License, or any later version.
11  *
12  * For the full copyright and license information, please read the
13  * LICENSE.txt file that was distributed with this source code.
14  *
15  * The TYPO3 project - inspiring people to share!
16  */
27 use TYPO3\TestingFramework\Core\Unit\UnitTestCase;
28 
32 class ‪BackendTest extends UnitTestCase
33 {
38  {
39  /* \TYPO3\CMS\Extbase\Persistence\Generic\Backend|\PHPUnit_Framework_MockObject_MockObject|\TYPO3\TestingFramework\Core\AccessibleObjectInterface */
40  $fixture = $this->getAccessibleMock(Backend::class, ['dummy'], [], '', false);
41  /* \TYPO3\CMS\Extbase\Persistence\Generic\Mapper\DataMapper|\PHPUnit_Framework_MockObject_MockObject */
42  $dataMapFactory = $this->createMock(DataMapFactory::class);
43  /* \TYPO3\CMS\Extbase\Persistence\Generic\Mapper\DataMap|\PHPUnit_Framework_MockObject_MockObject */
44  $dataMap = $this->createMock(DataMap::class);
45  /* \TYPO3\CMS\Extbase\Persistence\Generic\Mapper\ColumnMap|\PHPUnit_Framework_MockObject_MockObject */
46  $columnMap = $this->createMock(ColumnMap::class);
47  /* \TYPO3\CMS\Extbase\Persistence\Generic\Storage\BackendInterface|\PHPUnit_Framework_MockObject_MockObject */
48  $storageBackend = $this->createMock(BackendInterface::class);
49  /* \TYPO3\CMS\Extbase\DomainObject\DomainObjectInterface|\PHPUnit_Framework_MockObject_MockObject */
50  $domainObject = $this->createMock(DomainObjectInterface::class);
51 
52  $mmMatchFields = [
53  'identifier' => 'myTable:myField',
54  ];
55 
56  $expectedRow = [
57  'identifier' => 'myTable:myField',
58  '' => 0
59  ];
60 
61  $columnMap
62  ->expects($this->once())
63  ->method('getRelationTableMatchFields')
64  ->will($this->returnValue($mmMatchFields));
65  $columnMap
66  ->expects($this->any())
67  ->method('getChildSortByFieldName')
68  ->will($this->returnValue(''));
69  $dataMap
70  ->expects($this->any())
71  ->method('getColumnMap')
72  ->will($this->returnValue($columnMap));
73  $dataMapFactory
74  ->expects($this->any())
75  ->method('buildDataMap')
76  ->will($this->returnValue($dataMap));
77  $storageBackend
78  ->expects($this->once())
79  ->method('addRow')
80  ->with(null, $expectedRow, true);
81 
82  $fixture->_set('dataMapFactory', $dataMapFactory);
83  $fixture->_set('storageBackend', $storageBackend);
84  $fixture->_call('insertRelationInRelationtable', $domainObject, $domainObject, '');
85  }
86 
91  {
92  $fakeUuid = 'fakeUuid';
93  $configurationManager = $this->createMock(ConfigurationManagerInterface::class);
94  $session = $this->getMockBuilder('stdClass')
95  ->setMethods(['getIdentifierByObject'])
96  ->disableOriginalConstructor()
97  ->getMock();
98  $object = new \stdClass();
99 
100  $referenceIndexProphecy = $this->prophesize(ReferenceIndex::class);
101  GeneralUtility::addInstance(ReferenceIndex::class, $referenceIndexProphecy->reveal());
102 
103  $session->expects($this->once())->method('getIdentifierByObject')->with($object)->will($this->returnValue($fakeUuid));
104 
106  $backend = $this->getAccessibleMock(Backend::class, ['dummy'], [$configurationManager]);
107  $backend->_set('session', $session);
108 
109  $this->assertEquals($backend->getIdentifierByObject($object), $fakeUuid);
110  }
111 
116  {
117  $fakeUuid = 'fakeUuid';
118  $configurationManager = $this->createMock(ConfigurationManagerInterface::class);
119  $parentObject = new \stdClass();
120  $proxy = $this->getMockBuilder(LazyLoadingProxy::class)
121  ->setMethods(['_loadRealInstance'])
122  ->disableOriginalConstructor()
123  ->disableProxyingToOriginalMethods()
124  ->getMock();
125  $session = $this->getMockBuilder('stdClass')
126  ->setMethods(['getIdentifierByObject'])
127  ->disableOriginalConstructor()
128  ->getMock();
129  $object = new \stdClass();
130 
131  $referenceIndexProphecy = $this->prophesize(ReferenceIndex::class);
132  GeneralUtility::addInstance(ReferenceIndex::class, $referenceIndexProphecy->reveal());
133 
134  $proxy->expects($this->once())->method('_loadRealInstance')->will($this->returnValue($object));
135  $session->expects($this->once())->method('getIdentifierByObject')->with($object)->will($this->returnValue($fakeUuid));
136 
138  $backend = $this->getAccessibleMock(Backend::class, ['dummy'], [$configurationManager]);
139  $backend->_set('session', $session);
140 
141  $this->assertEquals($backend->getIdentifierByObject($proxy), $fakeUuid);
142  }
143 }
‪TYPO3\CMS\Extbase\Tests\Unit\Persistence\Generic\BackendTest\getIdentifierByObjectReturnsIdentifierForLazyObject
‪getIdentifierByObjectReturnsIdentifierForLazyObject()
Definition: BackendTest.php:115
‪TYPO3\CMS\Extbase\Persistence\Generic\Backend
Definition: Backend.php:30
‪TYPO3\CMS\Extbase\Tests\Unit\Persistence\Generic\BackendTest
Definition: BackendTest.php:33
‪TYPO3\CMS\Extbase\Persistence\Generic\Mapper\DataMap
Definition: DataMap.php:22
‪TYPO3\CMS\Core\Database\ReferenceIndex
Definition: ReferenceIndex.php:50
‪TYPO3\CMS\Extbase\Tests\Unit\Persistence\Generic\BackendTest\insertRelationInRelationtableSetsMmMatchFieldsInRow
‪insertRelationInRelationtableSetsMmMatchFieldsInRow()
Definition: BackendTest.php:37
‪TYPO3\CMS\Extbase\Persistence\Generic\Mapper\ColumnMap
Definition: ColumnMap.php:22
‪TYPO3\CMS\Extbase\Configuration\ConfigurationManagerInterface
Definition: ConfigurationManagerInterface.php:22
‪TYPO3\CMS\Extbase\Persistence\Generic\Mapper\DataMapFactory
Definition: DataMapFactory.php:24
‪TYPO3\CMS\Extbase\DomainObject\DomainObjectInterface
Definition: DomainObjectInterface.php:26
‪TYPO3\CMS\Extbase\Tests\Unit\Persistence\Generic
Definition: BackendTest.php:3
‪TYPO3\CMS\Extbase\Persistence\Generic\LazyLoadingProxy
Definition: LazyLoadingProxy.php:28
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:45
‪TYPO3\CMS\Extbase\Tests\Unit\Persistence\Generic\BackendTest\getIdentifierByObjectReturnsIdentifierForNonLazyObject
‪getIdentifierByObjectReturnsIdentifierForNonLazyObject()
Definition: BackendTest.php:90
‪TYPO3\CMS\Extbase\Persistence\Generic\Storage\BackendInterface
Definition: BackendInterface.php:21