[TASK] mssql: A series of functional test fixes
[Packages/TYPO3.CMS.git] / typo3 / sysext / frontend / Tests / Functional / Controller / TypoScriptFrontendControllerTest.php
1 <?php
2 namespace TYPO3\CMS\Frontend\Tests\Functional\Controller;
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
17 use Doctrine\DBAL\Platforms\SQLServerPlatform;
18 use TYPO3\CMS\Core\Cache\CacheManager;
19 use TYPO3\CMS\Core\Database\ConnectionPool;
20 use TYPO3\CMS\Core\Utility\GeneralUtility;
21 use TYPO3\CMS\Frontend\Controller\TypoScriptFrontendController;
22
23 /**
24 * Test case
25 */
26 class TypoScriptFrontendControllerTest extends \TYPO3\TestingFramework\Core\Functional\FunctionalTestCase
27 {
28 /**
29 * @var TypoScriptFrontendController
30 */
31 protected $tsFrontendController;
32
33 protected function setUp()
34 {
35 parent::setUp();
36 $this->importDataSet(__DIR__ . '/fixtures.xml');
37
38 $GLOBALS['TSFE']->gr_list = '';
39 $this->tsFrontendController = $this->getAccessibleMock(
40 TypoScriptFrontendController::class,
41 ['dummy'],
42 [],
43 '',
44 false
45 );
46
47 $pageContextMock = $this->getMockBuilder(\TYPO3\CMS\Frontend\Page\PageRepository::class)->getMock();
48 $this->tsFrontendController->_set('sys_page', $pageContextMock);
49 }
50
51 /**
52 * @test
53 */
54 public function getFirstTimeValueForRecordReturnCorrectData()
55 {
56 $this->assertSame(
57 $this->getFirstTimeValueForRecordCall('tt_content:2', 1),
58 2,
59 'The next start/endtime should be 2'
60 );
61 $this->assertSame(
62 $this->getFirstTimeValueForRecordCall('tt_content:2', 2),
63 3,
64 'The next start/endtime should be 3'
65 );
66 $this->assertSame(
67 $this->getFirstTimeValueForRecordCall('tt_content:2', 4),
68 5,
69 'The next start/endtime should be 5'
70 );
71 $this->assertSame(
72 $this->getFirstTimeValueForRecordCall('tt_content:2', 5),
73 PHP_INT_MAX,
74 'The next start/endtime should be PHP_INT_MAX as there are no more'
75 );
76 $this->assertSame(
77 $this->getFirstTimeValueForRecordCall('tt_content:3', 1),
78 PHP_INT_MAX,
79 'Should be PHP_INT_MAX as table has not this PID'
80 );
81 $this->assertSame(
82 $this->getFirstTimeValueForRecordCall('fe_groups:2', 1),
83 PHP_INT_MAX,
84 'Should be PHP_INT_MAX as table fe_groups has no start/endtime in TCA'
85 );
86 }
87
88 /**
89 * @param string $currentDomain
90 * @test
91 * @dataProvider getSysDomainCacheDataProvider
92 */
93 public function getSysDomainCacheReturnsCurrentDomainRecord($currentDomain)
94 {
95 GeneralUtility::flushInternalRuntimeCaches();
96
97 $_SERVER['HTTP_HOST'] = $currentDomain;
98 $domainRecords = [
99 'typo3.org' => [
100 'uid' => '1',
101 'pid' => '1',
102 'domainName' => 'typo3.org',
103 'forced' => 0,
104 ],
105 'foo.bar' => [
106 'uid' => '2',
107 'pid' => '1',
108 'domainName' => 'foo.bar',
109 'forced' => 0,
110 ],
111 'example.com' => [
112 'uid' => '3',
113 'pid' => '1',
114 'domainName' => 'example.com',
115 'forced' => 0,
116 ],
117 ];
118
119 $connection = (new ConnectionPool())->getConnectionForTable('sys_domain');
120
121 $sqlServerIdentityDisabled = false;
122 if ($connection->getDatabasePlatform() instanceof SQLServerPlatform) {
123 $connection->exec('SET IDENTITY_INSERT sys_domain ON');
124 $sqlServerIdentityDisabled = true;
125 }
126
127 foreach ($domainRecords as $domainRecord) {
128 $connection->insert(
129 'sys_domain',
130 $domainRecord
131 );
132 }
133
134 if ($sqlServerIdentityDisabled) {
135 $connection->exec('SET IDENTITY_INSERT sys_domain OFF');
136 }
137
138 GeneralUtility::makeInstance(CacheManager::class)->getCache('cache_runtime')->flush();
139 $expectedResult = [
140 $domainRecords[$currentDomain]['pid'] => $domainRecords[$currentDomain],
141 ];
142
143 $actualResult = $this->tsFrontendController->_call('getSysDomainCache');
144 $this->assertEquals($expectedResult, $actualResult);
145 }
146
147 /**
148 * @param string $currentDomain
149 * @test
150 * @dataProvider getSysDomainCacheDataProvider
151 */
152 public function getSysDomainCacheReturnsForcedDomainRecord($currentDomain)
153 {
154 GeneralUtility::flushInternalRuntimeCaches();
155
156 $_SERVER['HTTP_HOST'] = $currentDomain;
157 $domainRecords = [
158 'typo3.org' => [
159 'uid' => '1',
160 'pid' => '1',
161 'domainName' => 'typo3.org',
162 'forced' => 0,
163 ],
164 'foo.bar' => [
165 'uid' => '2',
166 'pid' => '1',
167 'domainName' => 'foo.bar',
168 'forced' => 1,
169 ],
170 'example.com' => [
171 'uid' => '3',
172 'pid' => '1',
173 'domainName' => 'example.com',
174 'forced' => 0,
175 ],
176 ];
177
178 $connection = (new ConnectionPool())->getConnectionForTable('sys_domain');
179
180 $sqlServerIdentityDisabled = false;
181 if ($connection->getDatabasePlatform() instanceof SQLServerPlatform) {
182 $connection->exec('SET IDENTITY_INSERT sys_domain ON');
183 $sqlServerIdentityDisabled = true;
184 }
185
186 foreach ($domainRecords as $domainRecord) {
187 $connection->insert(
188 'sys_domain',
189 $domainRecord
190 );
191 }
192
193 if ($sqlServerIdentityDisabled) {
194 $connection->exec('SET IDENTITY_INSERT sys_domain OFF');
195 }
196
197 GeneralUtility::makeInstance(CacheManager::class)->getCache('cache_runtime')->flush();
198 $expectedResult = [
199 $domainRecords[$currentDomain]['pid'] => $domainRecords['foo.bar'],
200 ];
201 $actualResult = $this->tsFrontendController->_call('getSysDomainCache');
202
203 $this->assertEquals($expectedResult, $actualResult);
204 }
205
206 /**
207 * @param string $tablePid
208 * @param int $now
209 * @return int
210 */
211 public function getFirstTimeValueForRecordCall($tablePid, $now)
212 {
213 return $this->tsFrontendController->_call('getFirstTimeValueForRecord', $tablePid, $now);
214 }
215
216 /**
217 * @return array
218 */
219 public function getSysDomainCacheDataProvider()
220 {
221 return [
222 'typo3.org' => [
223 'typo3.org',
224 ],
225 'foo.bar' => [
226 'foo.bar',
227 ],
228 'example.com' => [
229 'example.com',
230 ],
231 ];
232 }
233 }