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