[!!!][TASK] Extract testing framework for TYPO3
[Packages/TYPO3.CMS.git] / typo3 / sysext / extensionmanager / Tests / Unit / Utility / ListUtilityTest.php
1 <?php
2 namespace TYPO3\CMS\Extensionmanager\Tests\Unit\Utility;
3
4 /*
5 * This file is part of the TYPO3 CMS project.
6 *
7 * It is free software; you can redistribute it and/or modify it under
8 * the terms of the GNU General Public License, either version 2
9 * of the License, or any later version.
10 *
11 * For the full copyright and license information, please read the
12 * LICENSE.txt file that was distributed with this source code.
13 *
14 * The TYPO3 project - inspiring people to share!
15 */
16
17 /**
18 * List utility test
19 *
20 */
21 class ListUtilityTest extends \TYPO3\CMS\Components\TestingFramework\Core\UnitTestCase
22 {
23 /**
24 * @var \TYPO3\CMS\Extensionmanager\Utility\ListUtility
25 */
26 protected $subject;
27
28 /**
29 * @return void
30 */
31 protected function setUp()
32 {
33 $this->subject = $this->getMockBuilder(\TYPO3\CMS\Extensionmanager\Utility\ListUtility::class)
34 ->setMethods(['emitPackagesMayHaveChangedSignal'])
35 ->getMock();
36 $packageManagerMock = $this->getMockBuilder(\TYPO3\CMS\Core\Package\PackageManager::class)->getMock();
37 $packageManagerMock
38 ->expects($this->any())
39 ->method('getActivePackages')
40 ->will($this->returnValue([
41 'lang' => $this->getMockBuilder(\TYPO3\CMS\Core\Package::class)->disableOriginalConstructor()->getMock(),
42 'news' => $this->getMockBuilder(\TYPO3\CMS\Core\Package::class)->disableOriginalConstructor()->getMock(),
43 'saltedpasswords' => $this->getMockBuilder(\TYPO3\CMS\Core\Package::class)->disableOriginalConstructor()->getMock(),
44 'rsaauth' => $this->getMockBuilder(\TYPO3\CMS\Core\Package::class)->disableOriginalConstructor()->getMock(),
45 ]));
46 $this->inject($this->subject, 'packageManager', $packageManagerMock);
47 }
48
49 /**
50 * @return array
51 */
52 public function getAvailableAndInstalledExtensionsDataProvider()
53 {
54 return [
55 'same extension lists' => [
56 [
57 'lang' => [],
58 'news' => [],
59 'saltedpasswords' => [],
60 'rsaauth' => []
61 ],
62 [
63 'lang' => ['installed' => true],
64 'news' => ['installed' => true],
65 'saltedpasswords' => ['installed' => true],
66 'rsaauth' => ['installed' => true]
67 ]
68 ],
69 'different extension lists' => [
70 [
71 'lang' => [],
72 'news' => [],
73 'saltedpasswords' => [],
74 'rsaauth' => []
75 ],
76 [
77 'lang' => ['installed' => true],
78 'news' => ['installed' => true],
79 'saltedpasswords' => ['installed' => true],
80 'rsaauth' => ['installed' => true]
81 ]
82 ],
83 'different extension lists - set2' => [
84 [
85 'lang' => [],
86 'news' => [],
87 'saltedpasswords' => [],
88 'rsaauth' => [],
89 'em' => []
90 ],
91 [
92 'lang' => ['installed' => true],
93 'news' => ['installed' => true],
94 'saltedpasswords' => ['installed' => true],
95 'rsaauth' => ['installed' => true],
96 'em' => []
97 ]
98 ],
99 'different extension lists - set3' => [
100 [
101 'lang' => [],
102 'fluid' => [],
103 'news' => [],
104 'saltedpasswords' => [],
105 'rsaauth' => [],
106 'em' => []
107 ],
108 [
109 'lang' => ['installed' => true],
110 'fluid' => [],
111 'news' => ['installed' => true],
112 'saltedpasswords' => ['installed' => true],
113 'rsaauth' => ['installed' => true],
114 'em' => []
115 ]
116 ]
117 ];
118 }
119
120 /**
121 * @test
122 * @dataProvider getAvailableAndInstalledExtensionsDataProvider
123 * @param $availableExtensions
124 * @param $expectedResult
125 * @return void
126 */
127 public function getAvailableAndInstalledExtensionsTest($availableExtensions, $expectedResult)
128 {
129 $this->assertEquals($expectedResult, $this->subject->getAvailableAndInstalledExtensions($availableExtensions));
130 }
131
132 /**
133 * @return array
134 */
135 public function enrichExtensionsWithEmConfInformationDataProvider()
136 {
137 return [
138 'simple key value array emconf' => [
139 [
140 'lang' => ['property1' => 'oldvalue'],
141 'news' => [],
142 'saltedpasswords' => [],
143 'rsaauth' => []
144 ],
145 [
146 'property1' => 'property value1'
147 ],
148 [
149 'lang' => ['property1' => 'oldvalue'],
150 'news' => ['property1' => 'property value1'],
151 'saltedpasswords' => ['property1' => 'property value1'],
152 'rsaauth' => ['property1' => 'property value1']
153 ]
154 ]
155 ];
156 }
157
158 /**
159 * @test
160 * @dataProvider enrichExtensionsWithEmConfInformationDataProvider
161 * @param $extensions
162 * @param $emConf
163 * @param $expectedResult
164 * @return void
165 */
166 public function enrichExtensionsWithEmConfInformation($extensions, $emConf, $expectedResult)
167 {
168 $this->inject($this->subject, 'extensionRepository', $this->getAccessibleMock(\TYPO3\CMS\Extensionmanager\Domain\Repository\ExtensionRepository::class, ['findOneByExtensionKeyAndVersion', 'findHighestAvailableVersion'], [], '', false));
169 $emConfUtilityMock = $this->getMockBuilder(\TYPO3\CMS\Extensionmanager\Utility\EmConfUtility::class)->getMock();
170 $emConfUtilityMock->expects($this->any())->method('includeEmConf')->will($this->returnValue($emConf));
171 $this->inject($this->subject, 'emConfUtility', $emConfUtilityMock);
172 $this->assertEquals($expectedResult, $this->subject->enrichExtensionsWithEmConfAndTerInformation($extensions));
173 }
174 }