Skip to content

Commit a0fee45

Browse files
Merge branch 'MAGNIMEX-SPRINT2-UNIT-TESTS' into 'MAGNIMEX-SPRINT2'
Magnimex sprint2 unit tests Done tests: - app/code/Magento/CatalogImportExport/Model/Import/Product.php: getMultipleValueSeparator + - app/code/Magento/CatalogImportExport/Model/Import/Product.php: deleteProductsForReplacement + - app/code/Magento/CatalogImportExport/Model/Import/Product/Option.php: clearProductsSkuToId + - app/code/Magento/CatalogImportExport/Model/Import/Product/SkuProcessor.php: getOldSkus + reloadOldSkus + - app/code/Magento/ImportExport/Model/Import/Adapter.php: findAdapterFor -+(static) See merge request !104
2 parents 0bb90ed + 06bc8e2 commit a0fee45

File tree

4 files changed

+237
-0
lines changed

4 files changed

+237
-0
lines changed
Lines changed: 114 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,114 @@
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;
7+
8+
use Magento\CatalogImportExport\Model\Import\Product\SkuProcessor as SkuProcessor;
9+
10+
class SkuProcessorTest extends \PHPUnit_Framework_TestCase
11+
{
12+
/**
13+
* @var \Magento\Catalog\Model\ProductFactory|\PHPUnit_Framework_MockObject_MockObject
14+
*/
15+
protected $productFactory;
16+
17+
/**
18+
* @var SkuProcessor|\PHPUnit_Framework_MockObject_MockObject
19+
*/
20+
protected $skuProcessor;
21+
22+
public function setUp()
23+
{
24+
$this->productFactory = $this->getMock(
25+
'\Magento\Catalog\Model\ProductFactory',
26+
[],
27+
[],
28+
'',
29+
false
30+
);
31+
$this->skuProcessor = $this->getMock(
32+
'Magento\CatalogImportExport\Model\Import\Product\SkuProcessor',
33+
['_getSkus'],
34+
[
35+
$this->productFactory
36+
],
37+
''
38+
);
39+
}
40+
41+
public function testReloadOldSkus()
42+
{
43+
$skuValue = 'value';
44+
45+
$this->skuProcessor
46+
->expects($this->once())
47+
->method('_getSkus')
48+
->willReturn($skuValue);
49+
50+
$this->skuProcessor->reloadOldSkus();
51+
$oldSkus = $this->getPropertyValue($this->skuProcessor, 'oldSkus');
52+
53+
$this->assertEquals($skuValue, $oldSkus);
54+
}
55+
56+
public function testGetOldSkusIfNotSet()
57+
{
58+
$expectedOldSkus = 'value';
59+
$this->setPropertyValue($this->skuProcessor, 'oldSkus', null);
60+
$this->skuProcessor
61+
->expects($this->once())
62+
->method('_getSkus')
63+
->willReturn($expectedOldSkus);
64+
65+
$result = $this->skuProcessor->getOldSkus();
66+
67+
$this->assertEquals($expectedOldSkus, $result);
68+
}
69+
70+
public function testGetOldSkusIfSet()
71+
{
72+
$expectedOldSkus = 'value';
73+
$this->setPropertyValue($this->skuProcessor, 'oldSkus', 'value');
74+
$this->skuProcessor
75+
->expects($this->never())
76+
->method('_getSkus');
77+
78+
$result = $this->skuProcessor->getOldSkus();
79+
80+
$this->assertEquals($expectedOldSkus, $result);
81+
}
82+
83+
/**
84+
* Set object property.
85+
*
86+
* @param object $object
87+
* @param string $property
88+
* @param mixed $value
89+
*/
90+
protected function setPropertyValue(&$object, $property, $value)
91+
{
92+
$reflection = new \ReflectionClass(get_class($object));
93+
$reflectionProperty = $reflection->getProperty($property);
94+
$reflectionProperty->setAccessible(true);
95+
$reflectionProperty->setValue($object, $value);
96+
97+
return $object;
98+
}
99+
100+
/**
101+
* Get object property.
102+
*
103+
* @param object $object
104+
* @param string $property
105+
*/
106+
protected function getPropertyValue(&$object, $property)
107+
{
108+
$reflection = new \ReflectionClass(get_class($object));
109+
$reflectionProperty = $reflection->getProperty($property);
110+
$reflectionProperty->setAccessible(true);
111+
112+
return $reflectionProperty->getValue($object);
113+
}
114+
}

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

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -950,4 +950,47 @@ public function testParseRequiredData()
950950
);
951951
$this->assertTrue($model->importData());
952952
}
953+
954+
public function testClearProductsSkuToId()
955+
{
956+
$this->setPropertyValue($this->_modelMock, '_productsSkuToId', 'value');
957+
958+
$this->_modelMock->clearProductsSkuToId();
959+
960+
$productsSkuToId = $this->getPropertyValue($this->_modelMock, '_productsSkuToId');
961+
962+
$this->assertNull($productsSkuToId);
963+
}
964+
965+
/**
966+
* Set object property.
967+
*
968+
* @param object $object
969+
* @param string $property
970+
* @param mixed $value
971+
*/
972+
protected function setPropertyValue(&$object, $property, $value)
973+
{
974+
$reflection = new \ReflectionClass(get_class($object));
975+
$reflectionProperty = $reflection->getProperty($property);
976+
$reflectionProperty->setAccessible(true);
977+
$reflectionProperty->setValue($object, $value);
978+
979+
return $object;
980+
}
981+
982+
/**
983+
* Get object property.
984+
*
985+
* @param object $object
986+
* @param string $property
987+
*/
988+
protected function getPropertyValue(&$object, $property)
989+
{
990+
$reflection = new \ReflectionClass(get_class($object));
991+
$reflectionProperty = $reflection->getProperty($property);
992+
$reflectionProperty->setAccessible(true);
993+
994+
return $reflectionProperty->getValue($object);
995+
}
953996
}

app/code/Magento/CatalogImportExport/Test/Unit/Model/Import/ProductTest.php

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -656,6 +656,49 @@ public function testIsAttributeValidAddIntoUniqueueAttributes()
656656
$this->assertEquals($expectedSkuVal, $_uniqueAttributes[$attrCode][$rowData[$attrCode]]);
657657
}
658658

659+
public function testGetMultipleValueSeparatorDefault()
660+
{
661+
$this->setPropertyValue($this->importProduct, '_parameters', null);
662+
$this->assertEquals(
663+
\Magento\CatalogImportExport\Model\Import\Product::DEFAULT_GLOBAL_MULTI_VALUE_SEPARATOR,
664+
$this->importProduct->getMultipleValueSeparator()
665+
);
666+
}
667+
668+
public function testGetMultipleValueSeparatorFromParameters()
669+
{
670+
$expectedSeparator = 'value';
671+
$this->setPropertyValue($this->importProduct, '_parameters', [
672+
\Magento\ImportExport\Model\Import::FIELD_FIELD_MULTIPLE_VALUE_SEPARATOR => $expectedSeparator,
673+
]);
674+
675+
$this->assertEquals(
676+
$expectedSeparator,
677+
$this->importProduct->getMultipleValueSeparator()
678+
);
679+
}
680+
681+
public function testDeleteProductsForReplacement()
682+
{
683+
$importProduct = $this->getMockBuilder('\Magento\CatalogImportExport\Model\Import\Product')
684+
->disableOriginalConstructor()
685+
->setMethods([
686+
'setParameters', '_deleteProducts'
687+
])
688+
->getMock();
689+
690+
$importProduct->expects($this->once())->method('setParameters')->with(
691+
[
692+
'behavior' => \Magento\ImportExport\Model\Import::BEHAVIOR_DELETE,
693+
]
694+
);
695+
$importProduct->expects($this->once())->method('_deleteProducts');
696+
697+
$result = $importProduct->deleteProductsForReplacement();
698+
699+
$this->assertEquals($importProduct, $result);
700+
}
701+
659702
public function testGetMediaGalleryAttributeIdIfNotSetYet()
660703
{
661704
// reset possible existing id
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
<?php
2+
/**
3+
* Copyright © 2015 Magento. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
namespace Magento\ImportExport\Test\Unit\Model\Import;
7+
8+
use Magento\ImportExport\Model\Import\Adapter as Adapter;
9+
10+
class AdapterTest extends \PHPUnit_Framework_TestCase
11+
{
12+
/**
13+
* @var Adapter|\PHPUnit_Framework_MockObject_MockObject
14+
*/
15+
protected $adapter;
16+
17+
public function setUp()
18+
{
19+
$this->adapter = $this->getMock(
20+
'\Magento\ImportExport\Model\Import\Adapter',
21+
[],
22+
[],
23+
'',
24+
false
25+
);
26+
}
27+
28+
public function testFactory()
29+
{
30+
$this->markTestSkipped('Skipped because factory method has static modifier');
31+
}
32+
33+
public function testFindAdapterFor()
34+
{
35+
$this->markTestSkipped('Skipped because findAdapterFor method has static modifier');
36+
}
37+
}

0 commit comments

Comments
 (0)