Skip to content

Commit 7421614

Browse files
committed
Merge remote-tracking branch 'origin/MAGETWO-98088' into 2.3-develop-pr18
2 parents e51df41 + 34a37cb commit 7421614

File tree

3 files changed

+225
-3
lines changed

3 files changed

+225
-3
lines changed
Lines changed: 156 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,156 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
declare(strict_types=1);
7+
8+
namespace Magento\Catalog\Test\Unit\Ui\Component;
9+
10+
use PHPUnit\Framework\TestCase;
11+
use Magento\Catalog\Ui\Component\ColumnFactory;
12+
use Magento\Framework\TestFramework\Unit\Helper\ObjectManager;
13+
use Magento\Catalog\Api\Data\ProductAttributeInterface;
14+
use Magento\Framework\View\Element\UiComponent\ContextInterface;
15+
use Magento\Framework\View\Element\UiComponentFactory;
16+
use Magento\Ui\Component\Listing\Columns\ColumnInterface;
17+
use Magento\Ui\Component\Filters\FilterModifier;
18+
19+
/**
20+
* ColumnFactory test.
21+
*/
22+
class ColumnFactoryTest extends TestCase
23+
{
24+
/**
25+
* @var ColumnFactory
26+
*/
27+
private $columnFactory;
28+
29+
/**
30+
* @var ObjectManager
31+
*/
32+
private $objectManager;
33+
34+
/**
35+
* @var ProductAttributeInterface|\PHPUnit\Framework\MockObject\MockObject
36+
*/
37+
private $attribute;
38+
39+
/**
40+
* @var ContextInterface|\PHPUnit\Framework\MockObject\MockObject
41+
*/
42+
private $context;
43+
44+
/**
45+
* @var UiComponentFactory|\PHPUnit\Framework\MockObject\MockObject
46+
*/
47+
private $uiComponentFactory;
48+
49+
/**
50+
* @var ColumnInterface|\PHPUnit\Framework\MockObject\MockObject
51+
*/
52+
private $column;
53+
54+
/**
55+
* @inheritdoc
56+
*/
57+
protected function setUp(): void
58+
{
59+
$this->objectManager = new ObjectManager($this);
60+
61+
$this->attribute = $this->getMockBuilder(ProductAttributeInterface::class)
62+
->setMethods(['usesSource'])
63+
->getMockForAbstractClass();
64+
$this->context = $this->createMock(ContextInterface::class);
65+
$this->uiComponentFactory = $this->createMock(UiComponentFactory::class);
66+
$this->column = $this->getMockForAbstractClass(ColumnInterface::class);
67+
$this->uiComponentFactory->method('create')
68+
->willReturn($this->column);
69+
70+
$this->columnFactory = $this->objectManager->getObject(ColumnFactory::class, [
71+
'componentFactory' => $this->uiComponentFactory
72+
]);
73+
}
74+
75+
/**
76+
* Tests the create method will return correct object.
77+
*
78+
* @return void
79+
*/
80+
public function testCreatedObject(): void
81+
{
82+
$this->context->method('getRequestParam')
83+
->with(FilterModifier::FILTER_MODIFIER, [])
84+
->willReturn([]);
85+
86+
$object = $this->columnFactory->create($this->attribute, $this->context);
87+
$this->assertEquals(
88+
$this->column,
89+
$object,
90+
'Object must be the same which the ui component factory creates.'
91+
);
92+
}
93+
94+
/**
95+
* Tests create method with not filterable in grid attribute.
96+
*
97+
* @param array $filterModifiers
98+
* @param null|string $filter
99+
*
100+
* @return void
101+
* @dataProvider filterModifiersProvider
102+
*/
103+
public function testCreateWithNotFilterableInGridAttribute(array $filterModifiers, ?string $filter): void
104+
{
105+
$componentFactoryArgument = [
106+
'data' => [
107+
'config' => [
108+
'label' => __(null),
109+
'dataType' => 'text',
110+
'add_field' => true,
111+
'visible' => null,
112+
'filter' => $filter,
113+
'component' => 'Magento_Ui/js/grid/columns/column',
114+
],
115+
],
116+
'context' => $this->context,
117+
];
118+
119+
$this->context->method('getRequestParam')
120+
->with(FilterModifier::FILTER_MODIFIER, [])
121+
->willReturn($filterModifiers);
122+
$this->attribute->method('getIsFilterableInGrid')
123+
->willReturn(false);
124+
$this->attribute->method('getAttributeCode')
125+
->willReturn('color');
126+
127+
$this->uiComponentFactory->expects($this->once())
128+
->method('create')
129+
->with($this->anything(), $this->anything(), $componentFactoryArgument);
130+
131+
$this->columnFactory->create($this->attribute, $this->context);
132+
}
133+
134+
/**
135+
* Filter modifiers data provider.
136+
*
137+
* @return array
138+
*/
139+
public function filterModifiersProvider(): array
140+
{
141+
return [
142+
'without' => [
143+
'filter_modifiers' => [],
144+
'filter' => null,
145+
],
146+
'with' => [
147+
'filter_modifiers' => [
148+
'color' => [
149+
'condition_type' => 'notnull',
150+
],
151+
],
152+
'filter' => 'text',
153+
],
154+
];
155+
}
156+
}

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

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
*/
66
namespace Magento\Catalog\Ui\Component;
77

8+
use Magento\Ui\Component\Filters\FilterModifier;
9+
810
/**
911
* Column Factory
1012
*
@@ -60,13 +62,15 @@ public function __construct(\Magento\Framework\View\Element\UiComponentFactory $
6062
*/
6163
public function create($attribute, $context, array $config = [])
6264
{
65+
$filterModifiers = $context->getRequestParam(FilterModifier::FILTER_MODIFIER, []);
66+
6367
$columnName = $attribute->getAttributeCode();
6468
$config = array_merge([
6569
'label' => __($attribute->getDefaultFrontendLabel()),
6670
'dataType' => $this->getDataType($attribute),
6771
'add_field' => true,
6872
'visible' => $attribute->getIsVisibleInGrid(),
69-
'filter' => ($attribute->getIsFilterableInGrid())
73+
'filter' => ($attribute->getIsFilterableInGrid() || array_key_exists($columnName, $filterModifiers))
7074
? $this->getFilterType($attribute->getFrontendInput())
7175
: null,
7276
], $config);

dev/tests/integration/testsuite/Magento/ConfigurableProduct/Ui/DataProvider/Product/Form/Modifier/Data/AssociatedProductsTest.php

Lines changed: 64 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,19 @@
55
*/
66
namespace Magento\ConfigurableProduct\Ui\DataProvider\Product\Form\Modifier\Data;
77

8-
class AssociatedProductsTest extends \PHPUnit\Framework\TestCase
8+
use Magento\Framework\View\Element\UiComponentFactory;
9+
use Magento\Ui\Component\Filters\FilterModifier;
10+
use Magento\Framework\View\Element\UiComponent\ContextInterface;
11+
use Magento\ConfigurableProduct\Ui\DataProvider\Product\Form\Modifier\ConfigurablePanel;
12+
use Magento\Framework\App\RequestInterface;
13+
use PHPUnit\Framework\TestCase;
14+
15+
/**
16+
* AssociatedProductsTest
17+
*
18+
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
19+
*/
20+
class AssociatedProductsTest extends TestCase
921
{
1022
/**
1123
* @var \Magento\Framework\ObjectManagerInterface $objectManager
@@ -17,7 +29,10 @@ class AssociatedProductsTest extends \PHPUnit\Framework\TestCase
1729
*/
1830
private $registry;
1931

20-
public function setUp()
32+
/**
33+
* @inheritdoc
34+
*/
35+
public function setUp(): void
2136
{
2237
$this->objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager();
2338
$this->registry = $this->objectManager->get(\Magento\Framework\Registry::class);
@@ -64,6 +79,53 @@ public function testGetProductMatrix($interfaceLocale)
6479
}
6580
}
6681

82+
/**
83+
* Tests configurable product won't appear in product listing.
84+
*
85+
* Tests configurable product won't appear in configurable associated product listing if its options attribute
86+
* is not filterable in grid.
87+
*
88+
* @return void
89+
* @magentoDataFixture Magento/ConfigurableProduct/_files/product_configurable.php
90+
* @magentoAppArea adminhtml
91+
*/
92+
public function testAddManuallyConfigurationsWithNotFilterableInGridAttribute(): void
93+
{
94+
/** @var RequestInterface $request */
95+
$request = $this->objectManager->get(RequestInterface::class);
96+
$request->setParams([
97+
FilterModifier::FILTER_MODIFIER => [
98+
'test_configurable' => [
99+
'condition_type' => 'notnull',
100+
],
101+
],
102+
'attributes_codes' => [
103+
'test_configurable'
104+
],
105+
]);
106+
$context = $this->objectManager->create(ContextInterface::class, ['request' => $request]);
107+
/** @var UiComponentFactory $uiComponentFactory */
108+
$uiComponentFactory = $this->objectManager->get(UiComponentFactory::class);
109+
$uiComponent = $uiComponentFactory->create(
110+
ConfigurablePanel::ASSOCIATED_PRODUCT_LISTING,
111+
null,
112+
['context' => $context]
113+
);
114+
115+
foreach ($uiComponent->getChildComponents() as $childUiComponent) {
116+
$childUiComponent->prepare();
117+
}
118+
119+
$dataSource = $uiComponent->getDataSourceData();
120+
$skus = array_column($dataSource['data']['items'], 'sku');
121+
122+
$this->assertNotContains(
123+
'configurable',
124+
$skus,
125+
'Only products with specified attribute should be in product list'
126+
);
127+
}
128+
67129
/**
68130
* @return array
69131
*/

0 commit comments

Comments
 (0)