‪TYPO3CMS  ‪main
ListUtilityTest.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\DataProvider;
21 use PHPUnit\Framework\Attributes\Test;
24 use TYPO3\CMS\Core\Package\PackageManager;
26 use TYPO3\CMS\Extensionmanager\Utility\EmConfUtility;
28 use TYPO3\TestingFramework\Core\Unit\UnitTestCase;
29 
30 final class ‪ListUtilityTest extends UnitTestCase
31 {
33 
34  protected function ‪setUp(): void
35  {
36  parent::setUp();
37  $this->subject = new ‪ListUtility();
38  $this->subject->injectEventDispatcher(new ‪NoopEventDispatcher());
39  $packageManagerMock = $this->getMockBuilder(PackageManager::class)
40  ->disableOriginalConstructor()
41  ->getMock();
42  $packageManagerMock
43  ->method('getActivePackages')
44  ->willReturn([
45  'lang' => $this->getMockBuilder(Package::class)->disableOriginalConstructor()->getMock(),
46  'news' => $this->getMockBuilder(Package::class)->disableOriginalConstructor()->getMock(),
47  'felogin' => $this->getMockBuilder(Package::class)->disableOriginalConstructor()->getMock(),
48  ]);
49  $this->subject->injectPackageManager($packageManagerMock);
50  }
51 
52  public static function ‪getAvailableAndInstalledExtensionsDataProvider(): array
53  {
54  return [
55  'same extension lists' => [
56  [
57  'lang' => [],
58  'news' => [],
59  'felogin' => [],
60  ],
61  [
62  'lang' => ['installed' => true],
63  'news' => ['installed' => true],
64  'felogin' => ['installed' => true],
65  ],
66  ],
67  'different extension lists' => [
68  [
69  'lang' => [],
70  'news' => [],
71  'felogin' => [],
72  ],
73  [
74  'lang' => ['installed' => true],
75  'news' => ['installed' => true],
76  'felogin' => ['installed' => true],
77  ],
78  ],
79  'different extension lists - set2' => [
80  [
81  'lang' => [],
82  'news' => [],
83  'felogin' => [],
84  'em' => [],
85  ],
86  [
87  'lang' => ['installed' => true],
88  'news' => ['installed' => true],
89  'felogin' => ['installed' => true],
90  'em' => [],
91  ],
92  ],
93  'different extension lists - set3' => [
94  [
95  'lang' => [],
96  'fluid' => [],
97  'news' => [],
98  'felogin' => [],
99  'em' => [],
100  ],
101  [
102  'lang' => ['installed' => true],
103  'fluid' => [],
104  'news' => ['installed' => true],
105  'felogin' => ['installed' => true],
106  'em' => [],
107  ],
108  ],
109  ];
110  }
111 
112  #[DataProvider('getAvailableAndInstalledExtensionsDataProvider')]
113  #[Test]
114  public function ‪getAvailableAndInstalledExtensionsTest(array $availableExtensions, array $expectedResult): void
115  {
116  self::assertEquals($expectedResult, $this->subject->getAvailableAndInstalledExtensions($availableExtensions));
117  }
118 
120  {
121  return [
122  'simple key value array emconf' => [
123  [
124  'lang' => ['property1' => 'oldvalue'],
125  'news' => [],
126  'felogin' => [],
127  ],
128  [
129  'property1' => 'property value1',
130  ],
131  [
132  'lang' => ['property1' => 'oldvalue', 'state' => 'stable'],
133  'news' => ['property1' => 'property value1', 'state' => 'stable'],
134  'felogin' => ['property1' => 'property value1', 'state' => 'stable'],
135  ],
136  ],
137  ];
138  }
139 
140  #[DataProvider('enrichExtensionsWithEmConfInformationDataProvider')]
141  #[Test]
142  public function ‪enrichExtensionsWithEmConfInformation(array $extensions, array $emConf, array $expectedResult): void
143  {
144  $this->subject->injectExtensionRepository($this->getAccessibleMock(ExtensionRepository::class, ['findOneByExtensionKeyAndVersion', 'findHighestAvailableVersion'], [], '', false));
145  $emConfUtilityMock = $this->getMockBuilder(EmConfUtility::class)->getMock();
146  $emConfUtilityMock->method('includeEmConf')->willReturn($emConf);
147  $this->subject->injectEmConfUtility($emConfUtilityMock);
148  self::assertEquals($expectedResult, $this->subject->enrichExtensionsWithEmConfAndTerInformation($extensions));
149  }
150 }
‪TYPO3\CMS\Extensionmanager\Tests\Unit\Utility\ListUtilityTest\setUp
‪setUp()
Definition: ListUtilityTest.php:34
‪TYPO3\CMS\Extensionmanager\Tests\Unit\Utility
Definition: DependencyUtilityTest.php:18
‪TYPO3\CMS\Extensionmanager\Tests\Unit\Utility\ListUtilityTest\enrichExtensionsWithEmConfInformationDataProvider
‪static enrichExtensionsWithEmConfInformationDataProvider()
Definition: ListUtilityTest.php:119
‪TYPO3\CMS\Extensionmanager\Utility\ListUtility
Definition: ListUtility.php:41
‪TYPO3\CMS\Extensionmanager\Tests\Unit\Utility\ListUtilityTest\getAvailableAndInstalledExtensionsDataProvider
‪static getAvailableAndInstalledExtensionsDataProvider()
Definition: ListUtilityTest.php:52
‪TYPO3\CMS\Extensionmanager\Domain\Repository\ExtensionRepository
Definition: ExtensionRepository.php:37
‪TYPO3\CMS\Core\Package\Package
Definition: Package.php:30
‪TYPO3\CMS\Extensionmanager\Tests\Unit\Utility\ListUtilityTest
Definition: ListUtilityTest.php:31
‪TYPO3\CMS\Core\EventDispatcher\NoopEventDispatcher
Definition: NoopEventDispatcher.php:29
‪TYPO3\CMS\Extensionmanager\Tests\Unit\Utility\ListUtilityTest\$subject
‪ListUtility $subject
Definition: ListUtilityTest.php:32
‪TYPO3\CMS\Extensionmanager\Tests\Unit\Utility\ListUtilityTest\getAvailableAndInstalledExtensionsTest
‪getAvailableAndInstalledExtensionsTest(array $availableExtensions, array $expectedResult)
Definition: ListUtilityTest.php:114
‪TYPO3\CMS\Extensionmanager\Tests\Unit\Utility\ListUtilityTest\enrichExtensionsWithEmConfInformation
‪enrichExtensionsWithEmConfInformation(array $extensions, array $emConf, array $expectedResult)
Definition: ListUtilityTest.php:142