‪TYPO3CMS  ‪main
PageTsConfigLoaderTest.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 Psr\EventDispatcher\EventDispatcherInterface;
24 use TYPO3\TestingFramework\Core\Unit\UnitTestCase;
25 
26 final class ‪PageTsConfigLoaderTest extends UnitTestCase
27 {
31  public function ‪alwaysLoadDefaultSettings(): void
32  {
33  $expected = [
34  'default' => ‪$GLOBALS['TYPO3_CONF_VARS']['BE']['defaultPageTSconfig'],
35  ];
36  $expectedString = implode('"\n[GLOBAL]\n"', $expected);
37  $eventDispatcherMock = $this->createMock(EventDispatcherInterface::class);
38  $subject = new ‪PageTsConfigLoader($eventDispatcherMock);
39  $event = new ‪ModifyLoadedPageTsConfigEvent($expected, []);
40  $eventDispatcherMock->method('dispatch')->with(self::isInstanceOf(ModifyLoadedPageTsConfigEvent::class))->willReturn($event);
41  $result = $subject->collect([]);
42  self::assertSame($expected, $result);
43 
44  $result = $subject->load([]);
45  self::assertSame($expectedString, $result);
46  }
47 
52  {
53  $expected = [
54  'default' => ‪$GLOBALS['TYPO3_CONF_VARS']['BE']['defaultPageTSconfig'],
55  'page_13' => 'waiting for = love',
56  'page_27' => '',
57  ];
58  $rootLine = [['uid' => 0, 'pid' => 0], ['uid' => 13, 'TSconfig' => 'waiting for = love'], ['uid' => 27, 'TSconfig' => '']];
59  $eventDispatcherMock = $this->createMock(EventDispatcherInterface::class);
60  $event = new ‪ModifyLoadedPageTsConfigEvent($expected, $rootLine);
61  $eventDispatcherMock->method('dispatch')->with(self::isInstanceOf(ModifyLoadedPageTsConfigEvent::class))->willReturn($event);
62  $subject = new ‪PageTsConfigLoader($eventDispatcherMock);
63  $result = $subject->collect($rootLine);
64  self::assertSame($expected, $result);
65  }
66 
71  {
72  $expected = [
73  'global' => '',
74  'default' => ‪$GLOBALS['TYPO3_CONF_VARS']['BE']['defaultPageTSconfig'],
75  'page_13_includes_0' => 'Show_me = more
76 ',
77  'page_13' => 'waiting for = love',
78  'page_27' => '',
79  ];
80  $rootLine = [['uid' => 13, 'TSconfig' => 'waiting for = love', 'tsconfig_includes' => 'EXT:core/Tests/UnitDeprecated/Configuration/Loader/Fixtures/included.typoscript'], ['uid' => 27, 'TSconfig' => '']];
81  $subject = new ‪PageTsConfigLoader(new ‪NoopEventDispatcher());
82  $result = $subject->collect($rootLine);
83  self::assertSame($expected, $result);
84  }
85 
89  public function ‪invalidExternalFileIsNotLoaded(): void
90  {
91  $expected = [
92  'global' => '',
93  'default' => ‪$GLOBALS['TYPO3_CONF_VARS']['BE']['defaultPageTSconfig'],
94  'page_13' => 'waiting for = love',
95  'page_27' => '',
96  ];
97  $expectedString = implode("\n[GLOBAL]\n", $expected);
98  $rootLine = [['uid' => 13, 'TSconfig' => 'waiting for = love', 'tsconfig_includes' => 'EXT:core/Tests/UnitDeprecated/Configuration/Loader/Fixtures/me_does_not_exist.typoscript'], ['uid' => 27, 'TSconfig' => '']];
99  $subject = new ‪PageTsConfigLoader(new ‪NoopEventDispatcher());
100  $result = $subject->collect($rootLine);
101  self::assertSame($expected, $result);
102 
103  $result = $subject->load($rootLine);
104  self::assertSame($expectedString, $result);
105  }
106 }
‪TYPO3\CMS\Core\Configuration\Loader\PageTsConfigLoader
Definition: PageTsConfigLoader.php:42
‪TYPO3\CMS\Core\Tests\UnitDeprecated\Configuration\Loader\PageTsConfigLoaderTest
Definition: PageTsConfigLoaderTest.php:27
‪TYPO3\CMS\Core\Configuration\Event\ModifyLoadedPageTsConfigEvent
Definition: ModifyLoadedPageTsConfigEvent.php:27
‪TYPO3\CMS\Core\EventDispatcher\NoopEventDispatcher
Definition: NoopEventDispatcher.php:29
‪$GLOBALS
‪$GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['adminpanel']['modules']
Definition: ext_localconf.php:25
‪TYPO3\CMS\Core\Tests\UnitDeprecated\Configuration\Loader
Definition: PageTsConfigLoaderTest.php:18
‪TYPO3\CMS\Core\Tests\UnitDeprecated\Configuration\Loader\PageTsConfigLoaderTest\loadExternalInclusionsCorrectlyAndKeepLoadingOrder
‪loadExternalInclusionsCorrectlyAndKeepLoadingOrder()
Definition: PageTsConfigLoaderTest.php:70
‪TYPO3\CMS\Core\Tests\UnitDeprecated\Configuration\Loader\PageTsConfigLoaderTest\loadDefaultSettingsAtTheBeginningAndKeepEmptyEntriesExpectUidZero
‪loadDefaultSettingsAtTheBeginningAndKeepEmptyEntriesExpectUidZero()
Definition: PageTsConfigLoaderTest.php:51
‪TYPO3\CMS\Core\Tests\UnitDeprecated\Configuration\Loader\PageTsConfigLoaderTest\invalidExternalFileIsNotLoaded
‪invalidExternalFileIsNotLoaded()
Definition: PageTsConfigLoaderTest.php:89
‪TYPO3\CMS\Core\Tests\UnitDeprecated\Configuration\Loader\PageTsConfigLoaderTest\alwaysLoadDefaultSettings
‪alwaysLoadDefaultSettings()
Definition: PageTsConfigLoaderTest.php:31