‪TYPO3CMS  10.4
ModuleLoaderTest.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 
26 use TYPO3\TestingFramework\Core\Unit\UnitTestCase;
27 
28 class ‪ModuleLoaderTest extends UnitTestCase
29 {
30 
35  {
36  $moduleLoader = new ‪ModuleLoader();
37  $result = $moduleLoader->validateSortAndInitializeModules([]);
38 
39  self::assertSame([], $result);
40  }
41 
42  public function ‪missingConfigurationDataProvider(): array
43  {
44  return [
45  'empty' => [['modulename' => []]],
46  'no array' => [['modulename' => '']],
47  ];
48  }
49 
55  {
56  $this->expectException(InvalidConfigurationException::class);
57  $this->expectExceptionCode(1519490105);
58 
59  $moduleLoader = new ‪ModuleLoader();
60  $moduleLoader->validateSortAndInitializeModules($configuration);
61  }
62 
63  public function ‪invalidConfigurationDataProvider(): array
64  {
65  return [
66  'module class name is no string' => [
67  [
68  'modulename' => ['module' => []],
69  ],
70  ],
71  'module class name is empty' => [
72  [
73  'modulename' => ['module' => ''],
74  ],
75  ],
76  'module class name is no valid class' => [
77  [
78  'modulename' => ['module' => 'nonExistingClassName'],
79  ],
80  ],
81  'module class name does not implement AdminPanelModuleInterface' => [
82  [
83  'modulename' => ['module' => \stdClass::class],
84  ],
85  ]
86  ];
87  }
88 
94  {
95  $this->expectException(InvalidConfigurationException::class);
96  $this->expectExceptionCode(1519490112);
97 
98  $moduleLoader = new ‪ModuleLoader();
99  $moduleLoader->validateSortAndInitializeModules($configuration);
100  }
101 
106  {
107  $config = [
108  'module1' => [
109  'module' => MainModuleFixture::class
110  ]
111  ];
112 
113  $dependencyOrderingServiceProphecy = $this->prophesize(DependencyOrderingService::class);
114  GeneralUtility::addInstance(DependencyOrderingService::class, $dependencyOrderingServiceProphecy->reveal());
115  $dependencyOrderingServiceProphecy->orderByDependencies($config)->willReturn($config);
116 
117  $moduleLoader = new ‪ModuleLoader();
118  $moduleLoader->validateSortAndInitializeModules($config);
119 
120  $dependencyOrderingServiceProphecy->orderByDependencies($config)->shouldHaveBeenCalled();
121  }
122 
127  {
128  $config = [
129  'module1' => [
130  'module' => MainModuleFixture::class
131  ],
132  'module2' => [
133  'module' => DisabledMainModuleFixture::class
134  ]
135  ];
136 
137  $dependencyOrderingServiceProphecy = $this->prophesize(DependencyOrderingService::class);
138  GeneralUtility::addInstance(DependencyOrderingService::class, $dependencyOrderingServiceProphecy->reveal());
139  $dependencyOrderingServiceProphecy->orderByDependencies($config)->willReturn($config);
140 
141  $moduleLoader = new ‪ModuleLoader();
142  $result = $moduleLoader->validateSortAndInitializeModules($config);
143 
144  self::assertCount(1, $result);
145  self::assertInstanceOf(MainModuleFixture::class, $result['example']);
146  self::assertArrayNotHasKey('example-disabled', $result);
147  }
148 }
‪TYPO3\CMS\Adminpanel\Tests\Unit\Service\ModuleLoaderTest\validateSortAndInitializeModulesThrowsExceptionIfModuleHasMissingConfiguration
‪validateSortAndInitializeModulesThrowsExceptionIfModuleHasMissingConfiguration($configuration)
Definition: ModuleLoaderTest.php:54
‪TYPO3\CMS\Adminpanel\Tests\Unit\Service\ModuleLoaderTest\validateSortAndInitializeModulesReturnsEmptyArrayIfNoModulesAreConfigured
‪validateSortAndInitializeModulesReturnsEmptyArrayIfNoModulesAreConfigured()
Definition: ModuleLoaderTest.php:34
‪TYPO3\CMS\Adminpanel\Service\ModuleLoader
Definition: ModuleLoader.php:33
‪TYPO3\CMS\Adminpanel\Tests\Unit\Service\ModuleLoaderTest\validateSortAndInitializeModulesInstantiatesMainModulesOnlyIfEnabled
‪validateSortAndInitializeModulesInstantiatesMainModulesOnlyIfEnabled()
Definition: ModuleLoaderTest.php:126
‪TYPO3\CMS\Adminpanel\Tests\Unit\Service\ModuleLoaderTest\invalidConfigurationDataProvider
‪invalidConfigurationDataProvider()
Definition: ModuleLoaderTest.php:63
‪TYPO3\CMS\Adminpanel\Tests\Unit\Fixtures\MainModuleFixture
Definition: MainModuleFixture.php:39
‪TYPO3\CMS\Adminpanel\Tests\Unit\Service\ModuleLoaderTest
Definition: ModuleLoaderTest.php:29
‪TYPO3\CMS\Adminpanel\Exceptions\InvalidConfigurationException
Definition: InvalidConfigurationException.php:24
‪TYPO3\CMS\Core\Service\DependencyOrderingService
Definition: DependencyOrderingService.php:32
‪TYPO3\CMS\Adminpanel\Tests\Unit\Fixtures\DisabledMainModuleFixture
Definition: DisabledMainModuleFixture.php:21
‪TYPO3\CMS\Adminpanel\Tests\Unit\Service
Definition: ConfigurationServiceTest.php:18
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:46
‪TYPO3\CMS\Adminpanel\Tests\Unit\Service\ModuleLoaderTest\validateSortAndInitializeModulesOrdersModulesWithDependencyOrderingService
‪validateSortAndInitializeModulesOrdersModulesWithDependencyOrderingService()
Definition: ModuleLoaderTest.php:105
‪TYPO3\CMS\Adminpanel\Tests\Unit\Service\ModuleLoaderTest\missingConfigurationDataProvider
‪missingConfigurationDataProvider()
Definition: ModuleLoaderTest.php:42
‪TYPO3\CMS\Adminpanel\Tests\Unit\Service\ModuleLoaderTest\validateSortAndInitializeModulesThrowsExceptionIfModuleHasInvalidConfiguration
‪validateSortAndInitializeModulesThrowsExceptionIfModuleHasInvalidConfiguration($configuration)
Definition: ModuleLoaderTest.php:93