TYPO3CMS  8
 All Classes Namespaces Files Functions Variables Pages
BackendTest.php
Go to the documentation of this file.
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 
21 {
26  {
27  /* \TYPO3\CMS\Extbase\Persistence\Generic\Backend|\PHPUnit_Framework_MockObject_MockObject|\TYPO3\CMS\Core\Tests\AccessibleObjectInterface */
28  $fixture = $this->getAccessibleMock(\TYPO3\CMS\Extbase\Persistence\Generic\Backend::class, ['dummy'], [], '', false);
29  /* \TYPO3\CMS\Extbase\Persistence\Generic\Mapper\DataMapper|\PHPUnit_Framework_MockObject_MockObject */
30  $dataMapper = $this->createMock(\TYPO3\CMS\Extbase\Persistence\Generic\Mapper\DataMapper::class);
31  /* \TYPO3\CMS\Extbase\Persistence\Generic\Mapper\DataMap|\PHPUnit_Framework_MockObject_MockObject */
32  $dataMap = $this->createMock(\TYPO3\CMS\Extbase\Persistence\Generic\Mapper\DataMap::class);
33  /* \TYPO3\CMS\Extbase\Persistence\Generic\Mapper\ColumnMap|\PHPUnit_Framework_MockObject_MockObject */
34  $columnMap = $this->createMock(\TYPO3\CMS\Extbase\Persistence\Generic\Mapper\ColumnMap::class);
35  /* \TYPO3\CMS\Extbase\Persistence\Generic\Storage\BackendInterface|\PHPUnit_Framework_MockObject_MockObject */
36  $storageBackend = $this->createMock(\TYPO3\CMS\Extbase\Persistence\Generic\Storage\BackendInterface::class);
37  /* \TYPO3\CMS\Extbase\DomainObject\DomainObjectInterface|\PHPUnit_Framework_MockObject_MockObject */
38  $domainObject = $this->createMock(\TYPO3\CMS\Extbase\DomainObject\DomainObjectInterface::class);
39 
40  $mmMatchFields = [
41  'identifier' => 'myTable:myField',
42  ];
43 
44  $expectedRow = [
45  'identifier' => 'myTable:myField',
46  '' => 0
47  ];
48 
49  $columnMap
50  ->expects($this->once())
51  ->method('getRelationTableMatchFields')
52  ->will($this->returnValue($mmMatchFields));
53  $columnMap
54  ->expects($this->any())
55  ->method('getChildSortByFieldName')
56  ->will($this->returnValue(''));
57  $dataMap
58  ->expects($this->any())
59  ->method('getColumnMap')
60  ->will($this->returnValue($columnMap));
61  $dataMapper
62  ->expects($this->any())
63  ->method('getDataMap')
64  ->will($this->returnValue($dataMap));
65  $storageBackend
66  ->expects($this->once())
67  ->method('addRow')
68  ->with(null, $expectedRow, true);
69 
70  $fixture->_set('dataMapper', $dataMapper);
71  $fixture->_set('storageBackend', $storageBackend);
72  $fixture->_call('insertRelationInRelationtable', $domainObject, $domainObject, '');
73  }
74 
78  public function getIdentifierByObjectReturnsIdentifierForNonlazyObject()
79  {
80  $fakeUuid = 'fakeUuid';
81  $configurationManager = $this->createMock(\TYPO3\CMS\Extbase\Configuration\ConfigurationManagerInterface::class);
82  $session = $this->getMockBuilder('stdClass')
83  ->setMethods(['getIdentifierByObject'])
84  ->disableOriginalConstructor()
85  ->getMock();
86  $object = new \stdClass();
87 
88  $session->expects($this->once())->method('getIdentifierByObject')->with($object)->will($this->returnValue($fakeUuid));
89 
91  $backend = $this->getAccessibleMock(\TYPO3\CMS\Extbase\Persistence\Generic\Backend::class, ['dummy'], [$configurationManager]);
92  $backend->_set('session', $session);
93 
94  $this->assertEquals($backend->getIdentifierByObject($object), $fakeUuid);
95  }
96 
100  public function getIdentifierByObjectReturnsIdentifierForLazyObject()
101  {
102  $fakeUuid = 'fakeUuid';
103  $configurationManager = $this->createMock(\TYPO3\CMS\Extbase\Configuration\ConfigurationManagerInterface::class);
104  $parentObject = new \stdClass();
105  $proxy = $this->getMockBuilder(\TYPO3\CMS\Extbase\Persistence\Generic\LazyLoadingProxy::class)
106  ->setMethods(['_loadRealInstance'])
107  ->setConstructorArgs([$parentObject, 'y', 'z'])
108  ->disableProxyingToOriginalMethods()
109  ->getMock();
110  $session = $this->getMockBuilder('stdClass')
111  ->setMethods(['getIdentifierByObject'])
112  ->disableOriginalConstructor()
113  ->getMock();
114  $object = new \stdClass();
115 
116  $proxy->expects($this->once())->method('_loadRealInstance')->will($this->returnValue($object));
117  $session->expects($this->once())->method('getIdentifierByObject')->with($object)->will($this->returnValue($fakeUuid));
118 
120  $backend = $this->getAccessibleMock(\TYPO3\CMS\Extbase\Persistence\Generic\Backend::class, ['dummy'], [$configurationManager]);
121  $backend->_set('session', $session);
122 
123  $this->assertEquals($backend->getIdentifierByObject($proxy), $fakeUuid);
124  }
125 }
getAccessibleMock($originalClassName, $methods=[], array $arguments=[], $mockClassName= '', $callOriginalConstructor=true, $callOriginalClone=true, $callAutoload=true)