8
8
9
9
use Magento \Framework \Api \AttributeInterface ;
10
10
use Magento \Framework \Api \Search \DocumentInterface ;
11
+ use Magento \Framework \Data \OptionSourceInterface ;
11
12
use Magento \Framework \DataObject ;
12
13
use Magento \Framework \Exception \LocalizedException ;
13
14
use Magento \Framework \Locale \ResolverInterface ;
@@ -276,33 +277,36 @@ public function getRowDataProvider()
276
277
277
278
/**
278
279
* @param string $filter
279
- * @param array $options
280
+ * @param array $filterOptions
281
+ * @param array $columnsOptions
280
282
* @param array $expected
281
283
*
282
- * @dataProvider getOptionsDataProvider
283
284
* @throws LocalizedException
285
+ * @dataProvider getOptionsDataProvider
284
286
*/
285
- public function testGetOptions ($ filter , $ options , $ expected )
287
+ public function testGetOptions (string $ filter , array $ filterOptions , array $ columnsOptions , array $ expected )
286
288
{
287
- $ component = $ this ->prepareColumnsWithOptions ($ filter , $ options );
289
+ $ component = $ this ->prepareColumnsWithOptions ($ filter , $ filterOptions , $ columnsOptions );
288
290
289
291
$ this ->filter ->expects ($ this ->exactly (2 ))
290
292
->method ('getComponent ' )
291
293
->willReturn ($ component );
292
294
293
295
$ result = $ this ->model ->getOptions ();
294
296
$ this ->assertTrue (is_array ($ result ));
295
- $ this ->assertCount (1 , $ result );
297
+ $ this ->assertCount (2 , $ result );
296
298
$ this ->assertEquals ($ expected , $ result );
297
299
}
298
300
299
301
/**
300
302
* @param string $filter
301
- * @param array $options
303
+ * @param array $filterOptions
304
+ *
305
+ * @param array $columnsOptions
302
306
*
303
307
* @return UiComponentInterface|\PHPUnit_Framework_MockObject_MockObject
304
308
*/
305
- protected function prepareColumnsWithOptions (string $ filter , array $ options )
309
+ protected function prepareColumnsWithOptions (string $ filter , array $ filterOptions , array $ columnsOptions )
306
310
{
307
311
/** @var UiComponentInterface|\PHPUnit_Framework_MockObject_MockObject $component */
308
312
$ component = $ this ->getMockBuilder (UiComponentInterface::class)
@@ -354,7 +358,7 @@ protected function prepareColumnsWithOptions(string $filter, array $options)
354
358
$ select ->expects ($ this ->any ())
355
359
->method ('getData ' )
356
360
->with ('config/options ' )
357
- ->willReturn ($ options );
361
+ ->willReturn ($ filterOptions );
358
362
359
363
$ columns ->expects ($ this ->atLeastOnce ())
360
364
->method ('getChildComponents ' )
@@ -363,15 +367,28 @@ protected function prepareColumnsWithOptions(string $filter, array $options)
363
367
$ column ->expects ($ this ->any ())
364
368
->method ('getName ' )
365
369
->willReturn ('column_name ' );
370
+
371
+ $ optionSource = $ this ->getMockBuilder (OptionSourceInterface::class)
372
+ ->getMockForAbstractClass ();
373
+ $ optionSource ->expects ($ this ->once ())
374
+ ->method ('toOptionArray ' )
375
+ ->willReturn ($ columnsOptions );
376
+
366
377
$ column ->expects ($ this ->any ())
367
378
->method ('getData ' )
368
379
->willReturnMap (
369
380
[
370
381
['config/label ' , null , 'column_label ' ],
371
382
['config/dataType ' , null , 'data_type ' ],
383
+ ['options ' , null , $ optionSource ],
372
384
]
373
385
);
374
386
387
+ $ column ->expects ($ this ->once ())
388
+ ->method ('hasData ' )
389
+ ->willReturn (true )
390
+ ->with ('options ' );
391
+
375
392
$ columnActions ->expects ($ this ->any ())
376
393
->method ('getName ' )
377
394
->willReturn ('column_actions_name ' );
@@ -395,7 +412,13 @@ public function getOptionsDataProvider()
395
412
return [
396
413
[
397
414
'filter ' => 'filter_name ' ,
398
- 'options ' => [
415
+ 'filterOptions ' => [
416
+ [
417
+ 'value ' => 'value_1 ' ,
418
+ 'label ' => 'label_1 ' ,
419
+ ]
420
+ ],
421
+ 'columnsOptions ' => [
399
422
[
400
423
'value ' => 'value_1 ' ,
401
424
'label ' => 'label_1 ' ,
@@ -405,11 +428,25 @@ public function getOptionsDataProvider()
405
428
'filter_name ' => [
406
429
'value_1 ' => 'label_1 ' ,
407
430
],
431
+ 'column_name ' => [
432
+ 'value_1 ' => 'label_1 ' ,
433
+ ]
408
434
],
409
435
],
410
436
[
411
437
'filter ' => 'filter_name ' ,
412
- 'options ' => [
438
+ 'filterOptions ' => [
439
+ [
440
+ 'value ' => [
441
+ [
442
+ 'value ' => 'value_2 ' ,
443
+ 'label ' => 'label_2 ' ,
444
+ ],
445
+ ],
446
+ 'label ' => 'label_1 ' ,
447
+ ]
448
+ ],
449
+ 'columnsOptions ' => [
413
450
[
414
451
'value ' => [
415
452
[
@@ -424,11 +461,14 @@ public function getOptionsDataProvider()
424
461
'filter_name ' => [
425
462
'value_2 ' => 'label_1label_2 ' ,
426
463
],
464
+ 'column_name ' => [
465
+ 'value_2 ' => 'label_1label_2 ' ,
466
+ ]
427
467
],
428
468
],
429
469
[
430
470
'filter ' => 'filter_name ' ,
431
- 'options ' => [
471
+ 'filterOptions ' => [
432
472
[
433
473
'value ' => [
434
474
[
@@ -444,10 +484,12 @@ public function getOptionsDataProvider()
444
484
'label ' => 'label_1 ' ,
445
485
]
446
486
],
487
+ 'columnsOptions ' => [],
447
488
'expected ' => [
448
489
'filter_name ' => [
449
490
'value_3 ' => 'label_1label_2label_3 ' ,
450
491
],
492
+ 'column_name ' => []
451
493
],
452
494
],
453
495
];
@@ -461,6 +503,7 @@ public function getOptionsDataProvider()
461
503
*
462
504
* @dataProvider convertDateProvider
463
505
* @covers \Magento\Ui\Model\Export\MetadataProvider::convertDate()
506
+ * @throws \Exception
464
507
*/
465
508
public function testConvertDate ($ fieldValue , $ expected )
466
509
{
0 commit comments