‪TYPO3CMS  9.5
ModuleLoaderTest.php
Go to the documentation of this file.
1 <?php
2 declare(strict_types = 1);
3 
5 
6 /*
7  * This file is part of the TYPO3 CMS project.
8  *
9  * It is free software; you can redistribute it and/or modify it under
10  * the terms of the GNU General Public License, either version 2
11  * of the License, or any later version.
12  *
13  * For the full copyright and license information, please read the
14  * LICENSE.txt file that was distributed with this source code.
15  *
16  * The TYPO3 project - inspiring people to share!
17  */
18 
25 use TYPO3\TestingFramework\Core\Unit\UnitTestCase;
26 
27 class ‪ModuleLoaderTest extends UnitTestCase
28 {
29 
34  {
35  $moduleLoader = new ‪ModuleLoader();
36  $result = $moduleLoader->validateSortAndInitializeModules([]);
37 
38  self::assertSame([], $result);
39  }
40 
41  public function ‪missingConfigurationDataProvider(): array
42  {
43  return [
44  'empty' => [['modulename' => []]],
45  'no array' => [['modulename' => '']],
46  ];
47  }
48 
54  {
55  $this->expectException(InvalidConfigurationException::class);
56  $this->expectExceptionCode(1519490105);
57 
58  $moduleLoader = new ‪ModuleLoader();
59  $moduleLoader->validateSortAndInitializeModules($configuration);
60  }
61 
62  public function ‪invalidConfigurationDataProvider(): array
63  {
64  return [
65  'module class name is no string' => [
66  [
67  'modulename' => ['module' => []],
68  ],
69  ],
70  'module class name is empty' => [
71  [
72  'modulename' => ['module' => ''],
73  ],
74  ],
75  'module class name is no valid class' => [
76  [
77  'modulename' => ['module' => 'nonExistingClassName'],
78  ],
79  ],
80  'module class name does not implement AdminPanelModuleInterface' => [
81  [
82  'modulename' => ['module' => \stdClass::class],
83  ],
84  ]
85  ];
86  }
87 
93  {
94  $this->expectException(InvalidConfigurationException::class);
95  $this->expectExceptionCode(1519490112);
96 
97  $moduleLoader = new ‪ModuleLoader();
98  $moduleLoader->validateSortAndInitializeModules($configuration);
99  }
100 
105  {
106  $config = [
107  'module1' => [
108  'module' => MainModuleFixture::class
109  ]
110  ];
111 
112  $dependencyOrderingServiceProphecy = $this->prophesize(DependencyOrderingService::class);
113  GeneralUtility::addInstance(DependencyOrderingService::class, $dependencyOrderingServiceProphecy->reveal());
114  $dependencyOrderingServiceProphecy->orderByDependencies($config)->willReturn($config);
115 
116  $moduleLoader = new ‪ModuleLoader();
117  $moduleLoader->validateSortAndInitializeModules($config);
118 
119  $dependencyOrderingServiceProphecy->orderByDependencies($config)->shouldHaveBeenCalled();
120  }
121 
126  {
127  $config = [
128  'module1' => [
129  'module' => MainModuleFixture::class
130  ],
131  'module2' => [
132  'module' => DisabledMainModuleFixture::class
133  ]
134  ];
135 
136  $dependencyOrderingServiceProphecy = $this->prophesize(DependencyOrderingService::class);
137  GeneralUtility::addInstance(DependencyOrderingService::class, $dependencyOrderingServiceProphecy->reveal());
138  $dependencyOrderingServiceProphecy->orderByDependencies($config)->willReturn($config);
139 
140  $moduleLoader = new ‪ModuleLoader();
141  $result = $moduleLoader->validateSortAndInitializeModules($config);
142 
143  self::assertCount(1, $result);
144  self::assertInstanceOf(MainModuleFixture::class, $result['example']);
145  self::assertArrayNotHasKey('example-disabled', $result);
146  }
147 }
‪TYPO3\CMS\Adminpanel\Tests\Unit\Service\ModuleLoaderTest\validateSortAndInitializeModulesThrowsExceptionIfModuleHasMissingConfiguration
‪validateSortAndInitializeModulesThrowsExceptionIfModuleHasMissingConfiguration($configuration)
Definition: ModuleLoaderTest.php:53
‪TYPO3\CMS\Adminpanel\Tests\Unit\Service\ModuleLoaderTest\validateSortAndInitializeModulesReturnsEmptyArrayIfNoModulesAreConfigured
‪validateSortAndInitializeModulesReturnsEmptyArrayIfNoModulesAreConfigured()
Definition: ModuleLoaderTest.php:33
‪TYPO3\CMS\Adminpanel\Service\ModuleLoader
Definition: ModuleLoader.php:32
‪TYPO3\CMS\Adminpanel\Tests\Unit\Service\ModuleLoaderTest\validateSortAndInitializeModulesInstantiatesMainModulesOnlyIfEnabled
‪validateSortAndInitializeModulesInstantiatesMainModulesOnlyIfEnabled()
Definition: ModuleLoaderTest.php:125
‪TYPO3\CMS\Adminpanel\Tests\Unit\Service\ModuleLoaderTest\invalidConfigurationDataProvider
‪invalidConfigurationDataProvider()
Definition: ModuleLoaderTest.php:62
‪TYPO3\CMS\Adminpanel\Tests\Unit\Fixtures\MainModuleFixture
Definition: MainModuleFixture.php:38
‪TYPO3\CMS\Adminpanel\Tests\Unit\Service\ModuleLoaderTest
Definition: ModuleLoaderTest.php:28
‪TYPO3\CMS\Adminpanel\Exceptions\InvalidConfigurationException
Definition: InvalidConfigurationException.php:23
‪TYPO3\CMS\Core\Service\DependencyOrderingService
Definition: DependencyOrderingService.php:31
‪TYPO3\CMS\Adminpanel\Tests\Unit\Fixtures\DisabledMainModuleFixture
Definition: DisabledMainModuleFixture.php:20
‪TYPO3\CMS\Adminpanel\Tests\Unit\Service
Definition: ConfigurationServiceTest.php:4
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:45
‪TYPO3\CMS\Adminpanel\Tests\Unit\Service\ModuleLoaderTest\validateSortAndInitializeModulesOrdersModulesWithDependencyOrderingService
‪validateSortAndInitializeModulesOrdersModulesWithDependencyOrderingService()
Definition: ModuleLoaderTest.php:104
‪TYPO3\CMS\Adminpanel\Tests\Unit\Service\ModuleLoaderTest\missingConfigurationDataProvider
‪missingConfigurationDataProvider()
Definition: ModuleLoaderTest.php:41
‪TYPO3\CMS\Adminpanel\Tests\Unit\Service\ModuleLoaderTest\validateSortAndInitializeModulesThrowsExceptionIfModuleHasInvalidConfiguration
‪validateSortAndInitializeModulesThrowsExceptionIfModuleHasInvalidConfiguration($configuration)
Definition: ModuleLoaderTest.php:92