TYPO3 CMS  TYPO3_8-7
TypoScriptFrontendControllerTest.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 
22 
26 class TypoScriptFrontendControllerTest extends \TYPO3\TestingFramework\Core\Functional\FunctionalTestCase
27 {
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 
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 
93  public function getSysDomainCacheReturnsCurrentDomainRecord($currentDomain)
94  {
95  $_SERVER['HTTP_HOST'] = $currentDomain;
96  $domainRecords = [
97  'typo3.org' => [
98  'uid' => '1',
99  'pid' => '1',
100  'domainName' => 'typo3.org',
101  'forced' => 0,
102  ],
103  'foo.bar' => [
104  'uid' => '2',
105  'pid' => '1',
106  'domainName' => 'foo.bar',
107  'forced' => 0,
108  ],
109  'example.com' => [
110  'uid' => '3',
111  'pid' => '1',
112  'domainName' => 'example.com',
113  'forced' => 0,
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 
150  public function getSysDomainCacheReturnsForcedDomainRecord($currentDomain)
151  {
152  $_SERVER['HTTP_HOST'] = $currentDomain;
153  $domainRecords = [
154  'typo3.org' => [
155  'uid' => '1',
156  'pid' => '1',
157  'domainName' => 'typo3.org',
158  'forced' => 0,
159  ],
160  'foo.bar' => [
161  'uid' => '2',
162  'pid' => '1',
163  'domainName' => 'foo.bar',
164  'forced' => 1,
165  ],
166  'example.com' => [
167  'uid' => '3',
168  'pid' => '1',
169  'domainName' => 'example.com',
170  'forced' => 0,
171  ],
172  ];
173 
174  $connection = (new ConnectionPool())->getConnectionForTable('sys_domain');
175 
176  $sqlServerIdentityDisabled = false;
177  if ($connection->getDatabasePlatform() instanceof SQLServerPlatform) {
178  $connection->exec('SET IDENTITY_INSERT sys_domain ON');
179  $sqlServerIdentityDisabled = true;
180  }
181 
182  foreach ($domainRecords as $domainRecord) {
183  $connection->insert(
184  'sys_domain',
185  $domainRecord
186  );
187  }
188 
189  if ($sqlServerIdentityDisabled) {
190  $connection->exec('SET IDENTITY_INSERT sys_domain OFF');
191  }
192 
193  GeneralUtility::makeInstance(CacheManager::class)->getCache('cache_runtime')->flush();
194  $expectedResult = [
195  $domainRecords[$currentDomain]['pid'] => $domainRecords['foo.bar'],
196  ];
197  $actualResult = $this->tsFrontendController->_call('getSysDomainCache');
198 
199  $this->assertEquals($expectedResult, $actualResult);
200  }
201 
207  public function getFirstTimeValueForRecordCall($tablePid, $now)
208  {
209  return $this->tsFrontendController->_call('getFirstTimeValueForRecord', $tablePid, $now);
210  }
211 
216  {
217  return [
218  'typo3.org' => [
219  'typo3.org',
220  ],
221  'foo.bar' => [
222  'foo.bar',
223  ],
224  'example.com' => [
225  'example.com',
226  ],
227  ];
228  }
229 }
static makeInstance($className,... $constructorArguments)
if(TYPO3_MODE==='BE') $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_tsfebeuserauth.php']['frontendEditingController']['default']