‪TYPO3CMS  10.4
TemplateServiceTest.php
Go to the documentation of this file.
1 <?php
2 
3 declare(strict_types=1);
4 
5 /*
6  * This file is part of the TYPO3 CMS project.
7  *
8  * It is free software; you can redistribute it and/or modify it under
9  * the terms of the GNU General Public License, either version 2
10  * of the License, or any later version.
11  *
12  * For the full copyright and license information, please read the
13  * LICENSE.txt file that was distributed with this source code.
14  *
15  * The TYPO3 project - inspiring people to share!
16  */
17 
19 
20 use Prophecy\Argument;
21 use Prophecy\Prophecy\ObjectProphecy;
26 use TYPO3\CMS\Core\Package\PackageManager;
33 use TYPO3\TestingFramework\Core\AccessibleObjectInterface;
34 use TYPO3\TestingFramework\Core\Unit\UnitTestCase;
35 
39 class ‪TemplateServiceTest extends UnitTestCase
40 {
44  protected ‪$templateService;
45 
49  protected ‪$templateServiceMock;
50 
54  protected ‪$backupPackageManager;
55 
60 
64  protected function ‪setUp(): void
65  {
66  parent::setUp();
67  ‪$GLOBALS['SIM_ACCESS_TIME'] = time();
68  ‪$GLOBALS['ACCESS_TIME'] = time();
69  $this->packageManagerProphecy = $this->prophesize(PackageManager::class);
70  $frontendController = $this->prophesize(TypoScriptFrontendController::class);
71  $frontendController->getSite()->willReturn(new ‪Site('dummy', 13, [
72  'base' => 'https://example.com',
73  'settings' => [
74  'random' => 'value',
75  'styles' => [
76  'content' => [
77  'loginform' => [
78  'pid' => 123
79  ],
80  ],
81  ],
82  'numberedThings' => [
83  1 => 'foo',
84  99 => 'bar',
85  ]
86  ]
87  ]));
88  $this->templateService = new ‪TemplateService(
89  new ‪Context(),
90  $this->packageManagerProphecy->reveal(),
91  $frontendController->reveal()
92  );
94  }
95 
99  public function ‪tearDown(): void
100  {
102  parent::tearDown();
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  $this->packageManagerProphecy->getActivePackages()->shouldNotBeCalled();
116 
117  $this->templateService->runThroughTemplates([], 0);
118  self::assertNotContains(
119  'test.Core.TypoScript = 1',
120  $this->templateService->config
121  );
122  }
123 
128  {
129  $queryBuilderProphet = $this->prophesize(QueryBuilder::class);
130  $connectionPoolProphet = $this->prophesize(ConnectionPool::class);
131  $connectionPoolProphet->getQueryBuilderForTable(Argument::cetera())->willReturn($queryBuilderProphet->reveal());
132  GeneralUtility::addInstance(ConnectionPool::class, $connectionPoolProphet->reveal());
133 
134  $mockPackage = $this->getMockBuilder(Package::class)
135  ->setMethods(['getPackagePath', 'getPackageKey'])
136  ->disableOriginalConstructor()
137  ->getMock();
138  $mockPackage->expects(self::any())->method('getPackagePath')->willReturn(__DIR__ . '/Fixtures/');
139  $mockPackage->expects(self::any())->method('getPackageKey')->willReturn('core');
140 
141  $mockPackageManager = $this->getMockBuilder(PackageManager::class)
142  ->setMethods(['isPackageActive', 'getPackage'])
143  ->disableOriginalConstructor()
144  ->getMock();
145  $mockPackageManager->expects(self::any())->method('isPackageActive')->willReturn(true);
146  $mockPackageManager->expects(self::any())->method('getPackage')->willReturn($mockPackage);
148  $this->packageManagerProphecy->getActivePackages()->willReturn(['core' => $mockPackage]);
149 
150  $this->templateService->setProcessExtensionStatics(true);
151  $this->templateService->runThroughTemplates([], 0);
152 
153  self::assertContains(
154  'test.Core.TypoScript = 1',
155  $this->templateService->config
156  );
157  }
158 
162  public function ‪updateRootlineDataOverwritesOwnArrayData(): void
163  {
164  $originalRootline = [
165  0 => ['uid' => 2, 'title' => 'originalTitle'],
166  1 => ['uid' => 3, 'title' => 'originalTitle2'],
167  ];
168 
169  $updatedRootline = [
170  0 => ['uid' => 1, 'title' => 'newTitle'],
171  1 => ['uid' => 2, 'title' => 'newTitle2'],
172  2 => ['uid' => 3, 'title' => 'newTitle3'],
173  ];
174 
175  $expectedRootline = [
176  0 => ['uid' => 2, 'title' => 'newTitle2'],
177  1 => ['uid' => 3, 'title' => 'newTitle3'],
178  ];
179 
180  $this->templateService->rootLine = $originalRootline;
181  $this->templateService->updateRootlineData($updatedRootline);
182  self::assertEquals($expectedRootline, $this->templateService->rootLine);
183  }
184 
189  {
190  $originalRootline = [
191  0 => ['uid' => 2, 'title' => 'originalTitle'],
192  1 => ['uid' => 3, 'title' => 'originalTitle2'],
193  ];
194 
195  $newInvalidRootline = [
196  0 => ['uid' => 1, 'title' => 'newTitle'],
197  1 => ['uid' => 2, 'title' => 'newTitle2'],
198  ];
199 
200  $this->expectException(\RuntimeException::class);
201  $this->expectExceptionCode(1370419654);
202 
203  $this->templateService->rootLine = $originalRootline;
204  $this->templateService->updateRootlineData($newInvalidRootline);
205  }
206 }
‪TYPO3\CMS\Core\Tests\Unit\TypoScript\TemplateServiceTest\$templateService
‪TemplateService $templateService
Definition: TemplateServiceTest.php:43
‪TYPO3\CMS\Core\Tests\Unit\TypoScript
‪TYPO3\CMS\Core\Tests\Unit\TypoScript\TemplateServiceTest\$backupPackageManager
‪PackageManager $backupPackageManager
Definition: TemplateServiceTest.php:51
‪TYPO3\CMS\Core\Context\Context
Definition: Context.php:53
‪TYPO3\CMS\Core\Tests\Unit\TypoScript\TemplateServiceTest\updateRootlineDataOverwritesOwnArrayData
‪updateRootlineDataOverwritesOwnArrayData()
Definition: TemplateServiceTest.php:158
‪TYPO3\CMS\Core\Database\Query\QueryBuilder
Definition: QueryBuilder.php:52
‪TYPO3\CMS\Core\Site\Entity\Site
Definition: Site.php:40
‪TYPO3\CMS\Core\Utility\ExtensionManagementUtility
Definition: ExtensionManagementUtility.php:43
‪TYPO3\CMS\Core\Tests\Unit\TypoScript\TemplateServiceTest
Definition: TemplateServiceTest.php:40
‪TYPO3\CMS\Core\Tests\Unit\TypoScript\TemplateServiceTest\extensionStaticFilesAreNotProcessedIfNotExplicitlyRequested
‪extensionStaticFilesAreNotProcessedIfNotExplicitlyRequested()
Definition: TemplateServiceTest.php:104
‪TYPO3\CMS\Core\Utility\ExtensionManagementUtility\setPackageManager
‪static setPackageManager(PackageManager $packageManager)
Definition: ExtensionManagementUtility.php:66
‪TYPO3\CMS\Core\Tests\Unit\TypoScript\TemplateServiceTest\updateRootlineDataWithInvalidNewRootlineThrowsException
‪updateRootlineDataWithInvalidNewRootlineThrowsException()
Definition: TemplateServiceTest.php:184
‪TYPO3\CMS\Core\Package\Package
Definition: Package.php:26
‪TYPO3\CMS\Core\Tests\Unit\TypoScript\TemplateServiceTest\tearDown
‪tearDown()
Definition: TemplateServiceTest.php:95
‪TYPO3\CMS\Core\Tests\Unit\TypoScript\TemplateServiceTest\setUp
‪setUp()
Definition: TemplateServiceTest.php:60
‪TYPO3\CMS\Core\Tests\Unit\Utility\AccessibleProxies\ExtensionManagementUtilityAccessibleProxy\getPackageManager
‪static getPackageManager()
Definition: ExtensionManagementUtilityAccessibleProxy.php:32
‪TYPO3\CMS\Core\Tests\Unit\TypoScript\TemplateServiceTest\$packageManagerProphecy
‪PackageManager ObjectProphecy $packageManagerProphecy
Definition: TemplateServiceTest.php:55
‪TYPO3\CMS\Core\TypoScript\TemplateService
Definition: TemplateService.php:46
‪TYPO3\CMS\Frontend\Controller\TypoScriptFrontendController
Definition: TypoScriptFrontendController.php:98
‪TYPO3\CMS\Core\Tests\Unit\TypoScript\TemplateServiceTest\extensionStaticsAreProcessedIfExplicitlyRequested
‪extensionStaticsAreProcessedIfExplicitlyRequested()
Definition: TemplateServiceTest.php:123
‪$GLOBALS
‪$GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['adminpanel']['modules']
Definition: ext_localconf.php:5
‪TYPO3\CMS\Core\Tests\Unit\TypoScript\TemplateServiceTest\$templateServiceMock
‪PHPUnit Framework MockObject MockObject AccessibleObjectInterface TemplateService $templateServiceMock
Definition: TemplateServiceTest.php:47
‪TYPO3\CMS\Core\Database\ConnectionPool
Definition: ConnectionPool.php:46
‪TYPO3\CMS\Core\Tests\Unit\Utility\AccessibleProxies\ExtensionManagementUtilityAccessibleProxy
Definition: ExtensionManagementUtilityAccessibleProxy.php:26
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:46