‪TYPO3CMS  11.5
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 Prophecy\Argument;
21 use Prophecy\PhpUnit\ProphecyTrait;
22 use Psr\EventDispatcher\EventDispatcherInterface;
25 use TYPO3\TestingFramework\Core\Unit\UnitTestCase;
26 
27 class ‪PageTsConfigLoaderTest extends UnitTestCase
28 {
29  use ProphecyTrait;
30 
34  public function ‪alwaysLoadDefaultSettings(): void
35  {
36  $expected = [
37  'default' => ‪$GLOBALS['TYPO3_CONF_VARS']['BE']['defaultPageTSconfig'],
38  ];
39  $expectedString = implode('"\n[GLOBAL]\n"', $expected);
40  $eventDispatcher = $this->prophesize(EventDispatcherInterface::class);
41  $subject = new ‪PageTsConfigLoader($eventDispatcher->reveal());
42  $event = new ‪ModifyLoadedPageTsConfigEvent($expected, []);
43  $eventDispatcher->dispatch(Argument::type(ModifyLoadedPageTsConfigEvent::class))->willReturn($event);
44  $result = $subject->collect([]);
45  self::assertSame($expected, $result);
46 
47  $result = $subject->load([]);
48  self::assertSame($expectedString, $result);
49  }
50 
55  {
56  $expected = [
57  'default' => ‪$GLOBALS['TYPO3_CONF_VARS']['BE']['defaultPageTSconfig'],
58  'page_13' => 'waiting for = love',
59  'page_27' => '',
60  ];
61  $rootLine = [['uid' => 0, 'pid' => 0], ['uid' => 13, 'TSconfig' => 'waiting for = love'], ['uid' => 27, 'TSconfig' => '']];
62  $eventDispatcher = $this->prophesize(EventDispatcherInterface::class);
63  $event = new ‪ModifyLoadedPageTsConfigEvent($expected, $rootLine);
64  $eventDispatcher->dispatch(Argument::type(ModifyLoadedPageTsConfigEvent::class))->willReturn($event);
65  $subject = new ‪PageTsConfigLoader($eventDispatcher->reveal());
66  $result = $subject->collect($rootLine);
67  self::assertSame($expected, $result);
68  }
69 
74  {
75  $expected = [
76  'default' => ‪$GLOBALS['TYPO3_CONF_VARS']['BE']['defaultPageTSconfig'],
77  'page_13_includes_0' => 'Show_me = more
78 ',
79  'page_13' => 'waiting for = love',
80  'page_27' => '',
81  ];
82  $rootLine = [['uid' => 13, 'TSconfig' => 'waiting for = love', 'tsconfig_includes' => 'EXT:core/Tests/Unit/Configuration/Loader/Fixtures/included.typoscript'], ['uid' => 27, 'TSconfig' => '']];
83  $eventDispatcher = $this->prophesize(EventDispatcherInterface::class);
84  $event = new ‪ModifyLoadedPageTsConfigEvent($expected, $rootLine);
85  $eventDispatcher->dispatch(Argument::type(ModifyLoadedPageTsConfigEvent::class))->willReturn($event);
86  $subject = new ‪PageTsConfigLoader($eventDispatcher->reveal());
87  $result = $subject->collect($rootLine);
88  self::assertSame($expected, $result);
89  }
90 
94  public function ‪invalidExternalFileIsNotLoaded(): void
95  {
96  $expected = [
97  'default' => ‪$GLOBALS['TYPO3_CONF_VARS']['BE']['defaultPageTSconfig'],
98  'page_13' => 'waiting for = love',
99  'page_27' => '',
100  ];
101  $expectedString = implode("\n[GLOBAL]\n", $expected);
102  $rootLine = [['uid' => 13, 'TSconfig' => 'waiting for = love', 'tsconfig_includes' => 'EXT:core/Tests/Unit/Configuration/Loader/Fixtures/me_does_not_exist.typoscript'], ['uid' => 27, 'TSconfig' => '']];
103  $eventDispatcher = $this->prophesize(EventDispatcherInterface::class);
104  $event = new ‪ModifyLoadedPageTsConfigEvent($expected, $rootLine);
105  $eventDispatcher->dispatch(Argument::type(ModifyLoadedPageTsConfigEvent::class))->willReturn($event);
106  $subject = new ‪PageTsConfigLoader($eventDispatcher->reveal());
107  $result = $subject->collect($rootLine);
108  self::assertSame($expected, $result);
109 
110  $result = $subject->load($rootLine);
111  self::assertSame($expectedString, $result);
112  }
113 }
‪TYPO3\CMS\Core\Tests\Unit\Configuration\Loader\PageTsConfigLoaderTest
Definition: PageTsConfigLoaderTest.php:28
‪TYPO3\CMS\Core\Configuration\Loader\PageTsConfigLoader
Definition: PageTsConfigLoader.php:39
‪TYPO3\CMS\Core\Tests\Unit\Configuration\Loader\PageTsConfigLoaderTest\loadDefaultSettingsAtTheBeginningAndKeepEmptyEntriesExpectUidZero
‪loadDefaultSettingsAtTheBeginningAndKeepEmptyEntriesExpectUidZero()
Definition: PageTsConfigLoaderTest.php:53
‪TYPO3\CMS\Core\Tests\Unit\Configuration\Loader
Definition: PageTsConfigLoaderTest.php:18
‪TYPO3\CMS\Core\Tests\Unit\Configuration\Loader\PageTsConfigLoaderTest\loadExternalInclusionsCorrectlyAndKeepLoadingOrder
‪loadExternalInclusionsCorrectlyAndKeepLoadingOrder()
Definition: PageTsConfigLoaderTest.php:72
‪TYPO3\CMS\Core\Tests\Unit\Configuration\Loader\PageTsConfigLoaderTest\alwaysLoadDefaultSettings
‪alwaysLoadDefaultSettings()
Definition: PageTsConfigLoaderTest.php:33
‪TYPO3\CMS\Core\Configuration\Event\ModifyLoadedPageTsConfigEvent
Definition: ModifyLoadedPageTsConfigEvent.php:24
‪TYPO3\CMS\Core\Tests\Unit\Configuration\Loader\PageTsConfigLoaderTest\invalidExternalFileIsNotLoaded
‪invalidExternalFileIsNotLoaded()
Definition: PageTsConfigLoaderTest.php:93
‪$GLOBALS
‪$GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['adminpanel']['modules']
Definition: ext_localconf.php:25