TYPO3 CMS  TYPO3_8-7
Typo3DbBackendTest.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 
25 
29 class Typo3DbBackendTest extends \TYPO3\TestingFramework\Core\Unit\UnitTestCase
30 {
34  protected static $dataMapper;
35 
36  public function setUp()
37  {
38  parent::setUp();
39  $GLOBALS['TSFE'] = new \stdClass();
40  $GLOBALS['TSFE']->gr_list = '';
41  }
42 
46  public static function setUpBeforeClass()
47  {
48  self::$dataMapper = new DataMapper();
49  }
50 
55  {
56  return [
57  'isFrontendEnvironment' => [true],
58  'isBackendEnvironment' => [false],
59  ];
60  }
61 
66  public function uidOfAlreadyPersistedValueObjectIsDeterminedCorrectly(bool $isFrontendEnvironment)
67  {
68  $mockValueObject = $this->getMockBuilder(\TYPO3\CMS\Extbase\DomainObject\AbstractValueObject::class)
69  ->setMethods(['_getProperties'])
70  ->disableOriginalConstructor()
71  ->getMock();
72  $mockValueObject->expects($this->once())->method('_getProperties')
73  ->will($this->returnValue(['propertyName' => 'propertyValue']));
74  $mockColumnMap = $this->getMockBuilder(\TYPO3\CMS\Extbase\Persistence\Generic\Mapper\DataMap::class)
75  ->setMethods(['isPersistableProperty', 'getColumnName'])
76  ->disableOriginalConstructor()
77  ->getMock();
78  $mockColumnMap->expects($this->any())->method('getColumnName')->will($this->returnValue('column_name'));
79  $tableName = 'tx_foo_table';
80  $mockDataMap = $this->getMockBuilder(\TYPO3\CMS\Extbase\Persistence\Generic\Mapper\DataMap::class)
81  ->setMethods(['isPersistableProperty', 'getColumnMap', 'getTableName'])
82  ->disableOriginalConstructor()
83  ->getMock();
84  $mockDataMap->expects($this->any())->method('isPersistableProperty')->will($this->returnValue(true));
85  $mockDataMap->expects($this->any())->method('getColumnMap')->will($this->returnValue($mockColumnMap));
86  $mockDataMap->expects($this->any())->method('getTableName')->will($this->returnValue($tableName));
87  $mockDataMapper = $this->getMockBuilder(\TYPO3\CMS\Extbase\Persistence\Generic\Mapper\DataMapper::class)
88  ->setMethods(['getDataMap', 'getPlainValue'])
89  ->disableOriginalConstructor()
90  ->getMock();
91  $mockDataMapper->expects($this->once())->method('getDataMap')
92  ->will($this->returnValue($mockDataMap));
93  $mockDataMapper->expects($this->once())->method('getPlainValue')
94  ->will($this->returnValue('plainPropertyValue'));
95  $expectedUid = 52;
96 
97  $expressionBuilderProphet = $this->prophesize(ExpressionBuilder::class);
98  $expressionBuilderProphet->eq(Argument::cetera())->willReturn('1 = 1');
99  $queryResultProphet = $this->prophesize(Statement::class);
100  $queryResultProphet->fetchColumn(Argument::cetera())->willReturn($expectedUid);
101  $queryBuilderProphet = $this->prophesize(QueryBuilder::class);
102  $queryBuilderProphet->execute()->willReturn($queryResultProphet->reveal());
103  $queryBuilderProphet->expr()->willReturn($expressionBuilderProphet->reveal());
104  $queryBuilderProphet->createNamedParameter(Argument::cetera())->willReturnArgument(0);
105  $queryBuilderProphet->select('uid')->willReturn($queryBuilderProphet->reveal());
106  $queryBuilderProphet->from($tableName)->willReturn($queryBuilderProphet->reveal());
107  $queryBuilderProphet->where(Argument::cetera())->willReturn($queryBuilderProphet->reveal());
108  $connectionPoolProphet = $this->prophesize(ConnectionPool::class);
109  $connectionPoolProphet->getQueryBuilderForTable(Argument::cetera())->willReturn($queryBuilderProphet->reveal());
110 
111  $environmentServiceProphet = $this->prophesize(EnvironmentService::class);
112  $environmentServiceProphet->isEnvironmentInFrontendMode()->willReturn($isFrontendEnvironment);
113 
114  if ($isFrontendEnvironment) {
115  $queryBuilderProphet->setRestrictions(Argument::type(FrontendRestrictionContainer::class))
116  ->shouldBeCalled();
117  }
118 
119  $mockTypo3DbBackend = $this->getAccessibleMock(
120  \TYPO3\CMS\Extbase\Persistence\Generic\Storage\Typo3DbBackend::class,
121  ['dummy'],
122  [],
123  '',
124  false
125  );
126  $mockTypo3DbBackend->_set('dataMapper', $mockDataMapper);
127  $mockTypo3DbBackend->_set('connectionPool', $connectionPoolProphet->reveal());
128  $mockTypo3DbBackend->_set('environmentService', $environmentServiceProphet->reveal());
129  $result = $mockTypo3DbBackend->_callRef('getUidOfAlreadyPersistedValueObject', $mockValueObject);
130  $this->assertSame($expectedUid, $result);
131  }
132 
136  public function doLanguageAndWorkspaceOverlayChangesUidIfInPreview()
137  {
138  $comparisonRow = [
139  'uid' => '42',
140  'pid' => '42',
141  '_ORIG_pid' => '-1',
142  '_ORIG_uid' => '43'
143  ];
144  $row = [
145  'uid' => '42',
146  'pid' => '42'
147  ];
148  $workspaceVersion = [
149  'uid' => '43',
150  'pid' => '-1'
151  ];
153  $mockQuerySettings = $this->getMockBuilder(\TYPO3\CMS\Extbase\Persistence\Generic\Typo3QuerySettings::class)
154  ->setMethods(['dummy'])
155  ->disableOriginalConstructor()
156  ->getMock();
157 
158  $workspaceUid = 2;
159  $sourceMock = new \TYPO3\CMS\Extbase\Persistence\Generic\Qom\Selector('tx_foo', 'Tx_Foo');
161  $pageRepositoryMock = $this->getMockBuilder(\TYPO3\CMS\Frontend\Page\PageRepository::class)
162  ->setMethods(['movePlhOL', 'getWorkspaceVersionOfRecord'])
163  ->getMock();
164  $pageRepositoryMock->versioningPreview = true;
165  $pageRepositoryMock->expects($this->once())->method('getWorkspaceVersionOfRecord')->with($workspaceUid, 'tx_foo', '42')->will($this->returnValue($workspaceVersion));
166  $mockTypo3DbBackend = $this->getAccessibleMock(\TYPO3\CMS\Extbase\Persistence\Generic\Storage\Typo3DbBackend::class, ['dummy'], [], '', false);
167  $mockTypo3DbBackend->_set('pageRepository', $pageRepositoryMock);
168  $this->assertSame([$comparisonRow], $mockTypo3DbBackend->_call('doLanguageAndWorkspaceOverlay', $sourceMock, [$row], $mockQuerySettings, $workspaceUid));
169  }
170 }
if(TYPO3_MODE==='BE') $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_tsfebeuserauth.php']['frontendEditingController']['default']