21894189867a9d9a22aa29b96bf134a4e374d7e1
[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 * Copyright notice
6 *
7 * (c) 2012-2013 Susanne Moog, <susanne.moog@typo3.org>
8 * All rights reserved
9 *
10 * This script is part of the TYPO3 project. The TYPO3 project is
11 * free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 2 of the License, or
14 * (at your option) any later version.
15 *
16 * The GNU General Public License can be found at
17 * http://www.gnu.org/copyleft/gpl.html.
18 *
19 * This script is distributed in the hope that it will be useful,
20 * but WITHOUT ANY WARRANTY; without even the implied warranty of
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 * GNU General Public License for more details.
23 *
24 * This copyright notice MUST APPEAR in all copies of the script!
25 ***************************************************************/
26 use TYPO3\CMS\Cms\Package;
27
28 /**
29 * List utility test
30 *
31 */
32 class ListUtilityTest extends \TYPO3\CMS\Core\Tests\UnitTestCase {
33
34 /**
35 * @var \TYPO3\CMS\Extensionmanager\Utility\ListUtility
36 */
37 protected $subject;
38
39 /**
40 * @return void
41 */
42 public function setUp() {
43 $this->subject = $this->getMock('TYPO3\\CMS\\Extensionmanager\\Utility\\ListUtility', array('emitPackagesMayHaveChangedSignal'));
44 $packageManagerMock = $this->getMock('TYPO3\\CMS\\Core\\Package\\PackageManager');
45 $packageManagerMock
46 ->expects($this->any())
47 ->method('getActivePackages')
48 ->will($this->returnValue(array(
49 'cms' => $this->getMock('TYPO3\\CMS\\Cms\\Package', array(), array(), '', FALSE),
50 'lang' => $this->getMock('TYPO3\\CMS\\Cms\\Package', array(), array(), '', FALSE),
51 'news' => $this->getMock('TYPO3\\CMS\\Cms\\Package', array(), array(), '', FALSE),
52 'saltedpasswords' => $this->getMock('TYPO3\\CMS\\Cms\\Package', array(), array(), '', FALSE),
53 'rsaauth' => $this->getMock('TYPO3\\CMS\\Cms\\Package', array(), array(), '', FALSE),
54 )));
55 $this->inject($this->subject, 'packageManager', $packageManagerMock);
56 }
57
58 /**
59 * @return array
60 */
61 public function getAvailableAndInstalledExtensionsDataProvider() {
62 return array(
63 'same extension lists' => array(
64 array(
65 'cms' => array(),
66 'lang' => array(),
67 'news' => array(),
68 'saltedpasswords' => array(),
69 'rsaauth' => array()
70 ),
71 array(
72 'cms' => array('installed' => TRUE),
73 'lang' => array('installed' => TRUE),
74 'news' => array('installed' => TRUE),
75 'saltedpasswords' => array('installed' => TRUE),
76 'rsaauth' => array('installed' => TRUE)
77 )
78 ),
79 'different extension lists' => array(
80 array(
81 'cms' => array(),
82 'lang' => array(),
83 'news' => array(),
84 'saltedpasswords' => array(),
85 'rsaauth' => array()
86 ),
87 array(
88 'cms' => array('installed' => TRUE),
89 'lang' => array('installed' => TRUE),
90 'news' => array('installed' => TRUE),
91 'saltedpasswords' => array('installed' => TRUE),
92 'rsaauth' => array('installed' => TRUE)
93 )
94 ),
95 'different extension lists - set2' => array(
96 array(
97 'cms' => array(),
98 'lang' => array(),
99 'news' => array(),
100 'saltedpasswords' => array(),
101 'rsaauth' => array(),
102 'em' => array()
103 ),
104 array(
105 'cms' => array('installed' => TRUE),
106 'lang' => array('installed' => TRUE),
107 'news' => array('installed' => TRUE),
108 'saltedpasswords' => array('installed' => TRUE),
109 'rsaauth' => array('installed' => TRUE),
110 'em' => array()
111 )
112 ),
113 'different extension lists - set3' => array(
114 array(
115 'cms' => array(),
116 'lang' => array(),
117 'fluid' => array(),
118 'news' => array(),
119 'saltedpasswords' => array(),
120 'rsaauth' => array(),
121 'em' => array()
122 ),
123 array(
124 'cms' => array('installed' => TRUE),
125 'lang' => array('installed' => TRUE),
126 'fluid' => array(),
127 'news' => array('installed' => TRUE),
128 'saltedpasswords' => array('installed' => TRUE),
129 'rsaauth' => array('installed' => TRUE),
130 'em' => array()
131 )
132 )
133 );
134 }
135
136 /**
137 * @test
138 * @dataProvider getAvailableAndInstalledExtensionsDataProvider
139 * @param $availableExtensions
140 * @param $expectedResult
141 * @return void
142 */
143 public function getAvailableAndInstalledExtensionsTest($availableExtensions, $expectedResult) {
144 $this->assertEquals($expectedResult, $this->subject->getAvailableAndInstalledExtensions($availableExtensions));
145 }
146
147 /**
148 * @return array
149 */
150 public function enrichExtensionsWithEmConfInformationDataProvider() {
151 return array(
152 'simple key value array emconf' => array(
153 array(
154 'cms' => array('test' => 'test2'),
155 'lang' => array('property1' => 'oldvalue'),
156 'news' => array(),
157 'saltedpasswords' => array(),
158 'rsaauth' => array()
159 ),
160 array(
161 'property1' => 'property value1'
162 ),
163 array(
164 'cms' => array('test' => 'test2', 'property1' => 'property value1'),
165 'lang' => array('property1' => 'oldvalue'),
166 'news' => array('property1' => 'property value1'),
167 'saltedpasswords' => array('property1' => 'property value1'),
168 'rsaauth' => array('property1' => 'property value1')
169 )
170 )
171 );
172 }
173
174 /**
175 * @test
176 * @dataProvider enrichExtensionsWithEmConfInformationDataProvider
177 * @param $extensions
178 * @param $emConf
179 * @param $expectedResult
180 * @return void
181 */
182 public function enrichExtensionsWithEmConfInformation($extensions, $emConf, $expectedResult) {
183 $this->inject($this->subject, 'extensionRepository', $this->getAccessibleMock('TYPO3\\CMS\\Extensionmanager\\Domain\\Repository\\ExtensionRepository', array('findOneByExtensionKeyAndVersion'), array(), '', FALSE));
184 $emConfUtilityMock = $this->getMock('TYPO3\\CMS\\Extensionmanager\\Utility\\EmConfUtility');
185 $emConfUtilityMock->expects($this->any())->method('includeEmConf')->will($this->returnValue($emConf));
186 $this->inject($this->subject, 'emConfUtility', $emConfUtilityMock);
187 $this->assertEquals($expectedResult, $this->subject->enrichExtensionsWithEmConfAndTerInformation($extensions));
188 }
189 }