TYPO3 CMS  TYPO3_8-7
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 
23 
27 class TemplateServiceTest extends \TYPO3\TestingFramework\Core\Unit\UnitTestCase
28 {
32  protected $templateService;
33 
38 
43 
47  protected function setUp()
48  {
49  $GLOBALS['TYPO3_LOADED_EXT'] = [];
50  $this->templateService = new \TYPO3\CMS\Core\TypoScript\TemplateService();
51  $this->templateService->tt_track = false;
52  $this->templateServiceMock = $this->getAccessibleMock(\TYPO3\CMS\Core\TypoScript\TemplateService::class, ['dummy']);
53  $this->templateServiceMock->tt_track = false;
55  }
56 
60  public function tearDown()
61  {
63  parent::tearDown();
64  }
65 
70  {
71  $row = ['foo'];
72  $GLOBALS['TSFE'] = new \stdClass();
73  $sysPageMock = $this->createMock(\TYPO3\CMS\Frontend\Page\PageRepository::class);
74  $sysPageMock->expects($this->once())->method('versionOL')->with('sys_template', $row);
75  $GLOBALS['TSFE']->sys_page = $sysPageMock;
76  $this->templateService->versionOL($row);
77  }
78 
83  {
84  $queryBuilderProphet = $this->prophesize(QueryBuilder::class);
85  $connectionPoolProphet = $this->prophesize(ConnectionPool::class);
86  $connectionPoolProphet->getQueryBuilderForTable(Argument::cetera())->willReturn($queryBuilderProphet->reveal());
87  GeneralUtility::addInstance(ConnectionPool::class, $connectionPoolProphet->reveal());
88 
89  $identifier = $this->getUniqueId('test');
90  $GLOBALS['TYPO3_LOADED_EXT'] = [
91  $identifier => [
92  'ext_typoscript_setup.txt' => ExtensionManagementUtility::extPath(
93  'core',
94  'Tests/Unit/TypoScript/Fixtures/ext_typoscript_setup.txt'
95  ),
96  ],
97  ];
98 
99  $this->templateService->runThroughTemplates([], 0);
100  $this->assertFalse(
101  in_array('test.Core.TypoScript = 1', $this->templateService->config)
102  );
103  }
104 
109  {
110  $queryBuilderProphet = $this->prophesize(QueryBuilder::class);
111  $connectionPoolProphet = $this->prophesize(ConnectionPool::class);
112  $connectionPoolProphet->getQueryBuilderForTable(Argument::cetera())->willReturn($queryBuilderProphet->reveal());
113  GeneralUtility::addInstance(ConnectionPool::class, $connectionPoolProphet->reveal());
114 
115  $identifier = $this->getUniqueId('test');
116  $GLOBALS['TYPO3_LOADED_EXT'] = [
117  $identifier => [
118  'ext_typoscript_setup.txt' => ExtensionManagementUtility::extPath(
119  'core',
120  'Tests/Unit/TypoScript/Fixtures/ext_typoscript_setup.txt'
121  ),
122  'ext_typoscript_constants.txt' => ''
123  ],
124  ];
125 
126  $mockPackage = $this->getMockBuilder(\TYPO3\CMS\Core\Package\Package::class)
127  ->setMethods(['getPackagePath'])
128  ->disableOriginalConstructor()
129  ->getMock();
130  $mockPackage->expects($this->any())->method('getPackagePath')->will($this->returnValue(''));
131 
132  $mockPackageManager = $this->getMockBuilder(\TYPO3\CMS\Core\Package\PackageManager::class)
133  ->setMethods(['isPackageActive', 'getPackage'])
134  ->getMock();
135  $mockPackageManager->expects($this->any())->method('isPackageActive')->will($this->returnValue(true));
136  $mockPackageManager->expects($this->any())->method('getPackage')->will($this->returnValue($mockPackage));
138 
139  $this->templateService->setProcessExtensionStatics(true);
140  $this->templateService->runThroughTemplates([], 0);
141 
142  $this->assertTrue(
143  in_array('test.Core.TypoScript = 1', $this->templateService->config)
144  );
145  }
146 
151  {
152  $originalRootline = [
153  0 => ['uid' => 2, 'title' => 'originalTitle'],
154  1 => ['uid' => 3, 'title' => 'originalTitle2'],
155  ];
156 
157  $updatedRootline = [
158  0 => ['uid' => 1, 'title' => 'newTitle'],
159  1 => ['uid' => 2, 'title' => 'newTitle2'],
160  2 => ['uid' => 3, 'title' => 'newTitle3'],
161  ];
162 
163  $expectedRootline = [
164  0 => ['uid' => 2, 'title' => 'newTitle2'],
165  1 => ['uid' => 3, 'title' => 'newTitle3'],
166  ];
167 
168  $this->templateServiceMock->_set('rootLine', $originalRootline);
169  $this->templateServiceMock->updateRootlineData($updatedRootline);
170  $this->assertEquals($expectedRootline, $this->templateServiceMock->_get('rootLine'));
171  }
172 
177  {
178  $originalRootline = [
179  0 => ['uid' => 2, 'title' => 'originalTitle'],
180  1 => ['uid' => 3, 'title' => 'originalTitle2'],
181  ];
182 
183  $newInvalidRootline = [
184  0 => ['uid' => 1, 'title' => 'newTitle'],
185  1 => ['uid' => 2, 'title' => 'newTitle2'],
186  ];
187 
188  $this->expectException(\RuntimeException::class);
189  $this->expectExceptionCode(1370419654);
190 
191  $this->templateServiceMock->_set('rootLine', $originalRootline);
192  $this->templateServiceMock->updateRootlineData($newInvalidRootline);
193  }
194 
199  {
200  $this->assertSame('http://example.com', $this->templateService->getFileName('http://example.com'));
201  $this->assertSame('https://example.com', $this->templateService->getFileName('https://example.com'));
202  }
203 
208  {
209  $this->assertSame('typo3/index.php', $this->templateService->getFileName('typo3/index.php'));
210  }
211 
216  {
217  $this->assertNull($this->templateService->getFileName(__DIR__));
218  }
219 
224  {
225  $this->assertNull($this->templateService->getFileName(' '));
226  $this->assertNull($this->templateService->getFileName('something/../else'));
227  }
228 }
static addInstance($className, $instance)
static setPackageManager(PackageManager $packageManager)
if(TYPO3_MODE==='BE') $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_tsfebeuserauth.php']['frontendEditingController']['default']