‪TYPO3CMS  ‪main
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 
20 use PHPUnit\Framework\Attributes\Test;
24 use TYPO3\TestingFramework\Core\Unit\UnitTestCase;
25 
29 final class ‪AddonRegistryTest extends UnitTestCase
30 {
32 
33  protected function ‪setUp(): void
34  {
35  parent::setUp();
36  $this->subject = new ‪AddonRegistry();
37  $this->‪registerAddons();
38  }
39 
43  protected function ‪registerAddons(): void
44  {
45  $this->subject
46  ->register(GeneralUtility::makeInstance(Addon::class, 'addon/global'))
47  ->register(
48  GeneralUtility::makeInstance(Addon::class, 'addon/another/global')
49  ->setCssFiles(['EXT:foobar/Resources/Public/Css/Addon.css'])
50  )
51  ->register(
52  GeneralUtility::makeInstance(Addon::class, 'addon/with/same/cssfile')
53  ->setOptions([
54  'foobar' => true,
55  'husel' => 'pusel',
56  ])
57  ->setCssFiles(['EXT:foobar/Resources/Public/Css/Addon.css'])
58  )
59  ->register(
60  GeneralUtility::makeInstance(Addon::class, 'addon/with/settings')
61  ->setOptions([
62  'foobar' => false,
63  'randomInt' => 4, // chosen by fair dice roll
64  ])
65  );
66  }
67 
68  #[Test]
69  public function ‪globalAddonsGetReturned(): void
70  {
71  $expected = [
72  'addon/global',
73  'addon/another/global',
74  'addon/with/same/cssfile',
75  'addon/with/settings',
76  ];
77 
78  $actual = [];
79  foreach ($this->subject->getAddons() as $addon) {
80  $actual[] = $addon->getIdentifier();
81  }
82 
83  self::assertSame($expected, $actual);
84  }
85 
86  #[Test]
87  public function ‪settingsAreProperlyCompiled(): void
88  {
89  $expected = [
90  'foobar' => false,
91  'husel' => 'pusel',
92  'randomInt' => 4,
93  ];
94 
95  $actual = $this->subject->compileSettings($this->subject->getAddons());
96 
97  self::assertSame($expected, $actual);
98  }
99 }
‪TYPO3\CMS\Backend\CodeEditor\Registry\AddonRegistry
Definition: AddonRegistry.php:28
‪TYPO3\CMS\Backend\Tests\Unit\CodeEditor\Registry\AddonRegistryTest\settingsAreProperlyCompiled
‪settingsAreProperlyCompiled()
Definition: AddonRegistryTest.php:87
‪TYPO3\CMS\Backend\Tests\Unit\CodeEditor\Registry\AddonRegistryTest\globalAddonsGetReturned
‪globalAddonsGetReturned()
Definition: AddonRegistryTest.php:69
‪TYPO3\CMS\Backend\Tests\Unit\CodeEditor\Registry\AddonRegistryTest\registerAddons
‪registerAddons()
Definition: AddonRegistryTest.php:43
‪TYPO3\CMS\Backend\Tests\Unit\CodeEditor\Registry\AddonRegistryTest\setUp
‪setUp()
Definition: AddonRegistryTest.php:33
‪TYPO3\CMS\Backend\Tests\Unit\CodeEditor\Registry\AddonRegistryTest\$subject
‪AddonRegistry $subject
Definition: AddonRegistryTest.php:31
‪TYPO3\CMS\Backend\Tests\Unit\CodeEditor\Registry
Definition: AddonRegistryTest.php:18
‪TYPO3\CMS\Backend\CodeEditor\Addon
Definition: Addon.php:27
‪TYPO3\CMS\Backend\Tests\Unit\CodeEditor\Registry\AddonRegistryTest
Definition: AddonRegistryTest.php:30
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:52