TYPO3 CMS  TYPO3_7-6
BackendTest.php
Go to the documentation of this file.
1 <?php
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->getMock(\TYPO3\CMS\Extbase\Persistence\Generic\Mapper\DataMapper::class);
31  /* \TYPO3\CMS\Extbase\Persistence\Generic\Mapper\DataMap|\PHPUnit_Framework_MockObject_MockObject */
32  $dataMap = $this->getMock(\TYPO3\CMS\Extbase\Persistence\Generic\Mapper\DataMap::class, [], [], '', false);
33  /* \TYPO3\CMS\Extbase\Persistence\Generic\Mapper\ColumnMap|\PHPUnit_Framework_MockObject_MockObject */
34  $columnMap = $this->getMock(\TYPO3\CMS\Extbase\Persistence\Generic\Mapper\ColumnMap::class, [], [], '', false);
35  /* \TYPO3\CMS\Extbase\Persistence\Generic\Storage\BackendInterface|\PHPUnit_Framework_MockObject_MockObject */
36  $storageBackend = $this->getMock(\TYPO3\CMS\Extbase\Persistence\Generic\Storage\BackendInterface::class);
37  /* \TYPO3\CMS\Extbase\DomainObject\DomainObjectInterface|\PHPUnit_Framework_MockObject_MockObject */
38  $domainObject = $this->getMock(\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->getMock(\TYPO3\CMS\Extbase\Configuration\ConfigurationManagerInterface::class);
82  $session = $this->getMock('stdClass', ['getIdentifierByObject'], [], '', false);
83  $object = new \stdClass();
84 
85  $session->expects($this->once())->method('getIdentifierByObject')->with($object)->will($this->returnValue($fakeUuid));
86 
88  $backend = $this->getAccessibleMock(\TYPO3\CMS\Extbase\Persistence\Generic\Backend::class, ['dummy'], [$configurationManager]);
89  $backend->_set('session', $session);
90 
91  $this->assertEquals($backend->getIdentifierByObject($object), $fakeUuid);
92  }
93 
97  public function getIdentifierByObjectReturnsIdentifierForLazyObject()
98  {
99  $fakeUuid = 'fakeUuid';
100  $configurationManager = $this->getMock(\TYPO3\CMS\Extbase\Configuration\ConfigurationManagerInterface::class);
101  $parentObject = new \stdClass();
102  $proxy = $this->getMock(\TYPO3\CMS\Extbase\Persistence\Generic\LazyLoadingProxy::class, ['_loadRealInstance'], [$parentObject, 'y', 'z'], '', false);
103  $session = $this->getMock('stdClass', ['getIdentifierByObject'], [], '', false);
104  $object = new \stdClass();
105 
106  $proxy->expects($this->once())->method('_loadRealInstance')->will($this->returnValue($object));
107  $session->expects($this->once())->method('getIdentifierByObject')->with($object)->will($this->returnValue($fakeUuid));
108 
110  $backend = $this->getAccessibleMock(\TYPO3\CMS\Extbase\Persistence\Generic\Backend::class, ['dummy'], [$configurationManager]);
111  $backend->_set('session', $session);
112 
113  $this->assertEquals($backend->getIdentifierByObject($proxy), $fakeUuid);
114  }
115 }
getAccessibleMock( $originalClassName, $methods=[], array $arguments=[], $mockClassName='', $callOriginalConstructor=true, $callOriginalClone=true, $callAutoload=true)