Skip to content

Commit 971426c

Browse files
author
Sergey Shvets
committed
MAGETWO-73456: Product Url key value comes from product name on storeview level (use default = yes)
1 parent e716a7b commit 971426c

File tree

1 file changed

+40
-4
lines changed

1 file changed

+40
-4
lines changed

app/code/Magento/Catalog/Test/Unit/Controller/Adminhtml/Product/Initialization/Helper/AttributeFilterTest.php

Lines changed: 40 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
* Copyright © Magento, Inc. All rights reserved.
44
* See COPYING.txt for license details.
55
*/
6+
67
namespace Magento\Catalog\Test\Unit\Controller\Adminhtml\Product\Initialization\Helper;
78

89
use Magento\Catalog\Controller\Adminhtml\Product\Initialization\Helper\AttributeFilter;
@@ -44,15 +45,25 @@ public function testPrepareProductAttributes(
4445
$expectedProductData,
4546
$initialProductData
4647
) {
48+
/** @var \PHPUnit_Framework_MockObject_MockObject | Product $productMockMap */
4749
$productMockMap = $this->getMockBuilder(Product::class)
4850
->disableOriginalConstructor()
49-
->setMethods(['getData'])
51+
->setMethods(['getData', 'getAttributes'])
5052
->getMock();
5153

5254
if (!empty($initialProductData)) {
5355
$productMockMap->expects($this->any())->method('getData')->willReturnMap($initialProductData);
5456
}
5557

58+
if ($useDefaults) {
59+
$productMockMap
60+
->expects($this->once())
61+
->method('getAttributes')
62+
->willReturn(
63+
$this->getProductAttributesMock($useDefaults)
64+
);
65+
}
66+
5667
$actualProductData = $this->model->prepareProductAttributes($productMockMap, $requestProductData, $useDefaults);
5768
$this->assertEquals($expectedProductData, $actualProductData);
5869
}
@@ -169,7 +180,7 @@ public function setupInputDataProvider()
169180
'description' => 'descr modified'
170181
],
171182
'initialProductData' => [
172-
['name', null,'testName2'],
183+
['name', null, 'testName2'],
173184
['sku', null, 'testSku2'],
174185
['price', null, '101'],
175186
['description', null, 'descr text']
@@ -180,7 +191,8 @@ public function setupInputDataProvider()
180191
'name' => 'testName3',
181192
'sku' => 'testSku3',
182193
'price' => '103',
183-
'special_price' => '100'
194+
'special_price' => '100',
195+
'description' => 'descr modified',
184196
],
185197
'useDefaults' => [
186198
'description' => '1'
@@ -190,14 +202,38 @@ public function setupInputDataProvider()
190202
'sku' => 'testSku3',
191203
'price' => '103',
192204
'special_price' => '100',
205+
'description' => false
193206
],
194207
'initialProductData' => [
195-
['name', null,'testName2'],
208+
['name', null, 'testName2'],
196209
['sku', null, 'testSku2'],
197210
['price', null, '101'],
198211
['description', null, 'descr text']
199212
]
200213
],
201214
];
202215
}
216+
217+
/**
218+
* @param array $useDefaults
219+
* @return array
220+
*/
221+
private function getProductAttributesMock(array $useDefaults): array
222+
{
223+
$returnArray = [];
224+
foreach ($useDefaults as $attributecode => $isDefault) {
225+
if ($isDefault === '1') {
226+
/** @var \Magento\Catalog\Model\ResourceModel\Eav\Attribute | \PHPUnit_Framework_MockObject_MockObject $attribute */
227+
$attribute = $this->getMockBuilder(\Magento\Catalog\Model\ResourceModel\Eav\Attribute::class)
228+
->disableOriginalConstructor()
229+
->getMock();
230+
$attribute->expects($this->any())
231+
->method('getBackendType')
232+
->willReturn('varchar');
233+
234+
$returnArray[$attributecode] = $attribute;
235+
}
236+
}
237+
return $returnArray;
238+
}
203239
}

0 commit comments

Comments
 (0)