‪TYPO3CMS  9.5
TemplateServiceTest.php
Go to the documentation of this file.
1 <?php
2 declare(strict_types = 1);
3 
5 
6 /*
7  * This file is part of the TYPO3 CMS project.
8  *
9  * It is free software; you can redistribute it and/or modify it under
10  * the terms of the GNU General Public License, either version 2
11  * of the License, or any later version.
12  *
13  * For the full copyright and license information, please read the
14  * LICENSE.txt file that was distributed with this source code.
15  *
16  * The TYPO3 project - inspiring people to share!
17  */
18 
19 use Prophecy\Argument;
20 use Prophecy\Prophecy\ObjectProphecy;
25 use TYPO3\CMS\Core\Package\PackageManager;
30 use TYPO3\TestingFramework\Core\AccessibleObjectInterface;
31 use TYPO3\TestingFramework\Core\Unit\UnitTestCase;
32 
36 class ‪TemplateServiceTest extends UnitTestCase
37 {
41  protected ‪$templateService;
42 
46  protected ‪$templateServiceMock;
47 
51  protected ‪$backupPackageManager;
52 
57 
61  protected function ‪setUp(): void
62  {
63  ‪$GLOBALS['SIM_ACCESS_TIME'] = time();
64  ‪$GLOBALS['ACCESS_TIME'] = time();
65  $this->packageManagerProphecy = $this->prophesize(PackageManager::class);
66  $this->templateService = new ‪TemplateService(new ‪Context(), $this->packageManagerProphecy->reveal());
67  $this->templateServiceMock = $this->getAccessibleMock(
68  TemplateService::class,
69  ['dummy'],
70  [new ‪Context(), $this->packageManagerProphecy->reveal()]
71  );
73  }
74 
78  public function ‪tearDown(): void
79  {
81  parent::tearDown();
82  }
83 
88  {
89  $queryBuilderProphet = $this->prophesize(QueryBuilder::class);
90  $connectionPoolProphet = $this->prophesize(ConnectionPool::class);
91  $connectionPoolProphet->getQueryBuilderForTable(Argument::cetera())->willReturn($queryBuilderProphet->reveal());
92  GeneralUtility::addInstance(ConnectionPool::class, $connectionPoolProphet->reveal());
93 
94  $this->packageManagerProphecy->getActivePackages()->shouldNotBeCalled();
95 
96  $this->templateService->runThroughTemplates([], 0);
97  $this->assertFalse(
98  in_array('test.Core.TypoScript = 1', $this->templateService->config, true)
99  );
100  }
101 
106  {
107  $queryBuilderProphet = $this->prophesize(QueryBuilder::class);
108  $connectionPoolProphet = $this->prophesize(ConnectionPool::class);
109  $connectionPoolProphet->getQueryBuilderForTable(Argument::cetera())->willReturn($queryBuilderProphet->reveal());
110  GeneralUtility::addInstance(ConnectionPool::class, $connectionPoolProphet->reveal());
111 
112  $mockPackage = $this->getMockBuilder(Package::class)
113  ->setMethods(['getPackagePath', 'getPackageKey'])
114  ->disableOriginalConstructor()
115  ->getMock();
116  $mockPackage->expects($this->any())->method('getPackagePath')->will($this->returnValue(__DIR__ . '/Fixtures/'));
117  $mockPackage->expects($this->any())->method('getPackageKey')->will($this->returnValue('core'));
118 
119  $mockPackageManager = $this->getMockBuilder(PackageManager::class)
120  ->setMethods(['isPackageActive', 'getPackage'])
121  ->disableOriginalConstructor()
122  ->getMock();
123  $mockPackageManager->expects($this->any())->method('isPackageActive')->will($this->returnValue(true));
124  $mockPackageManager->expects($this->any())->method('getPackage')->will($this->returnValue($mockPackage));
126  $this->packageManagerProphecy->getActivePackages()->willReturn(['core' => $mockPackage]);
127 
128  $this->templateService->setProcessExtensionStatics(true);
129  $this->templateService->runThroughTemplates([], 0);
130 
131  $this->assertTrue(
132  in_array('test.Core.TypoScript = 1', $this->templateService->config, true)
133  );
134  }
135 
139  public function ‪updateRootlineDataOverwritesOwnArrayData(): void
140  {
141  $originalRootline = [
142  0 => ['uid' => 2, 'title' => 'originalTitle'],
143  1 => ['uid' => 3, 'title' => 'originalTitle2'],
144  ];
145 
146  $updatedRootline = [
147  0 => ['uid' => 1, 'title' => 'newTitle'],
148  1 => ['uid' => 2, 'title' => 'newTitle2'],
149  2 => ['uid' => 3, 'title' => 'newTitle3'],
150  ];
151 
152  $expectedRootline = [
153  0 => ['uid' => 2, 'title' => 'newTitle2'],
154  1 => ['uid' => 3, 'title' => 'newTitle3'],
155  ];
156 
157  $this->templateServiceMock->_set('rootLine', $originalRootline);
158  $this->templateServiceMock->updateRootlineData($updatedRootline);
159  $this->assertEquals($expectedRootline, $this->templateServiceMock->_get('rootLine'));
160  }
161 
166  {
167  $originalRootline = [
168  0 => ['uid' => 2, 'title' => 'originalTitle'],
169  1 => ['uid' => 3, 'title' => 'originalTitle2'],
170  ];
171 
172  $newInvalidRootline = [
173  0 => ['uid' => 1, 'title' => 'newTitle'],
174  1 => ['uid' => 2, 'title' => 'newTitle2'],
175  ];
176 
177  $this->expectException(\RuntimeException::class);
178  $this->expectExceptionCode(1370419654);
179 
180  $this->templateServiceMock->_set('rootLine', $originalRootline);
181  $this->templateServiceMock->updateRootlineData($newInvalidRootline);
182  }
183 }
‪TYPO3\CMS\Core\Tests\Unit\TypoScript\TemplateServiceTest\$templateService
‪TemplateService $templateService
Definition: TemplateServiceTest.php:40
‪TYPO3\CMS\Core\Tests\Unit\TypoScript
‪TYPO3\CMS\Core\Tests\Unit\TypoScript\TemplateServiceTest\$backupPackageManager
‪PackageManager $backupPackageManager
Definition: TemplateServiceTest.php:48
‪TYPO3\CMS\Core\Context\Context
Definition: Context.php:49
‪TYPO3\CMS\Core\Tests\Unit\TypoScript\TemplateServiceTest\updateRootlineDataOverwritesOwnArrayData
‪updateRootlineDataOverwritesOwnArrayData()
Definition: TemplateServiceTest.php:135
‪TYPO3\CMS\Core\Database\Query\QueryBuilder
Definition: QueryBuilder.php:47
‪TYPO3\CMS\Core\Utility\ExtensionManagementUtility
Definition: ExtensionManagementUtility.php:36
‪TYPO3\CMS\Core\Tests\Unit\TypoScript\TemplateServiceTest
Definition: TemplateServiceTest.php:37
‪TYPO3\CMS\Core\Tests\Unit\TypoScript\TemplateServiceTest\extensionStaticFilesAreNotProcessedIfNotExplicitlyRequested
‪extensionStaticFilesAreNotProcessedIfNotExplicitlyRequested()
Definition: TemplateServiceTest.php:83
‪TYPO3\CMS\Core\Utility\ExtensionManagementUtility\setPackageManager
‪static setPackageManager(PackageManager $packageManager)
Definition: ExtensionManagementUtility.php:63
‪TYPO3\CMS\Core\Tests\Unit\TypoScript\TemplateServiceTest\updateRootlineDataWithInvalidNewRootlineThrowsException
‪updateRootlineDataWithInvalidNewRootlineThrowsException()
Definition: TemplateServiceTest.php:161
‪TYPO3\CMS\Core\Package\Package
Definition: Package.php:21
‪TYPO3\CMS\Core\Tests\Unit\TypoScript\TemplateServiceTest\tearDown
‪tearDown()
Definition: TemplateServiceTest.php:74
‪TYPO3\CMS\Core\Tests\Unit\TypoScript\TemplateServiceTest\setUp
‪setUp()
Definition: TemplateServiceTest.php:57
‪TYPO3\CMS\Core\Tests\Unit\TypoScript\TemplateServiceTest\$templateServiceMock
‪PHPUnit_Framework_MockObject_MockObject AccessibleObjectInterface TemplateService $templateServiceMock
Definition: TemplateServiceTest.php:44
‪TYPO3\CMS\Core\Tests\Unit\Utility\AccessibleProxies\ExtensionManagementUtilityAccessibleProxy\getPackageManager
‪static getPackageManager()
Definition: ExtensionManagementUtilityAccessibleProxy.php:37
‪TYPO3\CMS\Core\Tests\Unit\TypoScript\TemplateServiceTest\$packageManagerProphecy
‪PackageManager ObjectProphecy $packageManagerProphecy
Definition: TemplateServiceTest.php:52
‪TYPO3\CMS\Core\TypoScript\TemplateService
Definition: TemplateService.php:50
‪TYPO3\CMS\Core\Tests\Unit\TypoScript\TemplateServiceTest\extensionStaticsAreProcessedIfExplicitlyRequested
‪extensionStaticsAreProcessedIfExplicitlyRequested()
Definition: TemplateServiceTest.php:101
‪$GLOBALS
‪$GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['adminpanel']['modules']
Definition: ext_localconf.php:5
‪TYPO3\CMS\Core\Database\ConnectionPool
Definition: ConnectionPool.php:44
‪TYPO3\CMS\Core\Tests\Unit\Utility\AccessibleProxies\ExtensionManagementUtilityAccessibleProxy
Definition: ExtensionManagementUtilityAccessibleProxy.php:26
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:45