‪TYPO3CMS  ‪main
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 PHPUnit\Framework\MockObject\MockObject;
23 use TYPO3\CMS\Core\Database\Query\QueryBuilder;
25 use TYPO3\CMS\Core\Package\PackageManager;
32 use TYPO3\TestingFramework\Core\AccessibleObjectInterface;
33 use TYPO3\TestingFramework\Core\Unit\UnitTestCase;
34 
35 final class ‪TemplateServiceTest extends UnitTestCase
36 {
38  protected MockObject&AccessibleObjectInterface&‪TemplateService ‪$templateServiceMock;
39  protected ?PackageManager ‪$backupPackageManager;
40  protected MockObject&PackageManager ‪$packageManagerMock;
41 
42  protected function ‪setUp(): void
43  {
44  parent::setUp();
45  ‪$GLOBALS['SIM_ACCESS_TIME'] = time();
46  ‪$GLOBALS['ACCESS_TIME'] = time();
47  $this->packageManagerMock = $this->createMock(PackageManager::class);
48  $frontendControllerMock = $this->createMock(TypoScriptFrontendController::class);
49  $frontendControllerMock->method('getSite')->willReturn(new ‪Site('dummy', 13, [
50  'base' => 'https://example.com',
51  'settings' => [
52  'random' => 'value',
53  'styles' => [
54  'content' => [
55  'loginform' => [
56  'pid' => 123,
57  ],
58  ],
59  ],
60  'numberedThings' => [
61  1 => 'foo',
62  99 => 'bar',
63  ],
64  ],
65  ]));
66  $this->templateService = new ‪TemplateService(
67  new ‪Context(),
68  $this->packageManagerMock,
69  $frontendControllerMock
70  );
72  }
73 
74  public function ‪tearDown(): void
75  {
77  parent::tearDown();
78  }
79 
84  {
85  $queryBuilderMock = $this->createMock(QueryBuilder::class);
86  $connectionPoolMock = $this->createMock(ConnectionPool::class);
87  $connectionPoolMock->method('getQueryBuilderForTable')->with(self::anything())->willReturn($queryBuilderMock);
88  GeneralUtility::addInstance(ConnectionPool::class, $connectionPoolMock);
89 
90  $this->packageManagerMock->expects(self::never())->method('getActivePackages');
91 
92  $this->templateService->runThroughTemplates([], 0);
93  self::assertNotContains(
94  'test.Core.TypoScript = 1',
95  $this->templateService->config
96  );
97  }
98 
103  {
104  $queryBuilderMock = $this->createMock(QueryBuilder::class);
105  $connectionPoolMock = $this->createMock(ConnectionPool::class);
106  $connectionPoolMock->method('getQueryBuilderForTable')->with(self::anything())->willReturn($queryBuilderMock);
107  GeneralUtility::addInstance(ConnectionPool::class, $connectionPoolMock);
108 
109  $mockPackage = $this->getMockBuilder(Package::class)
110  ->onlyMethods(['getPackagePath', 'getPackageKey'])
111  ->disableOriginalConstructor()
112  ->getMock();
113  $mockPackage->method('getPackagePath')->willReturn(__DIR__ . '/Fixtures/');
114  $mockPackage->method('getPackageKey')->willReturn('core');
115 
116  $mockPackageManager = $this->getMockBuilder(PackageManager::class)
117  ->onlyMethods(['isPackageActive', 'getPackage'])
118  ->disableOriginalConstructor()
119  ->getMock();
120  $mockPackageManager->method('isPackageActive')->willReturn(true);
121  $mockPackageManager->method('getPackage')->willReturn($mockPackage);
123  $this->packageManagerMock->method('getActivePackages')->willReturn(['core' => $mockPackage]);
124 
125  $this->templateService->setProcessExtensionStatics(true);
126  $this->templateService->runThroughTemplates([], 0);
127 
128  self::assertContains(
129  'test.Core.TypoScript = 1',
130  $this->templateService->config
131  );
132  }
133 }
‪TYPO3\CMS\Core\Tests\UnitDeprecated\TypoScript\TemplateServiceTest\$templateServiceMock
‪MockObject &AccessibleObjectInterface &TemplateService $templateServiceMock
Definition: TemplateServiceTest.php:38
‪TYPO3\CMS\Core\Tests\UnitDeprecated\TypoScript\TemplateServiceTest\setUp
‪setUp()
Definition: TemplateServiceTest.php:42
‪TYPO3\CMS\Core\Tests\UnitDeprecated\TypoScript\TemplateServiceTest\extensionStaticFilesAreNotProcessedIfNotExplicitlyRequested
‪extensionStaticFilesAreNotProcessedIfNotExplicitlyRequested()
Definition: TemplateServiceTest.php:83
‪TYPO3\CMS\Core\Context\Context
Definition: Context.php:55
‪TYPO3\CMS\Core\Tests\UnitDeprecated\TypoScript\TemplateServiceTest\$backupPackageManager
‪PackageManager $backupPackageManager
Definition: TemplateServiceTest.php:39
‪TYPO3\CMS\Core\Site\Entity\Site
Definition: Site.php:42
‪TYPO3\CMS\Core\Utility\ExtensionManagementUtility
Definition: ExtensionManagementUtility.php:40
‪TYPO3\CMS\Core\Utility\ExtensionManagementUtility\setPackageManager
‪static setPackageManager(PackageManager $packageManager)
Definition: ExtensionManagementUtility.php:61
‪TYPO3\CMS\Core\Tests\UnitDeprecated\TypoScript\TemplateServiceTest\$packageManagerMock
‪MockObject &PackageManager $packageManagerMock
Definition: TemplateServiceTest.php:40
‪TYPO3\CMS\Core\Tests\UnitDeprecated\TypoScript\TemplateServiceTest
Definition: TemplateServiceTest.php:36
‪TYPO3\CMS\Core\Package\Package
Definition: Package.php:28
‪TYPO3\CMS\Core\Tests\UnitDeprecated\TypoScript\TemplateServiceTest\extensionStaticsAreProcessedIfExplicitlyRequested
‪extensionStaticsAreProcessedIfExplicitlyRequested()
Definition: TemplateServiceTest.php:102
‪TYPO3\CMS\Core\Tests\Unit\Utility\AccessibleProxies\ExtensionManagementUtilityAccessibleProxy\getPackageManager
‪static getPackageManager()
Definition: ExtensionManagementUtilityAccessibleProxy.php:35
‪TYPO3\CMS\Core\TypoScript\TemplateService
Definition: TemplateService.php:46
‪TYPO3\CMS\Frontend\Controller\TypoScriptFrontendController
Definition: TypoScriptFrontendController.php:105
‪$GLOBALS
‪$GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['adminpanel']['modules']
Definition: ext_localconf.php:25
‪TYPO3\CMS\Core\Tests\UnitDeprecated\TypoScript\TemplateServiceTest\$templateService
‪TemplateService $templateService
Definition: TemplateServiceTest.php:37
‪TYPO3\CMS\Core\Database\ConnectionPool
Definition: ConnectionPool.php:51
‪TYPO3\CMS\Core\Tests\Unit\Utility\AccessibleProxies\ExtensionManagementUtilityAccessibleProxy
Definition: ExtensionManagementUtilityAccessibleProxy.php:29
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:51
‪TYPO3\CMS\Core\Tests\UnitDeprecated\TypoScript
‪TYPO3\CMS\Core\Tests\UnitDeprecated\TypoScript\TemplateServiceTest\tearDown
‪tearDown()
Definition: TemplateServiceTest.php:74