Skip to content

Commit 9bb416f

Browse files
committed
Grid Export rendered data is not reflecting in the exported File, Displayed ID instead of Rendered Label #25963.
Fixed Unit tests.
1 parent c517f5f commit 9bb416f

File tree

1 file changed

+91
-31
lines changed

1 file changed

+91
-31
lines changed

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

Lines changed: 91 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,12 @@
88
use Magento\Framework\Api\Search\DocumentInterface;
99
use Magento\Framework\Locale\ResolverInterface;
1010
use Magento\Framework\Stdlib\DateTime\TimezoneInterface;
11+
use Magento\Framework\TestFramework\Unit\Helper\ObjectManager;
1112
use Magento\Framework\View\Element\UiComponentInterface;
1213
use Magento\Ui\Component\Listing\Columns;
1314
use Magento\Ui\Component\Listing\Columns\Column;
1415
use Magento\Ui\Component\MassAction\Filter;
1516
use Magento\Ui\Model\Export\MetadataProvider;
16-
use Magento\Framework\TestFramework\Unit\Helper\ObjectManager;
1717

1818
/**
1919
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
@@ -76,8 +76,10 @@ protected function setUp()
7676
/**
7777
* @param array $columnLabels
7878
* @param array $expected
79+
*
7980
* @return void
8081
* @dataProvider getColumnsDataProvider
82+
* @throws \Exception
8183
*/
8284
public function testGetHeaders(array $columnLabels, array $expected): void
8385
{
@@ -156,11 +158,11 @@ protected function prepareColumns(
156158
$component->expects($this->any())
157159
->method('getName')
158160
->willReturn($componentName);
159-
$component->expects($this->once())
161+
$component->expects($this->atLeastOnce())
160162
->method('getChildComponents')
161163
->willReturn([$columns]);
162164

163-
$columns->expects($this->once())
165+
$columns->expects($this->atLeastOnce())
164166
->method('getChildComponents')
165167
->willReturn([$column, $columnActions]);
166168

@@ -267,52 +269,110 @@ public function getRowDataProvider()
267269
* @param string $filter
268270
* @param array $options
269271
* @param array $expected
272+
*
270273
* @dataProvider getOptionsDataProvider
274+
* @throws \Magento\Framework\Exception\LocalizedException
271275
*/
272276
public function testGetOptions($filter, $options, $expected)
273277
{
278+
$component = $this->prepareColumnsWithOptions($filter, $options);
279+
280+
$this->filter->expects($this->exactly(2))
281+
->method('getComponent')
282+
->willReturn($component);
283+
284+
$result = $this->model->getOptions();
285+
$this->assertTrue(is_array($result));
286+
$this->assertCount(1, $result);
287+
$this->assertEquals($expected, $result);
288+
}
289+
290+
/**
291+
* @return UiComponentInterface|\PHPUnit_Framework_MockObject_MockObject
292+
*/
293+
protected function prepareColumnsWithOptions(string $filter, array $options)
294+
{
295+
/** @var UiComponentInterface|\PHPUnit_Framework_MockObject_MockObject $component */
274296
$component = $this->getMockBuilder(\Magento\Framework\View\Element\UiComponentInterface::class)
275-
->getMockForAbstractClass();
297+
->getMockForAbstractClass();
276298

277-
$childComponent = $this->getMockBuilder(\Magento\Framework\View\Element\UiComponentInterface::class)
278-
->getMockForAbstractClass();
299+
$listingTopComponent = $this->getMockBuilder(\Magento\Framework\View\Element\UiComponentInterface::class)
300+
->getMockForAbstractClass();
279301

280302
$filters = $this->getMockBuilder(\Magento\Ui\Component\Filters::class)
281-
->disableOriginalConstructor()
282-
->getMock();
303+
->disableOriginalConstructor()
304+
->getMock();
283305

284-
$select = $this->getMockBuilder(\Magento\Ui\Component\Filters\Type\Select::class)
285-
->disableOriginalConstructor()
286-
->getMock();
306+
/** @var Columns|\PHPUnit_Framework_MockObject_MockObject $columns */
307+
$columns = $this->getMockBuilder(\Magento\Ui\Component\Listing\Columns::class)
308+
->disableOriginalConstructor()
309+
->getMock();
287310

288-
$this->filter->expects($this->once())
289-
->method('getComponent')
290-
->willReturn($component);
311+
/** @var Column|\PHPUnit_Framework_MockObject_MockObject $column */
312+
$column = $this->getMockBuilder(\Magento\Ui\Component\Listing\Columns\Column::class)
313+
->disableOriginalConstructor()
314+
->getMock();
315+
/** @var Column|\PHPUnit_Framework_MockObject_MockObject $columnActions */
316+
$columnActions = $this->getMockBuilder(\Magento\Ui\Component\Listing\Columns\Column::class)
317+
->disableOriginalConstructor()
318+
->getMock();
291319

292-
$component->expects($this->once())
293-
->method('getChildComponents')
294-
->willReturn(['listing_top' => $childComponent]);
320+
$component->expects($this->any())
321+
->method('getName')
322+
->willReturn('columns_component_name');
323+
$component->expects($this->atLeastOnce())
324+
->method('getChildComponents')
325+
->willReturn(['columns' => $columns, 'listing_top' => $listingTopComponent]);
295326

296-
$childComponent->expects($this->once())
297-
->method('getChildComponents')
298-
->willReturn([$filters]);
327+
$listingTopComponent->expects($this->once())
328+
->method('getChildComponents')
329+
->willReturn([$filters]);
330+
331+
$select = $this->getMockBuilder(\Magento\Ui\Component\Filters\Type\Select::class)
332+
->disableOriginalConstructor()
333+
->getMock();
299334

300335
$filters->expects($this->once())
301-
->method('getChildComponents')
302-
->willReturn([$select]);
336+
->method('getChildComponents')
337+
->willReturn([$select]);
303338

304339
$select->expects($this->any())
305-
->method('getName')
306-
->willReturn($filter);
340+
->method('getName')
341+
->willReturn($filter);
307342
$select->expects($this->any())
308-
->method('getData')
309-
->with('config/options')
310-
->willReturn($options);
343+
->method('getData')
344+
->with('config/options')
345+
->willReturn($options);
311346

312-
$result = $this->model->getOptions();
313-
$this->assertTrue(is_array($result));
314-
$this->assertCount(1, $result);
315-
$this->assertEquals($expected, $result);
347+
$columns->expects($this->atLeastOnce())
348+
->method('getChildComponents')
349+
->willReturn([$column, $columnActions]);
350+
351+
$column->expects($this->any())
352+
->method('getName')
353+
->willReturn('column_name');
354+
$column->expects($this->any())
355+
->method('getData')
356+
->willReturnMap(
357+
[
358+
['config/label', null, 'column_label'],
359+
['config/dataType', null, 'data_type'],
360+
]
361+
);
362+
363+
$columnActions->expects($this->any())
364+
->method('getName')
365+
->willReturn('column_actions_name');
366+
$columnActions->expects($this->any())
367+
->method('getData')
368+
->willReturnMap(
369+
[
370+
['config/label', null, 'column_actions_label'],
371+
['config/dataType', null, 'actions'],
372+
]
373+
);
374+
375+
return $component;
316376
}
317377

318378
/**

0 commit comments

Comments
 (0)