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