Skip to content

Commit 6b434ba

Browse files
committed
Grid Export rendered data is not reflecting in the exported File, Displayed ID instead of Rendered Label #25963.
Implemented Unit tests coverage.
1 parent cd24e41 commit 6b434ba

File tree

2 files changed

+55
-12
lines changed

2 files changed

+55
-12
lines changed

app/code/Magento/Ui/Model/Export/MetadataProvider.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -260,7 +260,7 @@ protected function getColumnOptions(): array
260260
$optionSource = $columnComponent->getData('options');
261261
$optionsArray = $optionSource instanceof OptionSourceInterface ?
262262
$optionSource->toOptionArray() : $optionSource;
263-
$options[$columnComponent->getName()] = $this->getOptionsArray($optionsArray);
263+
$options[$columnComponent->getName()] = $this->getOptionsArray($optionsArray ?: []);
264264
}
265265
}
266266

app/code/Magento/Ui/Test/Unit/Model/Export/MetadataProviderTest.php

Lines changed: 54 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99
use Magento\Framework\Api\AttributeInterface;
1010
use Magento\Framework\Api\Search\DocumentInterface;
11+
use Magento\Framework\Data\OptionSourceInterface;
1112
use Magento\Framework\DataObject;
1213
use Magento\Framework\Exception\LocalizedException;
1314
use Magento\Framework\Locale\ResolverInterface;
@@ -276,33 +277,36 @@ public function getRowDataProvider()
276277

277278
/**
278279
* @param string $filter
279-
* @param array $options
280+
* @param array $filterOptions
281+
* @param array $columnsOptions
280282
* @param array $expected
281283
*
282-
* @dataProvider getOptionsDataProvider
283284
* @throws LocalizedException
285+
* @dataProvider getOptionsDataProvider
284286
*/
285-
public function testGetOptions($filter, $options, $expected)
287+
public function testGetOptions(string $filter, array $filterOptions, array $columnsOptions, array $expected)
286288
{
287-
$component = $this->prepareColumnsWithOptions($filter, $options);
289+
$component = $this->prepareColumnsWithOptions($filter, $filterOptions, $columnsOptions);
288290

289291
$this->filter->expects($this->exactly(2))
290292
->method('getComponent')
291293
->willReturn($component);
292294

293295
$result = $this->model->getOptions();
294296
$this->assertTrue(is_array($result));
295-
$this->assertCount(1, $result);
297+
$this->assertCount(2, $result);
296298
$this->assertEquals($expected, $result);
297299
}
298300

299301
/**
300302
* @param string $filter
301-
* @param array $options
303+
* @param array $filterOptions
304+
*
305+
* @param array $columnsOptions
302306
*
303307
* @return UiComponentInterface|\PHPUnit_Framework_MockObject_MockObject
304308
*/
305-
protected function prepareColumnsWithOptions(string $filter, array $options)
309+
protected function prepareColumnsWithOptions(string $filter, array $filterOptions, array $columnsOptions)
306310
{
307311
/** @var UiComponentInterface|\PHPUnit_Framework_MockObject_MockObject $component */
308312
$component = $this->getMockBuilder(UiComponentInterface::class)
@@ -354,7 +358,7 @@ protected function prepareColumnsWithOptions(string $filter, array $options)
354358
$select->expects($this->any())
355359
->method('getData')
356360
->with('config/options')
357-
->willReturn($options);
361+
->willReturn($filterOptions);
358362

359363
$columns->expects($this->atLeastOnce())
360364
->method('getChildComponents')
@@ -363,15 +367,28 @@ protected function prepareColumnsWithOptions(string $filter, array $options)
363367
$column->expects($this->any())
364368
->method('getName')
365369
->willReturn('column_name');
370+
371+
$optionSource = $this->getMockBuilder(OptionSourceInterface::class)
372+
->getMockForAbstractClass();
373+
$optionSource->expects($this->once())
374+
->method('toOptionArray')
375+
->willReturn($columnsOptions);
376+
366377
$column->expects($this->any())
367378
->method('getData')
368379
->willReturnMap(
369380
[
370381
['config/label', null, 'column_label'],
371382
['config/dataType', null, 'data_type'],
383+
['options', null, $optionSource],
372384
]
373385
);
374386

387+
$column->expects($this->once())
388+
->method('hasData')
389+
->willReturn(true)
390+
->with('options');
391+
375392
$columnActions->expects($this->any())
376393
->method('getName')
377394
->willReturn('column_actions_name');
@@ -395,7 +412,13 @@ public function getOptionsDataProvider()
395412
return [
396413
[
397414
'filter' => 'filter_name',
398-
'options' => [
415+
'filterOptions' => [
416+
[
417+
'value' => 'value_1',
418+
'label' => 'label_1',
419+
]
420+
],
421+
'columnsOptions' => [
399422
[
400423
'value' => 'value_1',
401424
'label' => 'label_1',
@@ -405,11 +428,25 @@ public function getOptionsDataProvider()
405428
'filter_name' => [
406429
'value_1' => 'label_1',
407430
],
431+
'column_name' => [
432+
'value_1' => 'label_1',
433+
]
408434
],
409435
],
410436
[
411437
'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' => [
413450
[
414451
'value' => [
415452
[
@@ -424,11 +461,14 @@ public function getOptionsDataProvider()
424461
'filter_name' => [
425462
'value_2' => 'label_1label_2',
426463
],
464+
'column_name' => [
465+
'value_2' => 'label_1label_2',
466+
]
427467
],
428468
],
429469
[
430470
'filter' => 'filter_name',
431-
'options' => [
471+
'filterOptions' => [
432472
[
433473
'value' => [
434474
[
@@ -444,10 +484,12 @@ public function getOptionsDataProvider()
444484
'label' => 'label_1',
445485
]
446486
],
487+
'columnsOptions' => [],
447488
'expected' => [
448489
'filter_name' => [
449490
'value_3' => 'label_1label_2label_3',
450491
],
492+
'column_name' => []
451493
],
452494
],
453495
];
@@ -461,6 +503,7 @@ public function getOptionsDataProvider()
461503
*
462504
* @dataProvider convertDateProvider
463505
* @covers \Magento\Ui\Model\Export\MetadataProvider::convertDate()
506+
* @throws \Exception
464507
*/
465508
public function testConvertDate($fieldValue, $expected)
466509
{

0 commit comments

Comments
 (0)