[TASK] Shorten the extend class in all unit tests
[Packages/TYPO3.CMS.git] / typo3 / sysext / t3editor / Tests / Unit / Registry / AddonRegistryTest.php
1 <?php
2 declare(strict_types = 1);
3 namespace TYPO3\CMS\T3editor\Tests\Unit\Registry;
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
18 use TYPO3\CMS\Core\Utility\GeneralUtility;
19 use TYPO3\CMS\T3editor\Addon;
20 use TYPO3\CMS\T3editor\Registry\AddonRegistry;
21 use TYPO3\TestingFramework\Core\Unit\UnitTestCase;
22
23 /**
24 * Unit test class for Registry\AddonRegistry
25 */
26 class AddonRegistryTest extends UnitTestCase
27 {
28 /**
29 * @var AddonRegistry|\PHPUnit_Framework_MockObject_MockObject|\TYPO3\TestingFramework\Core\AccessibleObjectInterface
30 */
31 protected $subject;
32
33 protected function setUp()
34 {
35 $this->subject = $this->getAccessibleMock(AddonRegistry::class, ['dummy'], [], '', false);
36 $this->registerAddons();
37 }
38
39 /**
40 * Register addons for tests
41 */
42 protected function registerAddons()
43 {
44 $this->subject
45 ->register(GeneralUtility::makeInstance(Addon::class, 'addon/global'))
46 ->register(
47 GeneralUtility::makeInstance(Addon::class, 'addon/another/global')
48 ->setCssFiles(['EXT:foobar/Resources/Public/Css/Addon.css'])
49 )
50 ->register(
51 GeneralUtility::makeInstance(Addon::class, 'addon/with/same/cssfile')
52 ->setOptions([
53 'foobar' => true,
54 'husel' => 'pusel',
55 ])
56 ->setCssFiles(['EXT:foobar/Resources/Public/Css/Addon.css'])
57 )
58 ->register(
59 GeneralUtility::makeInstance(Addon::class, 'addon/for/mode')
60 ->setModes(['xml', 'htmlmixed'])
61 )
62 ->register(
63 GeneralUtility::makeInstance(Addon::class, 'addon/with/settings')
64 ->setOptions([
65 'foobar' => false,
66 'randomInt' => 4 // chosen by fair dice roll
67 ])
68 )
69 ;
70 }
71
72 /**
73 * @test
74 */
75 public function globalAddonsGetReturned()
76 {
77 $expected = [
78 'addon/global',
79 'addon/another/global',
80 'addon/with/same/cssfile',
81 'addon/with/settings',
82 ];
83
84 $actual = [];
85 foreach ($this->subject->getForMode() as $addon) {
86 $actual[] = $addon->getIdentifier();
87 }
88
89 static::assertSame($expected, $actual);
90 }
91
92 /**
93 * @test
94 */
95 public function globalAndModeAddonsGetReturned()
96 {
97 $expected = [
98 'addon/global',
99 'addon/another/global',
100 'addon/with/same/cssfile',
101 'addon/for/mode',
102 'addon/with/settings',
103 ];
104
105 $actual = [];
106 foreach ($this->subject->getForMode('xml') as $addon) {
107 $actual[] = $addon->getIdentifier();
108 }
109
110 static::assertSame($expected, $actual);
111 }
112
113 /**
114 * @test
115 */
116 public function settingsAreProperlyCompiled()
117 {
118 $expected = [
119 'foobar' => false,
120 'husel' => 'pusel',
121 'randomInt' => 4
122 ];
123
124 $actual = $this->subject->compileSettings($this->subject->getForMode());
125
126 static::assertSame($expected, $actual);
127 }
128 }