TYPO3CMS  8
 All Classes Namespaces Files Functions Variables Pages
Unit/Controller/TypoScriptFrontendControllerTest.php
Go to the documentation of this file.
1 <?php
2 namespace TYPO3\CMS\Frontend\Tests\Unit\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 
20 
25 {
29  protected $subject;
30 
31  protected function setUp()
32  {
34  $this->subject = $this->getAccessibleMock(TypoScriptFrontendController::class, ['dummy'], [], '', false);
35  $GLOBALS['TYPO3_CONF_VARS']['SYS']['encryptionKey'] = '170928423746123078941623042360abceb12341234231';
36 
37  $pageRepository = $this->getMockBuilder(PageRepository::class)->getMock();
38  $this->subject->sys_page = $pageRepository;
39  }
40 
49  {
50  $GLOBALS['TSFE'] = $this->setupTsfeMockForHeaderFooterReplacementCheck();
51  $GLOBALS['TSFE']->INTincScript();
52  $this->assertContains('headerData', $GLOBALS['TSFE']->content);
53  $this->assertContains('footerData', $GLOBALS['TSFE']->content);
54  }
55 
59  public function INTincScript_processCallback()
60  {
61  $GLOBALS['TSFE']->additionalHeaderData[] = 'headerData';
62  $GLOBALS['TSFE']->additionalFooterData[] = 'footerData';
63  }
64 
71  protected function setupTsfeMockForHeaderFooterReplacementCheck()
72  {
74  $tsfe = $this->getMockBuilder(TypoScriptFrontendController::class)
75  ->setMethods([
76  'INTincScript_process',
77  'INTincScript_loadJSCode',
78  'setAbsRefPrefix',
79  'regeneratePageTitle'
80  ])->disableOriginalConstructor()
81  ->getMock();
82  $tsfe->expects($this->exactly(2))->method('INTincScript_process')->will($this->returnCallback([$this, 'INTincScript_processCallback']));
83  $tsfe->content = file_get_contents(__DIR__ . '/Fixtures/renderedPage.html');
84  $config = [
85  'INTincScript_ext' => [
86  'divKey' => '679b52796e75d474ccbbed486b6837ab',
87  ],
88  'INTincScript' => [
89  'INT_SCRIPT.679b52796e75d474ccbbed486b6837ab' => [],
90  ]
91  ];
92  $tsfe->config = $config;
93 
94  return $tsfe;
95  }
96 
105  {
106  $string = $this->getUniqueId();
107  $this->assertEquals($string, $this->subject->sL($string));
108  }
109 
118  {
119  return [
120  'typo3.org' => [
121  'typo3.org',
122  ],
123  'foo.bar' => [
124  'foo.bar',
125  ],
126  'example.com' => [
127  'example.com',
128  ],
129  ];
130  }
131 
140  {
141  return [
142  'same domains' => [
143  'typo3.org',
144  'typo3.org',
145  '/index.php',
146  true,
147  ],
148  'same domains with subdomain' => [
149  'www.typo3.org',
150  'www.typo3.org',
151  '/index.php',
152  true,
153  ],
154  'different domains' => [
155  'foo.bar',
156  'typo3.org',
157  '/index.php',
158  false,
159  ],
160  'domain record with script name' => [
161  'typo3.org',
162  'typo3.org/foo/bar',
163  '/foo/bar/index.php',
164  true,
165  ],
166  'domain record with wrong script name' => [
167  'typo3.org',
168  'typo3.org/foo/bar',
169  '/bar/foo/index.php',
170  false,
171  ],
172  ];
173  }
174 
183  public function domainNameMatchesCurrentRequest($currentDomain, $domainRecord, $scriptName, $expectedResult)
184  {
185  $_SERVER['HTTP_HOST'] = $currentDomain;
186  $_SERVER['SCRIPT_NAME'] = $scriptName;
187  $this->assertEquals($expectedResult, $this->subject->domainNameMatchesCurrentRequest($domainRecord));
188  }
189 
194  {
195  return [
196  'without base url' => [
197  '',
198  'fileadmin/user_uploads/image.jpg',
199  'fileadmin/user_uploads/image.jpg'
200  ],
201  'with base url' => [
202  'http://www.google.com/',
203  'fileadmin/user_uploads/image.jpg',
204  'http://www.google.com/fileadmin/user_uploads/image.jpg'
205  ],
206  'without base url but with url prepended with a forward slash' => [
207  '',
208  '/fileadmin/user_uploads/image.jpg',
209  '/fileadmin/user_uploads/image.jpg',
210  ],
211  'with base url but with url prepended with a forward slash' => [
212  'http://www.google.com/',
213  '/fileadmin/user_uploads/image.jpg',
214  '/fileadmin/user_uploads/image.jpg',
215  ],
216  ];
217  }
218 
226  public function baseUrlWrapHandlesDifferentUrls($baseUrl, $url, $expected)
227  {
228  $this->subject->baseUrl = $baseUrl;
229  $this->assertSame($expected, $this->subject->baseUrlWrap($url));
230  }
231 }
if(TYPO3_MODE=== 'BE') $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_tsfebeuserauth.php']['frontendEditingController']['default']
getAccessibleMock($originalClassName, $methods=[], array $arguments=[], $mockClassName= '', $callOriginalConstructor=true, $callOriginalClone=true, $callAutoload=true)