Skip to content

Commit 781b6bf

Browse files
committed
MC-42132: Admin product grid for dropdown/multiselect attributes use store view and not admin values
1 parent bf4cdad commit 781b6bf

File tree

2 files changed

+76
-29
lines changed

2 files changed

+76
-29
lines changed

app/code/Magento/Catalog/Test/Unit/Ui/Component/ColumnFactoryTest.php

Lines changed: 75 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@
99

1010
use Magento\Catalog\Model\ResourceModel\Eav\Attribute;
1111
use Magento\Catalog\Ui\Component\ColumnFactory;
12+
use Magento\Eav\Model\Entity\Attribute\Source\AbstractSource;
1213
use Magento\Framework\Stdlib\DateTime\TimezoneInterface;
13-
use Magento\Framework\TestFramework\Unit\Helper\ObjectManager;
1414
use Magento\Framework\View\Element\UiComponent\ContextInterface;
1515
use Magento\Framework\View\Element\UiComponentFactory;
1616
use Magento\Ui\Component\Filters\FilterModifier;
@@ -28,11 +28,6 @@ class ColumnFactoryTest extends TestCase
2828
*/
2929
private $columnFactory;
3030

31-
/**
32-
* @var ObjectManager
33-
*/
34-
private $objectManager;
35-
3631
/**
3732
* @var Attribute|MockObject
3833
*/
@@ -63,32 +58,15 @@ class ColumnFactoryTest extends TestCase
6358
*/
6459
protected function setUp(): void
6560
{
66-
$this->objectManager = new ObjectManager($this);
67-
68-
$this->attribute = $this->createPartialMock(
69-
Attribute::class,
70-
[
71-
'getAttributeCode',
72-
'getIsFilterableInGrid',
73-
'getFrontendInput',
74-
'getDefaultFrontendLabel',
75-
'getIsVisibleInGrid',
76-
]
77-
);
78-
$this->context = $this->getMockForAbstractClass(ContextInterface::class);
61+
$this->attribute = $this->createMock(Attribute::class);
62+
$this->context = $this->createMock(ContextInterface::class);
7963
$this->uiComponentFactory = $this->createMock(UiComponentFactory::class);
80-
$this->column = $this->getMockForAbstractClass(ColumnInterface::class);
64+
$this->column = $this->createMock(ColumnInterface::class);
8165
$this->uiComponentFactory->method('create')
8266
->willReturn($this->column);
83-
$this->timezone = $this->getMockForAbstractClass(TimezoneInterface::class);
67+
$this->timezone = $this->createMock(TimezoneInterface::class);
8468

85-
$this->columnFactory = $this->objectManager->getObject(
86-
ColumnFactory::class,
87-
[
88-
'componentFactory' => $this->uiComponentFactory,
89-
'timezone' => $this->timezone,
90-
]
91-
);
69+
$this->columnFactory = new ColumnFactory($this->uiComponentFactory, $this->timezone);
9270
}
9371

9472
/**
@@ -268,4 +246,73 @@ public function createDateColumnDataProvider(): array
268246
],
269247
];
270248
}
249+
250+
public function testCreateAttributeWithSource(): void
251+
{
252+
$this->context->method('getRequestParam')
253+
->with(FilterModifier::FILTER_MODIFIER, [])
254+
->willReturn([]);
255+
$attributeCode = 'color';
256+
$this->attribute->expects($this->atLeastOnce())
257+
->method('getAttributeCode')
258+
->willReturn($attributeCode);
259+
$label = 'Color';
260+
$this->attribute->expects($this->atLeastOnce())
261+
->method('getDefaultFrontendLabel')
262+
->willReturn($label);
263+
$this->attribute->expects($this->atLeastOnce())
264+
->method('getFrontendInput')
265+
->willReturn('select');
266+
$this->attribute->expects($this->atLeastOnce())
267+
->method('getIsVisibleInGrid')
268+
->willReturn(true);
269+
$this->attribute->expects($this->atLeastOnce())
270+
->method('getIsFilterableInGrid')
271+
->willReturn(true);
272+
$this->attribute->expects($this->atLeastOnce())
273+
->method('usesSource')
274+
->willReturn(true);
275+
$source = $this->createMock(AbstractSource::class);
276+
$this->attribute->expects($this->atLeastOnce())
277+
->method('getSource')
278+
->willReturn($source);
279+
$options = [
280+
['label' => ''],
281+
['label' => 'admin1'],
282+
['label' => 'admin2'],
283+
];
284+
$source->expects($this->atLeastOnce())
285+
->method('getAllOptions')
286+
->with(true, true)
287+
->willReturn($options);
288+
289+
$expectedConfig = [
290+
'label' => __($label),
291+
'dataType' => 'select',
292+
'add_field' => true,
293+
'visible' => true,
294+
'filter' => 'select',
295+
'component' => 'Magento_Ui/js/grid/columns/select',
296+
'options' => array_map(
297+
function (array $option) {
298+
$option['__disableTmpl'] = true;
299+
return $option;
300+
},
301+
$options
302+
),
303+
];
304+
$expectedArguments = [
305+
'data' => ['config' => $expectedConfig],
306+
'context' => $this->context,
307+
];
308+
$this->uiComponentFactory->expects($this->once())
309+
->method('create')
310+
->with($attributeCode, 'column', $expectedArguments)
311+
->willReturn($this->column);
312+
313+
$this->assertEquals(
314+
$this->column,
315+
$this->columnFactory->create($this->attribute, $this->context)
316+
);
317+
}
271318
}

app/code/Magento/Catalog/Ui/Component/ColumnFactory.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ public function create($attribute, $context, array $config = [])
9797
);
9898

9999
if ($attribute->usesSource()) {
100-
$config['options'] = $attribute->getSource()->getAllOptions();
100+
$config['options'] = $attribute->getSource()->getAllOptions(true, true);
101101
foreach ($config['options'] as &$optionData) {
102102
$optionData['__disableTmpl'] = true;
103103
}

0 commit comments

Comments
 (0)