[!!!][TASK] Drop "documentation" extension
[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 use TYPO3\TestingFramework\Core\Functional\FunctionalTestCase;
23
24 /**
25 * Test case
26 */
27 class TypoScriptFrontendControllerTest extends FunctionalTestCase
28 {
29 /**
30 * @var TypoScriptFrontendController
31 */
32 protected $tsFrontendController;
33
34 protected function setUp()
35 {
36 parent::setUp();
37 $this->importDataSet(__DIR__ . '/fixtures.xml');
38
39 $GLOBALS['TSFE']->gr_list = '';
40 $this->tsFrontendController = $this->getAccessibleMock(
41 TypoScriptFrontendController::class,
42 ['dummy'],
43 [],
44 '',
45 false
46 );
47
48 $pageContextMock = $this->getMockBuilder(\TYPO3\CMS\Frontend\Page\PageRepository::class)->getMock();
49 $this->tsFrontendController->_set('sys_page', $pageContextMock);
50 }
51
52 /**
53 * @test
54 */
55 public function getFirstTimeValueForRecordReturnCorrectData()
56 {
57 $this->assertSame(
58 $this->getFirstTimeValueForRecordCall('tt_content:2', 1),
59 2,
60 'The next start/endtime should be 2'
61 );
62 $this->assertSame(
63 $this->getFirstTimeValueForRecordCall('tt_content:2', 2),
64 3,
65 'The next start/endtime should be 3'
66 );
67 $this->assertSame(
68 $this->getFirstTimeValueForRecordCall('tt_content:2', 4),
69 5,
70 'The next start/endtime should be 5'
71 );
72 $this->assertSame(
73 $this->getFirstTimeValueForRecordCall('tt_content:2', 5),
74 PHP_INT_MAX,
75 'The next start/endtime should be PHP_INT_MAX as there are no more'
76 );
77 $this->assertSame(
78 $this->getFirstTimeValueForRecordCall('tt_content:3', 1),
79 PHP_INT_MAX,
80 'Should be PHP_INT_MAX as table has not this PID'
81 );
82 $this->assertSame(
83 $this->getFirstTimeValueForRecordCall('fe_groups:2', 1),
84 PHP_INT_MAX,
85 'Should be PHP_INT_MAX as table fe_groups has no start/endtime in TCA'
86 );
87 }
88
89 /**
90 * @param string $currentDomain
91 * @test
92 * @dataProvider getSysDomainCacheDataProvider
93 */
94 public function getSysDomainCacheReturnsCurrentDomainRecord($currentDomain)
95 {
96 GeneralUtility::flushInternalRuntimeCaches();
97
98 $_SERVER['HTTP_HOST'] = $currentDomain;
99 $domainRecords = [
100 'typo3.org' => [
101 'uid' => '1',
102 'pid' => '1',
103 'domainName' => 'typo3.org',
104 ],
105 'foo.bar' => [
106 'uid' => '2',
107 'pid' => '1',
108 'domainName' => 'foo.bar',
109 ],
110 'example.com' => [
111 'uid' => '3',
112 'pid' => '1',
113 'domainName' => 'example.com',
114 ],
115 ];
116
117 $connection = (new ConnectionPool())->getConnectionForTable('sys_domain');
118
119 $sqlServerIdentityDisabled = false;
120 if ($connection->getDatabasePlatform() instanceof SQLServerPlatform) {
121 $connection->exec('SET IDENTITY_INSERT sys_domain ON');
122 $sqlServerIdentityDisabled = true;
123 }
124
125 foreach ($domainRecords as $domainRecord) {
126 $connection->insert(
127 'sys_domain',
128 $domainRecord
129 );
130 }
131
132 if ($sqlServerIdentityDisabled) {
133 $connection->exec('SET IDENTITY_INSERT sys_domain OFF');
134 }
135
136 GeneralUtility::makeInstance(CacheManager::class)->getCache('cache_runtime')->flush();
137 $expectedResult = [
138 $domainRecords[$currentDomain]['pid'] => $domainRecords[$currentDomain],
139 ];
140
141 $actualResult = $this->tsFrontendController->_call('getSysDomainCache');
142 $this->assertEquals($expectedResult, $actualResult);
143 }
144
145 /**
146 * @param string $tablePid
147 * @param int $now
148 * @return int
149 */
150 public function getFirstTimeValueForRecordCall($tablePid, $now)
151 {
152 return $this->tsFrontendController->_call('getFirstTimeValueForRecord', $tablePid, $now);
153 }
154
155 /**
156 * @return array
157 */
158 public function getSysDomainCacheDataProvider()
159 {
160 return [
161 'typo3.org' => [
162 'typo3.org',
163 ],
164 'foo.bar' => [
165 'foo.bar',
166 ],
167 'example.com' => [
168 'example.com',
169 ],
170 ];
171 }
172 }