Skip to content

Commit 46b8795

Browse files
committed
Merge remote-tracking branch 'chaika/MC-20112' into Chaika-PR-2019-09-20
2 parents db570ab + 5b01902 commit 46b8795

File tree

2 files changed

+56
-22
lines changed

2 files changed

+56
-22
lines changed

app/code/Magento/CatalogImportExport/Model/Import/Product/Type/AbstractType.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
/**
1414
* Import entity abstract product type model
1515
*
16+
* phpcs:disable Magento2.Classes.AbstractApi
1617
* @api
1718
*
1819
* @SuppressWarnings(PHPMD.TooManyFields)
@@ -543,7 +544,7 @@ public function prepareAttributesWithDefaultValueForSave(array $rowData, $withDe
543544
} else {
544545
$resultAttrs[$attrCode] = $rowData[$attrCode];
545546
}
546-
} elseif (array_key_exists($attrCode, $rowData) && empty($rowData['_store'])) {
547+
} elseif (array_key_exists($attrCode, $rowData)) {
547548
$resultAttrs[$attrCode] = $rowData[$attrCode];
548549
} elseif ($withDefaultValue && null !== $attrParams['default_value'] && empty($rowData['_store'])) {
549550
$resultAttrs[$attrCode] = $attrParams['default_value'];

app/code/Magento/CatalogImportExport/Test/Unit/Model/Import/Product/Type/AbstractTypeTest.php

Lines changed: 54 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,9 @@ protected function setUp()
7272
'setAttributeSetFilter'
7373
]
7474
);
75-
$attribute = $this->createPartialMock(\Magento\Eav\Model\Entity\Attribute::class, [
75+
$attribute = $this->createPartialMock(
76+
\Magento\Eav\Model\Entity\Attribute::class,
77+
[
7678
'getAttributeCode',
7779
'getId',
7880
'getIsVisible',
@@ -85,7 +87,8 @@ protected function setUp()
8587
'getDefaultValue',
8688
'usesSource',
8789
'getFrontendInput',
88-
]);
90+
]
91+
);
8992
$attribute->expects($this->any())->method('getIsVisible')->willReturn(true);
9093
$attribute->expects($this->any())->method('getIsGlobal')->willReturn(true);
9194
$attribute->expects($this->any())->method('getIsRequired')->willReturn(true);
@@ -107,6 +110,7 @@ protected function setUp()
107110
];
108111
$attribute1 = clone $attribute;
109112
$attribute2 = clone $attribute;
113+
$attribute3 = clone $attribute;
110114

111115
$attribute1->expects($this->any())->method('getId')->willReturn('1');
112116
$attribute1->expects($this->any())->method('getAttributeCode')->willReturn('attr_code');
@@ -118,6 +122,11 @@ protected function setUp()
118122
$attribute2->expects($this->any())->method('getFrontendInput')->willReturn('boolean');
119123
$attribute2->expects($this->any())->method('isStatic')->willReturn(false);
120124

125+
$attribute3->expects($this->any())->method('getId')->willReturn('3');
126+
$attribute3->expects($this->any())->method('getAttributeCode')->willReturn('text_attribute');
127+
$attribute3->expects($this->any())->method('getFrontendInput')->willReturn('text');
128+
$attribute3->expects($this->any())->method('isStatic')->willReturn(false);
129+
121130
$this->entityModel->expects($this->any())->method('getEntityTypeId')->willReturn(3);
122131
$this->entityModel->expects($this->any())->method('getAttributeOptions')->willReturnOnConsecutiveCalls(
123132
['option1', 'option2'],
@@ -126,7 +135,9 @@ protected function setUp()
126135
$attrSetColFactory->expects($this->any())->method('create')->willReturn($attrSetCollection);
127136
$attrSetCollection->expects($this->any())->method('setEntityTypeFilter')->willReturn([$attributeSet]);
128137
$attrColFactory->expects($this->any())->method('create')->willReturn($attrCollection);
129-
$attrCollection->expects($this->any())->method('setAttributeSetFilter')->willReturn([$attribute1, $attribute2]);
138+
$attrCollection->expects($this->any())
139+
->method('setAttributeSetFilter')
140+
->willReturn([$attribute1, $attribute2, $attribute3]);
130141
$attributeSet->expects($this->any())->method('getId')->willReturn(1);
131142
$attributeSet->expects($this->any())->method('getAttributeSetName')->willReturn('attribute_set_name');
132143

@@ -157,23 +168,29 @@ protected function setUp()
157168
],
158169
]
159170
)
160-
->willReturn([$attribute1, $attribute2]);
171+
->willReturn([$attribute1, $attribute2, $attribute3]);
161172

162-
$this->connection = $this->createPartialMock(\Magento\Framework\DB\Adapter\Pdo\Mysql::class, [
173+
$this->connection = $this->createPartialMock(
174+
\Magento\Framework\DB\Adapter\Pdo\Mysql::class,
175+
[
163176
'select',
164177
'fetchAll',
165178
'fetchPairs',
166179
'joinLeft',
167180
'insertOnDuplicate',
168181
'delete',
169182
'quoteInto'
170-
]);
171-
$this->select = $this->createPartialMock(\Magento\Framework\DB\Select::class, [
183+
]
184+
);
185+
$this->select = $this->createPartialMock(
186+
\Magento\Framework\DB\Select::class,
187+
[
172188
'from',
173189
'where',
174190
'joinLeft',
175191
'getConnection',
176-
]);
192+
]
193+
);
177194
$this->select->expects($this->any())->method('from')->will($this->returnSelf());
178195
$this->select->expects($this->any())->method('where')->will($this->returnSelf());
179196
$this->select->expects($this->any())->method('joinLeft')->will($this->returnSelf());
@@ -189,10 +206,13 @@ protected function setUp()
189206
->method('fetchAll')
190207
->will($this->returnValue($entityAttributes));
191208

192-
$this->resource = $this->createPartialMock(\Magento\Framework\App\ResourceConnection::class, [
209+
$this->resource = $this->createPartialMock(
210+
\Magento\Framework\App\ResourceConnection::class,
211+
[
193212
'getConnection',
194213
'getTableName',
195-
]);
214+
]
215+
);
196216
$this->resource->expects($this->any())->method('getConnection')->will(
197217
$this->returnValue($this->connection)
198218
);
@@ -257,9 +277,13 @@ public function testIsRowValidSuccess()
257277
$rowNum = 1;
258278
$this->entityModel->expects($this->any())->method('getRowScope')->willReturn(null);
259279
$this->entityModel->expects($this->never())->method('addRowError');
260-
$this->setPropertyValue($this->simpleType, '_attributes', [
261-
$rowData[\Magento\CatalogImportExport\Model\Import\Product::COL_ATTR_SET] => [],
262-
]);
280+
$this->setPropertyValue(
281+
$this->simpleType,
282+
'_attributes',
283+
[
284+
$rowData[\Magento\CatalogImportExport\Model\Import\Product::COL_ATTR_SET] => [],
285+
]
286+
);
263287
$this->assertTrue($this->simpleType->isRowValid($rowData, $rowNum));
264288
}
265289

@@ -278,13 +302,17 @@ public function testIsRowValidError()
278302
'attr_code'
279303
)
280304
->willReturnSelf();
281-
$this->setPropertyValue($this->simpleType, '_attributes', [
282-
$rowData[\Magento\CatalogImportExport\Model\Import\Product::COL_ATTR_SET] => [
283-
'attr_code' => [
284-
'is_required' => true,
305+
$this->setPropertyValue(
306+
$this->simpleType,
307+
'_attributes',
308+
[
309+
$rowData[\Magento\CatalogImportExport\Model\Import\Product::COL_ATTR_SET] => [
310+
'attr_code' => [
311+
'is_required' => true,
312+
],
285313
],
286-
],
287-
]);
314+
]
315+
);
288316

289317
$this->assertFalse($this->simpleType->isRowValid($rowData, $rowNum));
290318
}
@@ -364,9 +392,14 @@ public function testPrepareAttributesWithDefaultValueForSave()
364392
{
365393
$rowData = [
366394
'_attribute_set' => 'attributeSetName',
367-
'boolean_attribute' => 'Yes'
395+
'boolean_attribute' => 'Yes',
396+
];
397+
398+
$expected = [
399+
'boolean_attribute' => 1,
400+
'text_attribute' => 'default_value'
368401
];
369402
$result = $this->simpleType->prepareAttributesWithDefaultValueForSave($rowData);
370-
$this->assertEquals(['boolean_attribute' => 1], $result);
403+
$this->assertEquals($expected, $result);
371404
}
372405
}

0 commit comments

Comments
 (0)