3
3
* Copyright © Magento, Inc. All rights reserved.
4
4
* See COPYING.txt for license details.
5
5
*/
6
+
6
7
namespace Magento \Ui \Test \Unit \Model \Export ;
7
8
9
+ use Magento \Framework \Api \AttributeInterface ;
8
10
use Magento \Framework \Api \Search \DocumentInterface ;
11
+ use Magento \Framework \DataObject ;
12
+ use Magento \Framework \Exception \LocalizedException ;
9
13
use Magento \Framework \Locale \ResolverInterface ;
10
14
use Magento \Framework \Stdlib \DateTime \TimezoneInterface ;
11
15
use Magento \Framework \TestFramework \Unit \Helper \ObjectManager ;
12
16
use Magento \Framework \View \Element \UiComponentInterface ;
17
+ use Magento \Ui \Component \Filters ;
18
+ use Magento \Ui \Component \Filters \Type \Select ;
13
19
use Magento \Ui \Component \Listing \Columns ;
14
20
use Magento \Ui \Component \Listing \Columns \Column ;
15
21
use Magento \Ui \Component \MassAction \Filter ;
16
22
use Magento \Ui \Model \Export \MetadataProvider ;
23
+ use PHPUnit \Framework \TestCase ;
17
24
18
25
/**
19
26
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
20
27
*/
21
- class MetadataProviderTest extends \ PHPUnit \ Framework \ TestCase
28
+ class MetadataProviderTest extends TestCase
22
29
{
23
30
/**
24
31
* @var MetadataProvider
@@ -45,25 +52,25 @@ class MetadataProviderTest extends \PHPUnit\Framework\TestCase
45
52
*/
46
53
protected function setUp ()
47
54
{
48
- $ this ->filter = $ this ->getMockBuilder (\ Magento \ Ui \ Component \ MassAction \ Filter::class)
49
- ->disableOriginalConstructor ()
50
- ->getMock ();
55
+ $ this ->filter = $ this ->getMockBuilder (Filter::class)
56
+ ->disableOriginalConstructor ()
57
+ ->getMock ();
51
58
52
- $ this ->localeDate = $ this ->getMockBuilder (\ Magento \ Framework \ Stdlib \ DateTime \ TimezoneInterface::class)
53
- ->disableOriginalConstructor ()
54
- ->getMock ();
59
+ $ this ->localeDate = $ this ->getMockBuilder (TimezoneInterface::class)
60
+ ->disableOriginalConstructor ()
61
+ ->getMock ();
55
62
56
- $ this ->localeResolver = $ this ->getMockBuilder (\ Magento \ Framework \ Locale \ ResolverInterface::class)
57
- ->disableOriginalConstructor ()
58
- ->getMock ();
63
+ $ this ->localeResolver = $ this ->getMockBuilder (ResolverInterface::class)
64
+ ->disableOriginalConstructor ()
65
+ ->getMock ();
59
66
60
67
$ this ->localeResolver ->expects ($ this ->any ())
61
- ->method ('getLocale ' )
62
- ->willReturn (null );
68
+ ->method ('getLocale ' )
69
+ ->willReturn (null );
63
70
64
71
$ objectManager = new ObjectManager ($ this );
65
72
$ this ->model = $ objectManager ->getObject (
66
- \ Magento \ Ui \ Model \ Export \ MetadataProvider::class,
73
+ MetadataProvider::class,
67
74
[
68
75
'filter ' => $ this ->filter ,
69
76
'localeDate ' => $ this ->localeDate ,
@@ -99,12 +106,12 @@ public function testGetHeaders(array $columnLabels, array $expected): void
99
106
public function getColumnsDataProvider (): array
100
107
{
101
108
return [
102
- [['ID ' ],['ID ' ]],
103
- [['Name ' ],['Name ' ]],
104
- [['Id ' ],['Id ' ]],
105
- [['id ' ],['id ' ]],
106
- [['IDTEST ' ],['IDTEST ' ]],
107
- [['ID TEST ' ],['ID TEST ' ]],
109
+ [['ID ' ], ['ID ' ]],
110
+ [['Name ' ], ['Name ' ]],
111
+ [['Id ' ], ['Id ' ]],
112
+ [['id ' ], ['id ' ]],
113
+ [['IDTEST ' ], ['IDTEST ' ]],
114
+ [['ID TEST ' ], ['ID TEST ' ]],
108
115
];
109
116
}
110
117
@@ -128,6 +135,7 @@ public function testGetFields()
128
135
* @param string $columnLabel
129
136
* @param string $columnActionsName
130
137
* @param string $columnActionsLabel
138
+ *
131
139
* @return UiComponentInterface|\PHPUnit_Framework_MockObject_MockObject
132
140
*/
133
141
protected function prepareColumns (
@@ -138,57 +146,57 @@ protected function prepareColumns(
138
146
$ columnActionsLabel = 'actions_label '
139
147
) {
140
148
/** @var UiComponentInterface|\PHPUnit_Framework_MockObject_MockObject $component */
141
- $ component = $ this ->getMockBuilder (\ Magento \ Framework \ View \ Element \ UiComponentInterface::class)
142
- ->getMockForAbstractClass ();
149
+ $ component = $ this ->getMockBuilder (UiComponentInterface::class)
150
+ ->getMockForAbstractClass ();
143
151
144
152
/** @var Columns|\PHPUnit_Framework_MockObject_MockObject $columns */
145
- $ columns = $ this ->getMockBuilder (\ Magento \ Ui \ Component \ Listing \ Columns::class)
146
- ->disableOriginalConstructor ()
147
- ->getMock ();
153
+ $ columns = $ this ->getMockBuilder (Columns::class)
154
+ ->disableOriginalConstructor ()
155
+ ->getMock ();
148
156
149
157
/** @var Column|\PHPUnit_Framework_MockObject_MockObject $column */
150
- $ column = $ this ->getMockBuilder (\ Magento \ Ui \ Component \ Listing \ Columns \ Column::class)
151
- ->disableOriginalConstructor ()
152
- ->getMock ();
158
+ $ column = $ this ->getMockBuilder (Column::class)
159
+ ->disableOriginalConstructor ()
160
+ ->getMock ();
153
161
/** @var Column|\PHPUnit_Framework_MockObject_MockObject $columnActions */
154
- $ columnActions = $ this ->getMockBuilder (\ Magento \ Ui \ Component \ Listing \ Columns \ Column::class)
155
- ->disableOriginalConstructor ()
156
- ->getMock ();
162
+ $ columnActions = $ this ->getMockBuilder (Column::class)
163
+ ->disableOriginalConstructor ()
164
+ ->getMock ();
157
165
158
166
$ component ->expects ($ this ->any ())
159
- ->method ('getName ' )
160
- ->willReturn ($ componentName );
167
+ ->method ('getName ' )
168
+ ->willReturn ($ componentName );
161
169
$ component ->expects ($ this ->atLeastOnce ())
162
- ->method ('getChildComponents ' )
163
- ->willReturn ([$ columns ]);
170
+ ->method ('getChildComponents ' )
171
+ ->willReturn ([$ columns ]);
164
172
165
173
$ columns ->expects ($ this ->atLeastOnce ())
166
- ->method ('getChildComponents ' )
167
- ->willReturn ([$ column , $ columnActions ]);
174
+ ->method ('getChildComponents ' )
175
+ ->willReturn ([$ column , $ columnActions ]);
168
176
169
177
$ column ->expects ($ this ->any ())
170
- ->method ('getName ' )
171
- ->willReturn ($ columnName );
178
+ ->method ('getName ' )
179
+ ->willReturn ($ columnName );
172
180
$ column ->expects ($ this ->any ())
173
- ->method ('getData ' )
174
- ->willReturnMap (
175
- [
176
- ['config/label ' , null , $ columnLabel ],
177
- ['config/dataType ' , null , 'data_type ' ],
178
- ]
179
- );
181
+ ->method ('getData ' )
182
+ ->willReturnMap (
183
+ [
184
+ ['config/label ' , null , $ columnLabel ],
185
+ ['config/dataType ' , null , 'data_type ' ],
186
+ ]
187
+ );
180
188
181
189
$ columnActions ->expects ($ this ->any ())
182
- ->method ('getName ' )
183
- ->willReturn ($ columnActionsName );
190
+ ->method ('getName ' )
191
+ ->willReturn ($ columnActionsName );
184
192
$ columnActions ->expects ($ this ->any ())
185
- ->method ('getData ' )
186
- ->willReturnMap (
187
- [
188
- ['config/label ' , null , $ columnActionsLabel ],
189
- ['config/dataType ' , null , 'actions ' ],
190
- ]
191
- );
193
+ ->method ('getData ' )
194
+ ->willReturnMap (
195
+ [
196
+ ['config/label ' , null , $ columnActionsLabel ],
197
+ ['config/dataType ' , null , 'actions ' ],
198
+ ]
199
+ );
192
200
193
201
return $ component ;
194
202
}
@@ -198,25 +206,26 @@ protected function prepareColumns(
198
206
* @param array $fields
199
207
* @param array $options
200
208
* @param array $expected
209
+ *
201
210
* @dataProvider getRowDataProvider
202
211
*/
203
212
public function testGetRowData ($ key , $ fields , $ options , $ expected )
204
213
{
205
214
/** @var DocumentInterface|\PHPUnit_Framework_MockObject_MockObject $document */
206
- $ document = $ this ->getMockBuilder (\ Magento \ Framework \ Api \ Search \ DocumentInterface::class)
207
- ->getMockForAbstractClass ();
215
+ $ document = $ this ->getMockBuilder (DocumentInterface::class)
216
+ ->getMockForAbstractClass ();
208
217
209
- $ attribute = $ this ->getMockBuilder (\ Magento \ Framework \ Api \ AttributeInterface::class)
210
- ->getMockForAbstractClass ();
218
+ $ attribute = $ this ->getMockBuilder (AttributeInterface::class)
219
+ ->getMockForAbstractClass ();
211
220
212
221
$ document ->expects ($ this ->once ())
213
- ->method ('getCustomAttribute ' )
214
- ->with ($ fields [0 ])
215
- ->willReturn ($ attribute );
222
+ ->method ('getCustomAttribute ' )
223
+ ->with ($ fields [0 ])
224
+ ->willReturn ($ attribute );
216
225
217
226
$ attribute ->expects ($ this ->once ())
218
- ->method ('getValue ' )
219
- ->willReturn ($ key );
227
+ ->method ('getValue ' )
228
+ ->willReturn ($ key );
220
229
221
230
$ result = $ this ->model ->getRowData ($ document , $ fields , $ options );
222
231
$ this ->assertTrue (is_array ($ result ));
@@ -271,15 +280,15 @@ public function getRowDataProvider()
271
280
* @param array $expected
272
281
*
273
282
* @dataProvider getOptionsDataProvider
274
- * @throws \Magento\Framework\Exception\ LocalizedException
283
+ * @throws LocalizedException
275
284
*/
276
285
public function testGetOptions ($ filter , $ options , $ expected )
277
286
{
278
287
$ component = $ this ->prepareColumnsWithOptions ($ filter , $ options );
279
288
280
289
$ this ->filter ->expects ($ this ->exactly (2 ))
281
- ->method ('getComponent ' )
282
- ->willReturn ($ component );
290
+ ->method ('getComponent ' )
291
+ ->willReturn ($ component );
283
292
284
293
$ result = $ this ->model ->getOptions ();
285
294
$ this ->assertTrue (is_array ($ result ));
@@ -288,32 +297,35 @@ public function testGetOptions($filter, $options, $expected)
288
297
}
289
298
290
299
/**
300
+ * @param string $filter
301
+ * @param array $options
302
+ *
291
303
* @return UiComponentInterface|\PHPUnit_Framework_MockObject_MockObject
292
304
*/
293
305
protected function prepareColumnsWithOptions (string $ filter , array $ options )
294
306
{
295
307
/** @var UiComponentInterface|\PHPUnit_Framework_MockObject_MockObject $component */
296
- $ component = $ this ->getMockBuilder (\ Magento \ Framework \ View \ Element \ UiComponentInterface::class)
308
+ $ component = $ this ->getMockBuilder (UiComponentInterface::class)
297
309
->getMockForAbstractClass ();
298
310
299
- $ listingTopComponent = $ this ->getMockBuilder (\ Magento \ Framework \ View \ Element \ UiComponentInterface::class)
300
- ->getMockForAbstractClass ();
311
+ $ listingTopComponent = $ this ->getMockBuilder (UiComponentInterface::class)
312
+ ->getMockForAbstractClass ();
301
313
302
- $ filters = $ this ->getMockBuilder (\ Magento \ Ui \ Component \ Filters::class)
314
+ $ filters = $ this ->getMockBuilder (Filters::class)
303
315
->disableOriginalConstructor ()
304
316
->getMock ();
305
317
306
318
/** @var Columns|\PHPUnit_Framework_MockObject_MockObject $columns */
307
- $ columns = $ this ->getMockBuilder (\ Magento \ Ui \ Component \ Listing \ Columns::class)
319
+ $ columns = $ this ->getMockBuilder (Columns::class)
308
320
->disableOriginalConstructor ()
309
321
->getMock ();
310
322
311
323
/** @var Column|\PHPUnit_Framework_MockObject_MockObject $column */
312
- $ column = $ this ->getMockBuilder (\ Magento \ Ui \ Component \ Listing \ Columns \ Column::class)
324
+ $ column = $ this ->getMockBuilder (Column::class)
313
325
->disableOriginalConstructor ()
314
326
->getMock ();
315
327
/** @var Column|\PHPUnit_Framework_MockObject_MockObject $columnActions */
316
- $ columnActions = $ this ->getMockBuilder (\ Magento \ Ui \ Component \ Listing \ Columns \ Column::class)
328
+ $ columnActions = $ this ->getMockBuilder (Column::class)
317
329
->disableOriginalConstructor ()
318
330
->getMock ();
319
331
@@ -328,7 +340,7 @@ protected function prepareColumnsWithOptions(string $filter, array $options)
328
340
->method ('getChildComponents ' )
329
341
->willReturn ([$ filters ]);
330
342
331
- $ select = $ this ->getMockBuilder (\ Magento \ Ui \ Component \ Filters \ Type \ Select::class)
343
+ $ select = $ this ->getMockBuilder (Select::class)
332
344
->disableOriginalConstructor ()
333
345
->getMock ();
334
346
@@ -446,29 +458,30 @@ public function getOptionsDataProvider()
446
458
*
447
459
* @param string $fieldValue
448
460
* @param string $expected
461
+ *
449
462
* @dataProvider convertDateProvider
450
463
* @covers \Magento\Ui\Model\Export\MetadataProvider::convertDate()
451
464
*/
452
465
public function testConvertDate ($ fieldValue , $ expected )
453
466
{
454
467
$ componentName = 'component_name ' ;
455
468
/** @var DocumentInterface|\PHPUnit_Framework_MockObject_MockObject $document */
456
- $ document = $ this ->getMockBuilder (\ Magento \ Framework \ DataObject::class)
457
- ->disableOriginalConstructor ()
458
- ->getMock ();
469
+ $ document = $ this ->getMockBuilder (DataObject::class)
470
+ ->disableOriginalConstructor ()
471
+ ->getMock ();
459
472
460
473
$ document ->expects ($ this ->once ())
461
- ->method ('getData ' )
462
- ->with ('field ' )
463
- ->willReturn ($ fieldValue );
474
+ ->method ('getData ' )
475
+ ->with ('field ' )
476
+ ->willReturn ($ fieldValue );
464
477
465
478
$ this ->localeDate ->expects ($ this ->once ())
466
- ->method ('date ' )
467
- ->willReturn (new \DateTime ($ fieldValue , new \DateTimeZone ('UTC ' )));
479
+ ->method ('date ' )
480
+ ->willReturn (new \DateTime ($ fieldValue , new \DateTimeZone ('UTC ' )));
468
481
469
482
$ document ->expects ($ this ->once ())
470
- ->method ('setData ' )
471
- ->with ('field ' , $ expected );
483
+ ->method ('setData ' )
484
+ ->with ('field ' , $ expected );
472
485
473
486
$ this ->model ->convertDate ($ document , $ componentName );
474
487
}
0 commit comments