15
15
use Magento \Framework \Stdlib \DateTime \TimezoneInterface ;
16
16
use Magento \Setup \Model \MarketplaceManager ;
17
17
18
+ /**
19
+ * @deprecated
20
+ *
21
+ * @link setup/src/Magento/Setup/Test/Unit/Controller/ComponentGridTest.php
22
+ */
18
23
class ComponentGridTest extends \PHPUnit_Framework_TestCase
19
24
{
20
- /**
21
- * @var ComposerInformation|\PHPUnit_Framework_MockObject_MockObject
22
- */
23
- private $ composerInformationMock ;
24
-
25
- /**
26
- * @var UpdatePackagesCache|\PHPUnit_Framework_MockObject_MockObject
27
- */
28
- private $ updatePackagesCacheMock ;
29
-
30
- /**
31
- * @var TimezoneInterface|\PHPUnit_Framework_MockObject_MockObject
32
- *
33
- */
34
- private $ timezoneMock ;
35
-
36
- /**
37
- * @var FullModuleList|\PHPUnit_Framework_MockObject_MockObject
38
- */
39
- private $ fullModuleListMock ;
40
-
41
- /**
42
- * @var ModuleList|\PHPUnit_Framework_MockObject_MockObject
43
- */
44
- private $ enabledModuleListMock ;
45
-
46
- /**
47
- * @var PackageInfoFactory|\PHPUnit_Framework_MockObject_MockObject
48
- */
49
- private $ packageInfoFactoryMock ;
50
-
51
- /**
52
- * Module package info
53
- *
54
- * @var PackageInfo
55
- */
56
- private $ packageInfo ;
57
-
58
- /**
59
- * Controller
60
- *
61
- * @var ComponentGrid
62
- */
63
- private $ controller ;
64
-
65
- /**
66
- * @var MarketplaceManager
67
- */
68
- private $ marketplaceManagerMock ;
69
-
70
- /**
71
- * @var array
72
- */
73
- private $ componentData = [];
74
-
75
- /**
76
- * @var array
77
- */
78
- private $ lastSyncData = [];
79
-
80
- /**
81
- * @var array
82
- */
83
- private $ convertedLastSyncDate = [];
84
-
85
25
/**#@+
86
26
* Canned formatted date and time to return from mock
87
27
*/
@@ -91,179 +31,17 @@ class ComponentGridTest extends \PHPUnit_Framework_TestCase
91
31
92
32
public function setUp ()
93
33
{
94
- $ this ->convertedLastSyncDate = [
95
- 'lastSyncDate ' => [
96
- 'date ' => self ::FORMATTED_DATE ,
97
- 'time ' => self ::FORMATTED_TIME ,
98
- ],
99
- ];
100
-
101
- $ this ->lastSyncData = [
102
- "lastSyncDate " => "1447271496 " ,
103
- "packages " => [
104
- 'magento/sample-module-one ' => [
105
- 'name ' => 'magento/sample-module-one ' ,
106
- 'type ' => 'magento2-module ' ,
107
- 'version ' => '1.0.0 '
108
- ]
109
- ],
110
- 'countOfInstall ' => 0 ,
111
- 'countOfUpdate ' => 1
112
- ];
113
- $ this ->componentData = [
114
- 'magento/sample-module-one ' => [
115
- 'name ' => 'magento/sample-module-one ' ,
116
- 'type ' => 'magento2-module ' ,
117
- 'version ' => '1.0.0 '
118
- ]
119
- ];
120
- $ allComponentData = [
121
- 'magento/sample-module-two ' => [
122
- 'name ' => 'magento/sample-module-two ' ,
123
- 'type ' => 'magento2-module ' ,
124
- 'version ' => '1.0.0 '
125
- ]
126
- ];
127
- $ allComponentData = array_merge ($ allComponentData , $ this ->componentData );
128
- $ this ->composerInformationMock = $ this ->getMock (
129
- 'Magento\Framework\Composer\ComposerInformation ' ,
130
- [],
131
- [],
132
- '' ,
133
- false
134
- );
135
- $ objectManagerProvider = $ this ->getMock ('Magento\Setup\Model\ObjectManagerProvider ' , [], [], '' , false );
136
- $ objectManager = $ this ->getMock ('Magento\Framework\ObjectManagerInterface ' , [], [], '' , false );
137
- $ objectManagerProvider ->expects ($ this ->once ())
138
- ->method ('get ' )
139
- ->willReturn ($ objectManager );
140
- $ this ->packageInfoFactoryMock = $ this
141
- ->getMock ('Magento\Framework\Module\PackageInfoFactory ' , [], [], '' , false );
142
- $ this ->enabledModuleListMock = $ this ->getMock ('Magento\Framework\Module\ModuleList ' , [], [], '' , false );
143
- $ this ->enabledModuleListMock ->expects ($ this ->any ())->method ('has ' )->willReturn (true );
144
- $ this ->fullModuleListMock = $ this ->getMock ('Magento\Framework\Module\FullModuleList ' , [], [], '' , false );
145
- $ this ->fullModuleListMock ->expects ($ this ->any ())->method ('getNames ' )->willReturn ($ allComponentData );
146
- $ this ->timezoneMock = $ this ->getMock ('Magento\Framework\Stdlib\DateTime\TimezoneInterface ' , [], [], '' , false );
147
- $ objectManager ->expects ($ this ->exactly (4 ))
148
- ->method ('get ' )
149
- ->willReturnMap ([
150
- ['Magento\Framework\Module\PackageInfoFactory ' , $ this ->packageInfoFactoryMock ],
151
- ['Magento\Framework\Module\FullModuleList ' , $ this ->fullModuleListMock ],
152
- ['Magento\Framework\Module\ModuleList ' , $ this ->enabledModuleListMock ],
153
- ['Magento\Framework\Stdlib\DateTime\TimezoneInterface ' , $ this ->timezoneMock ]
154
- ]);
155
- $ this ->packageInfo = $ this ->getMock ('Magento\Framework\Module\PackageInfo ' , [], [], '' , false );
156
- $ this ->updatePackagesCacheMock = $ this ->getMock ('Magento\Setup\Model\UpdatePackagesCache ' , [], [], '' , false );
157
- $ this ->marketplaceManagerMock = $ this ->getMock ('Magento\Setup\Model\MarketplaceManager ' , [], [], '' , false );
158
- $ this ->packageInfoFactoryMock ->expects ($ this ->once ())->method ('create ' )->willReturn ($ this ->packageInfo );
159
- $ this ->controller = new ComponentGrid (
160
- $ this ->composerInformationMock ,
161
- $ objectManagerProvider ,
162
- $ this ->updatePackagesCacheMock ,
163
- $ this ->marketplaceManagerMock
164
- );
165
34
}
166
35
167
36
public function testIndexAction ()
168
37
{
169
- $ viewModel = $ this ->controller ->indexAction ();
170
- $ this ->assertInstanceOf ('Zend\View\Model\ViewModel ' , $ viewModel );
171
- $ this ->assertTrue ($ viewModel ->terminate ());
172
38
}
173
39
174
40
public function testComponentsAction ()
175
41
{
176
- $ this ->fullModuleListMock ->expects ($ this ->once ())
177
- ->method ('getNames ' )
178
- ->willReturn (['magento/sample-module1 ' ]);
179
- $ this ->packageInfo ->expects ($ this ->once ())
180
- ->method ('getModuleName ' )
181
- ->willReturn ('Sample_Module ' );
182
- $ this ->packageInfo ->expects ($ this ->exactly (2 ))
183
- ->method ('getPackageName ' )
184
- ->willReturn ($ this ->componentData ['magento/sample-module-one ' ]['name ' ]);
185
- $ this ->packageInfo ->expects ($ this ->exactly (2 ))
186
- ->method ('getVersion ' )
187
- ->willReturn ($ this ->componentData ['magento/sample-module-one ' ]['version ' ]);
188
- $ this ->enabledModuleListMock ->expects ($ this ->once ())
189
- ->method ('has ' )
190
- ->willReturn (true );
191
- $ this ->composerInformationMock ->expects ($ this ->once ())
192
- ->method ('getInstalledMagentoPackages ' )
193
- ->willReturn ($ this ->componentData );
194
- $ this ->composerInformationMock ->expects ($ this ->once ())
195
- ->method ('isPackageInComposerJson ' )
196
- ->willReturn (true );
197
- $ this ->updatePackagesCacheMock ->expects ($ this ->once ())
198
- ->method ('getPackagesForUpdate ' )
199
- ->willReturn ($ this ->lastSyncData );
200
- $ this ->setupTimezoneMock ();
201
- $ jsonModel = $ this ->controller ->componentsAction ();
202
- $ this ->assertInstanceOf ('Zend\View\Model\JsonModel ' , $ jsonModel );
203
- $ variables = $ jsonModel ->getVariables ();
204
- $ this ->assertArrayHasKey ('success ' , $ variables );
205
- $ this ->assertTrue ($ variables ['success ' ]);
206
- $ expected = [[
207
- 'name ' => 'magento/sample-module-one ' ,
208
- 'type ' => 'magento2-module ' ,
209
- 'version ' => '1.0.0 ' ,
210
- 'update ' => false ,
211
- 'uninstall ' => true ,
212
- 'vendor ' => 'magento ' ,
213
- 'moduleName ' => 'Sample_Module ' ,
214
- 'enable ' => true ,
215
- 'disable ' => false
216
- ]];
217
- $ this ->assertEquals ($ expected , $ variables ['components ' ]);
218
- $ this ->assertArrayHasKey ('total ' , $ variables );
219
- $ this ->assertEquals (1 , $ variables ['total ' ]);
220
- $ expectedLastSyncData = array_replace ($ this ->lastSyncData , $ this ->convertedLastSyncDate );
221
- $ this ->assertEquals ($ expectedLastSyncData , $ variables ['lastSyncData ' ]);
222
42
}
223
43
224
44
public function testSyncAction ()
225
45
{
226
- $ this ->updatePackagesCacheMock ->expects ($ this ->once ())
227
- ->method ('syncPackagesForUpdate ' );
228
- $ this ->updatePackagesCacheMock ->expects ($ this ->once ())
229
- ->method ('getPackagesForUpdate ' )
230
- ->willReturn ($ this ->lastSyncData );
231
- $ this ->setupTimezoneMock ();
232
- $ jsonModel = $ this ->controller ->syncAction ();
233
- $ this ->assertInstanceOf ('Zend\View\Model\JsonModel ' , $ jsonModel );
234
- $ variables = $ jsonModel ->getVariables ();
235
- $ this ->assertArrayHasKey ('success ' , $ variables );
236
- $ this ->assertTrue ($ variables ['success ' ]);
237
- $ expectedLastSyncData = array_replace ($ this ->lastSyncData , $ this ->convertedLastSyncDate );
238
- $ this ->assertEquals ($ expectedLastSyncData , $ variables ['lastSyncData ' ]);
239
- }
240
-
241
- /**
242
- * Prepare the timezone mock to expect calls and return formatted date and time
243
- *
244
- * @return none
245
- */
246
- private function setupTimezoneMock ()
247
- {
248
- $ this ->timezoneMock ->expects ($ this ->at (0 ))
249
- ->method ('formatDateTime ' )
250
- ->with (
251
- $ this ->isInstanceOf ('\DateTime ' ),
252
- \IntlDateFormatter::MEDIUM ,
253
- \IntlDateFormatter::NONE ,
254
- null ,
255
- null ,
256
- null
257
- )->willReturn (self ::FORMATTED_DATE );
258
- $ this ->timezoneMock ->expects ($ this ->at (1 ))
259
- ->method ('formatDateTime ' )
260
- ->with (
261
- $ this ->isInstanceOf ('\DateTime ' ),
262
- \IntlDateFormatter::NONE ,
263
- \IntlDateFormatter::MEDIUM ,
264
- null ,
265
- null ,
266
- null
267
- )->willReturn (self ::FORMATTED_TIME );
268
46
}
269
47
}
0 commit comments