Skip to content

Commit b9990ce

Browse files
committed
Merge remote-tracking branch 'nord/MAGETWO-37499' into MAGETWO-37718
2 parents 9ff93e3 + da51655 commit b9990ce

File tree

3 files changed

+152
-1
lines changed

3 files changed

+152
-1
lines changed

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1682,6 +1682,7 @@ protected function _saveValidatedBunches()
16821682
}
16831683
$rowData = $source->current();
16841684
$this->validateRow($rowData, $source->key());
1685+
$this->_processedRowsCount++;
16851686
$source->next();
16861687
}
16871688
$this->getOptionEntity()->validateAmbiguousData();

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -270,7 +270,7 @@ public function isRowValid(array $rowData, $rowNum, $isNewProduct = true)
270270
))
271271
) {
272272
$this->_entityModel->addRowError(
273-
\Magento\CatalogImportExport\Model\Import\Product::ERROR_VALUE_IS_REQUIRED,
273+
\Magento\CatalogImportExport\Model\Import\Product\RowValidatorInterface::ERROR_VALUE_IS_REQUIRED,
274274
$rowNum,
275275
$attrCode
276276
);
Lines changed: 150 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,150 @@
1+
<?php
2+
/**
3+
* Copyright © 2015 Magento. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
namespace Magento\CatalogImportExport\Test\Unit\Model\Import\Product\Type;
7+
8+
use Magento\Framework\TestFramework\Unit\Helper\ObjectManager as ObjectManagerHelper;
9+
10+
/**
11+
* Test class for import product AbstractType class
12+
*/
13+
class AbstractTypeTest extends \PHPUnit_Framework_TestCase
14+
{
15+
/**
16+
* @var \Magento\CatalogImportExport\Model\Import\Product|\PHPUnit_Framework_MockObject_MockObject
17+
*/
18+
protected $entityModel;
19+
20+
/**
21+
* @var \Magento\CatalogImportExport\Model\Import\Product\Type\Simple
22+
*/
23+
protected $simpleType;
24+
25+
/**
26+
* @var ObjectManagerHelper
27+
*/
28+
protected $objectManagerHelper;
29+
30+
protected function setUp()
31+
{
32+
$this->entityModel = $this->getMock(
33+
'\Magento\CatalogImportExport\Model\Import\Product',
34+
[],
35+
[],
36+
'',
37+
false
38+
);
39+
$attrSetColFactory = $this->getMock(
40+
'\Magento\Eav\Model\Resource\Entity\Attribute\Set\CollectionFactory',
41+
[],
42+
[],
43+
'',
44+
false
45+
);
46+
$attrSetCollection = $this->getMock(
47+
'\Magento\Eav\Model\Resource\Entity\Attribute\Set\Collection',
48+
[],
49+
[],
50+
'',
51+
false
52+
);
53+
$attrColFactory = $this->getMock(
54+
'\Magento\Catalog\Model\Resource\Product\Attribute\CollectionFactory',
55+
[],
56+
[],
57+
'',
58+
false
59+
);
60+
$attributeSet = $this->getMock(
61+
'\Magento\Eav\Model\Entity\Attribute\Set',
62+
[],
63+
[],
64+
'',
65+
false
66+
);
67+
$attrCollection = $this->getMock(
68+
'\Magento\Eav\Model\Resource\Entity\Attribute\Collection',
69+
[],
70+
[],
71+
'',
72+
false
73+
);
74+
$attribute = $this->getMock(
75+
'\Magento\Eav\Model\Entity\Attribute',
76+
[
77+
'getAttributeCode',
78+
'getId',
79+
'getIsVisible',
80+
'getIsGlobal',
81+
'getIsRequired',
82+
'getIsUnique',
83+
'getFrontendLabel',
84+
'isStatic',
85+
'getApplyTo',
86+
'getDefaultValue',
87+
'usesSource',
88+
'getFrontendInput'
89+
],
90+
[],
91+
'',
92+
false
93+
);
94+
95+
$this->entityModel->expects($this->any())->method('getEntityTypeId')->willReturn(3);
96+
$this->entityModel->expects($this->any())->method('getAttributeOptions')->willReturn(['option1', 'option2']);
97+
$attrSetColFactory->expects($this->any())->method('create')->willReturn($attrSetCollection);
98+
$attrSetCollection->expects($this->any())->method('setEntityTypeFilter')->willReturn([$attributeSet]);
99+
$attrColFactory->expects($this->any())->method('create')->willReturn($attrCollection);
100+
$attrCollection->expects($this->any())->method('setAttributeSetFilter')->willReturn([$attribute]);
101+
$attributeSet->expects($this->any())->method('getId')->willReturn(1);
102+
$attributeSet->expects($this->any())->method('getAttributeSetName')->willReturn('attribute_set_name');
103+
$attribute->expects($this->any())->method('getAttributeCode')->willReturn('attr_code');
104+
$attribute->expects($this->any())->method('getId')->willReturn('1');
105+
$attribute->expects($this->any())->method('getIsVisible')->willReturn(true);
106+
$attribute->expects($this->any())->method('getIsGlobal')->willReturn(true);
107+
$attribute->expects($this->any())->method('getIsRequired')->willReturn(true);
108+
$attribute->expects($this->any())->method('getIsUnique')->willReturn(true);
109+
$attribute->expects($this->any())->method('getFrontendLabel')->willReturn('frontend_label');
110+
$attribute->expects($this->any())->method('isStatic')->willReturn(true);
111+
$attribute->expects($this->any())->method('getApplyTo')->willReturn(['simple']);
112+
$attribute->expects($this->any())->method('getDefaultValue')->willReturn('default_value');
113+
$attribute->expects($this->any())->method('usesSource')->willReturn(true);
114+
$attribute->expects($this->any())->method('getFrontendInput')->willReturn('multiselect');
115+
116+
$this->objectManagerHelper = new ObjectManagerHelper($this);
117+
$this->simpleType = $this->objectManagerHelper->getObject(
118+
'Magento\CatalogImportExport\Model\Import\Product\Type\Simple',
119+
[
120+
'attrSetColFac' => $attrSetColFactory,
121+
'prodAttrColFac' => $attrColFactory,
122+
'params' => [$this->entityModel, 'simple']
123+
]
124+
);
125+
}
126+
127+
public function testIsRowValidSuccess()
128+
{
129+
$rowData = ['_attribute_set' => 'attribute_set_name'];
130+
$rowNum = 1;
131+
$this->entityModel->expects($this->any())->method('getRowScope')->willReturn(null);
132+
$this->entityModel->expects($this->never())->method('addRowError');
133+
$this->assertTrue($this->simpleType->isRowValid($rowData, $rowNum));
134+
}
135+
136+
public function testIsRowValidError()
137+
{
138+
$rowData = ['_attribute_set' => 'attribute_set_name'];
139+
$rowNum = 1;
140+
$this->entityModel->expects($this->any())->method('getRowScope')->willReturn(1);
141+
$this->entityModel->expects($this->once())->method('addRowError')
142+
->with(
143+
\Magento\CatalogImportExport\Model\Import\Product\RowValidatorInterface::ERROR_VALUE_IS_REQUIRED,
144+
1,
145+
'attr_code'
146+
)
147+
->willReturnSelf();
148+
$this->assertFalse($this->simpleType->isRowValid($rowData, $rowNum));
149+
}
150+
}

0 commit comments

Comments
 (0)