TYPO3 CMS  TYPO3_7-6
TemplateServiceTest.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 
19 
24 {
28  protected $templateService;
29 
34 
40  protected function setUp()
41  {
42  $GLOBALS['TYPO3_LOADED_EXT'] = [];
43  $this->templateService = new \TYPO3\CMS\Core\TypoScript\TemplateService();
44  $this->templateService->tt_track = false;
45  $this->templateServiceMock = $this->getAccessibleMock(\TYPO3\CMS\Core\TypoScript\TemplateService::class, ['dummy']);
46  $this->templateServiceMock->tt_track = false;
47  }
48 
53  {
54  $row = ['foo'];
55  $GLOBALS['TSFE'] = new \stdClass();
56  $sysPageMock = $this->getMock(\TYPO3\CMS\Frontend\Page\PageRepository::class);
57  $sysPageMock->expects($this->once())->method('versionOL')->with('sys_template', $row);
58  $GLOBALS['TSFE']->sys_page = $sysPageMock;
59  $this->templateService->versionOL($row);
60  }
61 
66  {
67  $identifier = $this->getUniqueId('test');
68  $GLOBALS['TYPO3_LOADED_EXT'] = [
69  $identifier => [
70  'ext_typoscript_setup.txt' => ExtensionManagementUtility::extPath(
71  'core', 'Tests/Unit/TypoScript/Fixtures/ext_typoscript_setup.txt'
72  ),
73  ],
74  ];
75 
76  $this->templateService->runThroughTemplates([], 0);
77  $this->assertFalse(
78  in_array('test.Core.TypoScript = 1', $this->templateService->config)
79  );
80  }
81 
86  {
87  $identifier = $this->getUniqueId('test');
88  $GLOBALS['TYPO3_LOADED_EXT'] = [
89  $identifier => [
90  'ext_typoscript_setup.txt' => ExtensionManagementUtility::extPath(
91  'core', 'Tests/Unit/TypoScript/Fixtures/ext_typoscript_setup.txt'
92  ),
93  'ext_typoscript_constants.txt' => ''
94  ],
95  ];
96 
97  $mockPackage = $this->getMock(\TYPO3\CMS\Core\Package\Package::class, ['getPackagePath'], [], '', false);
98  $mockPackage->expects($this->any())->method('getPackagePath')->will($this->returnValue(''));
99 
100  $mockPackageManager = $this->getMock(\TYPO3\CMS\Core\Package\PackageManager::class, ['isPackageActive', 'getPackage']);
101  $mockPackageManager->expects($this->any())->method('isPackageActive')->will($this->returnValue(true));
102  $mockPackageManager->expects($this->any())->method('getPackage')->will($this->returnValue($mockPackage));
104 
105  $this->templateService->setProcessExtensionStatics(true);
106  $this->templateService->runThroughTemplates([], 0);
107 
108  $this->assertTrue(
109  in_array('test.Core.TypoScript = 1', $this->templateService->config)
110  );
111 
112  ExtensionManagementUtility::setPackageManager(GeneralUtility::makeInstance(\TYPO3\CMS\Core\Package\PackageManager::class));
113  }
114 
119  {
120  $originalRootline = [
121  0 => ['uid' => 2, 'title' => 'originalTitle'],
122  1 => ['uid' => 3, 'title' => 'originalTitle2'],
123  ];
124 
125  $updatedRootline = [
126  0 => ['uid' => 1, 'title' => 'newTitle'],
127  1 => ['uid' => 2, 'title' => 'newTitle2'],
128  2 => ['uid' => 3, 'title' => 'newTitle3'],
129  ];
130 
131  $expectedRootline = [
132  0 => ['uid' => 2, 'title' => 'newTitle2'],
133  1 => ['uid' => 3, 'title' => 'newTitle3'],
134  ];
135 
136  $this->templateServiceMock->_set('rootLine', $originalRootline);
137  $this->templateServiceMock->updateRootlineData($updatedRootline);
138  $this->assertEquals($expectedRootline, $this->templateServiceMock->_get('rootLine'));
139  }
140 
146  {
147  $originalRootline = [
148  0 => ['uid' => 2, 'title' => 'originalTitle'],
149  1 => ['uid' => 3, 'title' => 'originalTitle2'],
150  ];
151 
152  $newInvalidRootline = [
153  0 => ['uid' => 1, 'title' => 'newTitle'],
154  1 => ['uid' => 2, 'title' => 'newTitle2'],
155  ];
156 
157  $this->templateServiceMock->_set('rootLine', $originalRootline);
158  $this->templateServiceMock->updateRootlineData($newInvalidRootline);
159  }
160 
165  {
166  $this->assertSame('http://example.com', $this->templateService->getFileName('http://example.com'));
167  $this->assertSame('https://example.com', $this->templateService->getFileName('https://example.com'));
168  }
169 
174  {
175  $this->assertSame('typo3/index.php', $this->templateService->getFileName('typo3/index.php'));
176  }
177 
182  {
183  $this->assertNull($this->templateService->getFileName(__DIR__));
184  }
185 
190  {
191  $this->assertNull($this->templateService->getFileName(' '));
192  $this->assertNull($this->templateService->getFileName('something/../else'));
193  }
194 
195  public function splitConfDataProvider()
196  {
197  return [
198  [
199  ['splitConfiguration' => 'a'],
200  3,
201  [
202  0 => ['splitConfiguration' => 'a'],
203  1 => ['splitConfiguration' => 'a'],
204  2 => ['splitConfiguration' => 'a']
205  ]
206  ],
207  [
208  ['splitConfiguration' => 'a || b || c'],
209  5,
210  [
211  0 => ['splitConfiguration' => 'a'],
212  1 => ['splitConfiguration' => 'b'],
213  2 => ['splitConfiguration' => 'c'],
214  3 => ['splitConfiguration' => 'c'],
215  4 => ['splitConfiguration' => 'c']
216  ]
217  ],
218  [
219  ['splitConfiguration' => 'a || b |*| c'],
220  5,
221  [
222  0 => ['splitConfiguration' => 'a'],
223  1 => ['splitConfiguration' => 'b'],
224  2 => ['splitConfiguration' => 'c'],
225  3 => ['splitConfiguration' => 'c'],
226  4 => ['splitConfiguration' => 'c']
227  ]
228  ],
229  [
230  ['splitConfiguration' => 'a || b |*| c |*| d || e'],
231  7,
232  [
233  0 => ['splitConfiguration' => 'a'],
234  1 => ['splitConfiguration' => 'b'],
235  2 => ['splitConfiguration' => 'c'],
236  3 => ['splitConfiguration' => 'c'],
237  4 => ['splitConfiguration' => 'c'],
238  5 => ['splitConfiguration' => 'd'],
239  6 => ['splitConfiguration' => 'e']
240  ]
241  ],
242  [
243  ['splitConfiguration' => 'a || b |*| c |*| d || e'],
244  4,
245  [
246  0 => ['splitConfiguration' => 'a'],
247  1 => ['splitConfiguration' => 'b'],
248  2 => ['splitConfiguration' => 'd'],
249  3 => ['splitConfiguration' => 'e']
250  ]
251  ],
252  [
253  ['splitConfiguration' => 'a || b |*| c |*| d || e'],
254  3,
255  [
256  0 => ['splitConfiguration' => 'a'],
257  1 => ['splitConfiguration' => 'd'],
258  2 => ['splitConfiguration' => 'e']
259  ]
260  ],
261  [
262  ['splitConfiguration' => 'a || b |*||*| c || d'],
263  7,
264  [
265  0 => ['splitConfiguration' => 'a'],
266  1 => ['splitConfiguration' => 'b'],
267  2 => ['splitConfiguration' => 'b'],
268  3 => ['splitConfiguration' => 'b'],
269  4 => ['splitConfiguration' => 'b'],
270  5 => ['splitConfiguration' => 'c'],
271  6 => ['splitConfiguration' => 'd']
272  ]
273  ],
274  [
275  ['splitConfiguration' => '|*||*| a || b'],
276  7,
277  [
278  0 => ['splitConfiguration' => 'a'],
279  1 => ['splitConfiguration' => 'a'],
280  2 => ['splitConfiguration' => 'a'],
281  3 => ['splitConfiguration' => 'a'],
282  4 => ['splitConfiguration' => 'a'],
283  5 => ['splitConfiguration' => 'a'],
284  6 => ['splitConfiguration' => 'b']
285  ]
286  ],
287  [
288  ['splitConfiguration' => 'a |*| b || c |*|'],
289  7,
290  [
291  0 => ['splitConfiguration' => 'a'],
292  1 => ['splitConfiguration' => 'b'],
293  2 => ['splitConfiguration' => 'c'],
294  3 => ['splitConfiguration' => 'b'],
295  4 => ['splitConfiguration' => 'c'],
296  5 => ['splitConfiguration' => 'b'],
297  6 => ['splitConfiguration' => 'c']
298  ]
299  ],
300  ];
301  }
302 
308  public function splitConfArraytest($configuration, $splitCount, $expected)
309  {
310  $actual = $this->templateService->splitConfArray($configuration, $splitCount);
311  $this->assertSame($expected, $actual);
312  }
313 }
splitConfArraytest($configuration, $splitCount, $expected)
getAccessibleMock( $originalClassName, $methods=[], array $arguments=[], $mockClassName='', $callOriginalConstructor=true, $callOriginalClone=true, $callAutoload=true)
static setPackageManager(PackageManager $packageManager)
if(TYPO3_MODE==='BE') $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_tsfebeuserauth.php']['frontendEditingController']['default']