‪TYPO3CMS  10.4
AddonRegistryTest.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 
23 use TYPO3\TestingFramework\Core\Unit\UnitTestCase;
24 
28 class ‪AddonRegistryTest extends UnitTestCase
29 {
33  protected ‪$subject;
34 
35  protected function ‪setUp(): void
36  {
37  $this->subject = new ‪AddonRegistry();
38  $this->‪registerAddons();
39  }
40 
44  protected function ‪registerAddons(): void
45  {
46  $this->subject
47  ->register(GeneralUtility::makeInstance(Addon::class, 'addon/global'))
48  ->register(
49  GeneralUtility::makeInstance(Addon::class, 'addon/another/global')
50  ->setCssFiles(['EXT:foobar/Resources/Public/Css/Addon.css'])
51  )
52  ->register(
53  GeneralUtility::makeInstance(Addon::class, 'addon/with/same/cssfile')
54  ->setOptions([
55  'foobar' => true,
56  'husel' => 'pusel',
57  ])
58  ->setCssFiles(['EXT:foobar/Resources/Public/Css/Addon.css'])
59  )
60  ->register(
61  GeneralUtility::makeInstance(Addon::class, 'addon/for/mode')
62  ->setModes(['xml', 'htmlmixed'])
63  )
64  ->register(
65  GeneralUtility::makeInstance(Addon::class, 'addon/with/settings')
66  ->setOptions([
67  'foobar' => false,
68  'randomInt' => 4 // chosen by fair dice roll
69  ])
70  )
71  ;
72  }
73 
77  public function ‪globalAddonsGetReturned(): void
78  {
79  $expected = [
80  'addon/global',
81  'addon/another/global',
82  'addon/with/same/cssfile',
83  'addon/with/settings',
84  ];
85 
86  $actual = [];
87  foreach ($this->subject->getForMode() as $addon) {
88  $actual[] = $addon->getIdentifier();
89  }
90 
91  self::assertSame($expected, $actual);
92  }
93 
97  public function ‪globalAndModeAddonsGetReturned(): void
98  {
99  $expected = [
100  'addon/global',
101  'addon/another/global',
102  'addon/with/same/cssfile',
103  'addon/for/mode',
104  'addon/with/settings',
105  ];
106 
107  $actual = [];
108  foreach ($this->subject->getForMode('xml') as $addon) {
109  $actual[] = $addon->getIdentifier();
110  }
111 
112  self::assertSame($expected, $actual);
113  }
114 
118  public function ‪settingsAreProperlyCompiled(): void
119  {
120  $expected = [
121  'foobar' => false,
122  'husel' => 'pusel',
123  'randomInt' => 4
124  ];
125 
126  $actual = $this->subject->compileSettings($this->subject->getForMode());
127 
128  self::assertSame($expected, $actual);
129  }
130 }
‪TYPO3\CMS\T3editor\Registry\AddonRegistry
Definition: AddonRegistry.php:29
‪TYPO3\CMS\T3editor\Tests\Unit\Registry\AddonRegistryTest\globalAddonsGetReturned
‪globalAddonsGetReturned()
Definition: AddonRegistryTest.php:76
‪TYPO3\CMS\T3editor\Tests\Unit\Registry\AddonRegistryTest\setUp
‪setUp()
Definition: AddonRegistryTest.php:34
‪TYPO3\CMS\T3editor\Tests\Unit\Registry\AddonRegistryTest\$subject
‪AddonRegistry $subject
Definition: AddonRegistryTest.php:32
‪TYPO3\CMS\T3editor\Tests\Unit\Registry\AddonRegistryTest\registerAddons
‪registerAddons()
Definition: AddonRegistryTest.php:43
‪TYPO3\CMS\T3editor\Addon
Definition: Addon.php:25
‪TYPO3\CMS\T3editor\Tests\Unit\Registry
Definition: AddonRegistryTest.php:18
‪TYPO3\CMS\T3editor\Tests\Unit\Registry\AddonRegistryTest\globalAndModeAddonsGetReturned
‪globalAndModeAddonsGetReturned()
Definition: AddonRegistryTest.php:96
‪TYPO3\CMS\T3editor\Tests\Unit\Registry\AddonRegistryTest\settingsAreProperlyCompiled
‪settingsAreProperlyCompiled()
Definition: AddonRegistryTest.php:117
‪TYPO3\CMS\T3editor\Tests\Unit\Registry\AddonRegistryTest
Definition: AddonRegistryTest.php:29
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:46