Skip to content

Commit 350d12d

Browse files
author
Mykola Palamar
committed
MAGETWO-56487: [GitHub] Multi-select option attribute values do not appear in admin #5877
1 parent 1d5d114 commit 350d12d

File tree

2 files changed

+50
-32
lines changed

2 files changed

+50
-32
lines changed

app/code/Magento/Catalog/Controller/Adminhtml/Product/Attribute/Validate.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ public function execute()
109109
$response,
110110
$options
111111
);
112-
$valueOptions = is_array($options['value']) ? $options['value'] : [];
112+
$valueOptions = (isset($options['value']) && is_array($options['value'])) ? $options['value'] : [];
113113
$this->checkEmptyOption($response, $valueOptions);
114114
}
115115

app/code/Magento/Catalog/Test/Unit/Controller/Adminhtml/Product/Attribute/ValidateTest.php

Lines changed: 49 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
use Magento\Framework\ObjectManagerInterface;
1616
use Magento\Framework\View\LayoutFactory;
1717
use Magento\Framework\View\LayoutInterface;
18-
use Magento\Framework\DataObject;
1918

2019
/**
2120
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
@@ -62,24 +61,20 @@ class ValidateTest extends AttributeTest
6261
*/
6362
protected $layoutMock;
6463

65-
/**
66-
* @var DataObject
67-
*/
68-
protected $responseDataObject;
69-
7064
protected function setUp()
7165
{
7266
parent::setUp();
7367
$this->resultJsonFactoryMock = $this->getMockBuilder(ResultJsonFactory::class)
7468
->disableOriginalConstructor()
75-
->setMethods(['create'])
7669
->getMock();
7770
$this->resultJson = $this->getMockBuilder(ResultJson::class)
7871
->disableOriginalConstructor()
7972
->getMock();
8073
$this->layoutFactoryMock = $this->getMockBuilder(LayoutFactory::class)
8174
->disableOriginalConstructor()
8275
->getMock();
76+
$this->objectManagerMock = $this->getMockBuilder(ObjectManagerInterface::class)
77+
->getMockForAbstractClass();
8378
$this->attributeMock = $this->getMockBuilder(Attribute::class)
8479
->disableOriginalConstructor()
8580
->getMock();
@@ -91,9 +86,10 @@ protected function setUp()
9186
->getMock();
9287
$this->layoutMock = $this->getMockBuilder(LayoutInterface::class)
9388
->getMockForAbstractClass();
94-
$this->responseDataObject = $this->getMockBuilder(DataObject::class)
95-
->setMethods(null)
96-
->getMock();
89+
90+
$this->contextMock->expects($this->any())
91+
->method('getObjectManager')
92+
->willReturn($this->objectManagerMock);
9793
}
9894

9995
/**
@@ -104,17 +100,13 @@ protected function getModel()
104100
return $this->objectManager->getObject(
105101
Validate::class,
106102
[
107-
'context' => $this->contextMock,
108-
'attributeLabelCache' => $this->attributeLabelCacheMock,
109-
'coreRegistry' => $this->coreRegistryMock,
110-
'resultPageFactory' => $this->resultPageFactoryMock,
111-
'resultJsonFactory' => $this->resultJsonFactoryMock,
112-
'layoutFactory' => $this->layoutFactoryMock,
113-
'multipleAttributeList' => ['select' => 'option', 'multipleselect' => 'option'],
114-
'attributeResource' => $this->attributeMock,
115-
'attributeSetResource' => $this->attributeSetMock,
116-
'escaper' => $this->escaperMock,
117-
'responseObject' => $this->responseDataObject,
103+
'context' => $this->contextMock,
104+
'attributeLabelCache' => $this->attributeLabelCacheMock,
105+
'coreRegistry' => $this->coreRegistryMock,
106+
'resultPageFactory' => $this->resultPageFactoryMock,
107+
'resultJsonFactory' => $this->resultJsonFactoryMock,
108+
'layoutFactory' => $this->layoutFactoryMock,
109+
'multipleAttributeList' => ['select' => 'option']
118110
]
119111
);
120112
}
@@ -128,9 +120,22 @@ public function testExecute()
128120
['attribute_code', null, 'test_attribute_code'],
129121
['new_attribute_set_name', null, 'test_attribute_set_name'],
130122
]);
123+
$this->objectManagerMock->expects($this->exactly(2))
124+
->method('create')
125+
->willReturnMap([
126+
[\Magento\Catalog\Model\ResourceModel\Eav\Attribute::class, [], $this->attributeMock],
127+
[\Magento\Eav\Model\Entity\Attribute\Set::class, [], $this->attributeSetMock]
128+
]);
131129
$this->attributeMock->expects($this->once())
132130
->method('loadByCode')
133131
->willReturnSelf();
132+
$this->requestMock->expects($this->once())
133+
->method('has')
134+
->with('new_attribute_set_name')
135+
->willReturn(true);
136+
$this->attributeSetMock->expects($this->once())
137+
->method('setEntityTypeId')
138+
->willReturnSelf();
134139
$this->attributeSetMock->expects($this->once())
135140
->method('load')
136141
->willReturnSelf();
@@ -150,11 +155,13 @@ public function testExecute()
150155
/**
151156
* @dataProvider provideUniqueData
152157
* @param array $options
158+
* @param boolean $isError
153159
* @throws \Magento\Framework\Exception\NotFoundException
154160
*/
155-
public function testUniqueValidation(array $options)
161+
public function testUniqueValidation(array $options, $isError)
156162
{
157-
$this->requestMock->expects($this->any())
163+
$countFunctionCalls = ($isError) ? 6 : 5;
164+
$this->requestMock->expects($this->exactly($countFunctionCalls))
158165
->method('getParam')
159166
->willReturnMap([
160167
['frontend_label', null, null],
@@ -164,10 +171,19 @@ public function testUniqueValidation(array $options)
164171
['message_key', null, Validate::DEFAULT_MESSAGE_KEY]
165172
]);
166173

174+
$this->objectManagerMock->expects($this->once())
175+
->method('create')
176+
->willReturn($this->attributeMock);
177+
167178
$this->attributeMock->expects($this->once())
168179
->method('loadByCode')
169180
->willReturnSelf();
170181

182+
$this->requestMock->expects($this->once())
183+
->method('has')
184+
->with('new_attribute_set_name')
185+
->willReturn(false);
186+
171187
$this->resultJsonFactoryMock->expects($this->once())
172188
->method('create')
173189
->willReturn($this->resultJson);
@@ -189,7 +205,7 @@ public function provideUniqueData()
189205
"option_1" => "",
190206
"option_2" => "",
191207
]
192-
]
208+
], false
193209
],
194210
'valid options' => [
195211
[
@@ -203,7 +219,7 @@ public function provideUniqueData()
203219
"option_1" => "",
204220
"option_2" => "",
205221
]
206-
]
222+
], false
207223
],
208224
'duplicate options' => [
209225
[
@@ -217,7 +233,7 @@ public function provideUniqueData()
217233
"option_1" => "",
218234
"option_2" => "",
219235
]
220-
]
236+
], true
221237
],
222238
'duplicate and deleted' => [
223239
[
@@ -231,7 +247,7 @@ public function provideUniqueData()
231247
"option_1" => "1",
232248
"option_2" => "",
233249
]
234-
]
250+
], false
235251
],
236252
];
237253
}
@@ -253,9 +269,13 @@ public function testEmptyOption(array $options, $result)
253269
['attribute_code', null, "test_attribute_code"],
254270
['new_attribute_set_name', null, 'test_attribute_set_name'],
255271
['option', null, $options],
256-
[Validate::ARRAY_MESSAGE_KEY, Validate::DEFAULT_MESSAGE_KEY, Validate::DEFAULT_MESSAGE_KEY]
272+
['message_key', Validate::DEFAULT_MESSAGE_KEY, 'message'],
257273
]);
258274

275+
$this->objectManagerMock->expects($this->once())
276+
->method('create')
277+
->willReturn($this->attributeMock);
278+
259279
$this->attributeMock->expects($this->once())
260280
->method('loadByCode')
261281
->willReturnSelf();
@@ -289,9 +309,7 @@ public function provideEmptyOption()
289309
],
290310
(object) [
291311
'error' => true,
292-
'message' => [
293-
'The value of Admin scope can\'t be empty.'
294-
]
312+
'message' => 'The value of Admin scope can\'t be empty.',
295313
]
296314
],
297315
'not empty admin scope options' => [

0 commit comments

Comments
 (0)