‪TYPO3CMS  ‪main
BackendTest.php
Go to the documentation of this file.
1 <?php
2 
3 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  */
17 
19 
20 use PHPUnit\Framework\Attributes\Test;
31 use TYPO3\TestingFramework\Core\Unit\UnitTestCase;
32 
33 final class ‪BackendTest extends UnitTestCase
34 {
35  protected function ‪tearDown(): void
36  {
37  GeneralUtility::purgeInstances();
38  parent::tearDown();
39  }
40 
41  #[Test]
43  {
44  $fixture = $this->getAccessibleMock(Backend::class, null, [], '', false);
45  $dataMapFactory = $this->createMock(DataMapFactory::class);
46  $dataMap = $this->createMock(DataMap::class);
47  $columnMap = $this->createMock(ColumnMap::class);
48  $storageBackend = $this->createMock(BackendInterface::class);
49  $domainObject = $this->createMock(DomainObjectInterface::class);
50 
51  $mmMatchFields = [
52  'identifier' => 'myTable:myField',
53  ];
54 
55  $expectedRow = [
56  'identifier' => 'myTable:myField',
57  '' => 0,
58  ];
59 
60  $columnMap
61  ->expects(self::once())
62  ->method('getRelationTableName')
63  ->willReturn('myTable');
64  $columnMap
65  ->expects(self::once())
66  ->method('getRelationTableMatchFields')
67  ->willReturn($mmMatchFields);
68  $columnMap
69  ->method('getChildSortByFieldName')
70  ->willReturn('');
71  $dataMap
72  ->method('getColumnMap')
73  ->willReturn($columnMap);
74  $dataMapFactory
75  ->method('buildDataMap')
76  ->willReturn($dataMap);
77  $storageBackend
78  ->expects(self::once())
79  ->method('addRow')
80  ->with('myTable', $expectedRow, true);
81 
82  $fixture->_set('dataMapFactory', $dataMapFactory);
83  $fixture->_set('storageBackend', $storageBackend);
84  $fixture->_call('insertRelationInRelationtable', $domainObject, $domainObject, '');
85  }
86 
87  #[Test]
89  {
90  $session = $this->createMock(Session::class);
91  $session->expects(self::never())->method('getIdentifierByObject');
92 
93  $backend = $this->getAccessibleMock(Backend::class, null, [$this->createMock(ConfigurationManagerInterface::class)], '', false);
94  $backend->_set('session', $session);
95 
96  self::assertNull($backend->getIdentifierByObject('invalidObject'));
97  }
98 
99  #[Test]
101  {
102  $fakeUuid = 'fakeUuid';
103  $configurationManager = $this->createMock(ConfigurationManagerInterface::class);
104  $session = $this->createMock(Session::class);
105  $object = new \stdClass();
106  $session->expects(self::once())->method('getIdentifierByObject')->with($object)->willReturn($fakeUuid);
107  $backend = $this->getAccessibleMock(Backend::class, null, [$configurationManager], '', false);
108  $backend->_set('session', $session);
109  self::assertEquals($backend->getIdentifierByObject($object), $fakeUuid);
110  }
111 
112  #[Test]
114  {
115  $fakeUuid = 'fakeUuid';
116  $configurationManager = $this->createMock(ConfigurationManagerInterface::class);
117  $proxy = $this->createMock(LazyLoadingProxy::class);
118  $session = $this->createMock(Session::class);
119  $object = new \stdClass();
120  $proxy->expects(self::once())->method('_loadRealInstance')->willReturn($object);
121  $session->expects(self::once())->method('getIdentifierByObject')->with($object)->willReturn($fakeUuid);
122  $backend = $this->getAccessibleMock(Backend::class, null, [$configurationManager], '', false);
123  $backend->_set('session', $session);
124  self::assertEquals($backend->getIdentifierByObject($proxy), $fakeUuid);
125  }
126 }
‪TYPO3\CMS\Extbase\Tests\Unit\Persistence\Generic\BackendTest\getIdentifierByObjectReturnsIdentifierForLazyObject
‪getIdentifierByObjectReturnsIdentifierForLazyObject()
Definition: BackendTest.php:113
‪TYPO3\CMS\Extbase\Persistence\Generic\Backend
Definition: Backend.php:53
‪TYPO3\CMS\Extbase\Tests\Unit\Persistence\Generic\BackendTest
Definition: BackendTest.php:34
‪TYPO3\CMS\Extbase\Persistence\Generic\Mapper\DataMap
Definition: DataMap.php:25
‪TYPO3\CMS\Extbase\Tests\Unit\Persistence\Generic\BackendTest\tearDown
‪tearDown()
Definition: BackendTest.php:35
‪TYPO3\CMS\Extbase\Tests\Unit\Persistence\Generic\BackendTest\insertRelationInRelationtableSetsMmMatchFieldsInRow
‪insertRelationInRelationtableSetsMmMatchFieldsInRow()
Definition: BackendTest.php:42
‪TYPO3\CMS\Extbase\Configuration\ConfigurationManagerInterface
Definition: ConfigurationManagerInterface.php:28
‪TYPO3\CMS\Extbase\Tests\Unit\Persistence\Generic\BackendTest\getIdentifierByObjectWithStringInsteadOfObjectReturnsNull
‪getIdentifierByObjectWithStringInsteadOfObjectReturnsNull()
Definition: BackendTest.php:88
‪TYPO3\CMS\Extbase\Persistence\Generic\Mapper\DataMapFactory
Definition: DataMapFactory.php:34
‪TYPO3\CMS\Extbase\DomainObject\DomainObjectInterface
Definition: DomainObjectInterface.php:33
‪TYPO3\CMS\Extbase\Persistence\Generic\Session
Definition: Session.php:27
‪TYPO3\CMS\Extbase\Tests\Unit\Persistence\Generic
Definition: BackendTest.php:18
‪TYPO3\CMS\Extbase\Persistence\Generic\LazyLoadingProxy
Definition: LazyLoadingProxy.php:30
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:52
‪TYPO3\CMS\Extbase\Tests\Unit\Persistence\Generic\BackendTest\getIdentifierByObjectReturnsIdentifierForNonLazyObject
‪getIdentifierByObjectReturnsIdentifierForNonLazyObject()
Definition: BackendTest.php:100
‪TYPO3\CMS\Extbase\Persistence\Generic\Storage\BackendInterface
Definition: BackendInterface.php:27
‪TYPO3\CMS\Extbase\Persistence\Generic\Mapper\ColumnMap
Definition: Relation.php:18