Skip to content

Commit 30517b5

Browse files
author
Andrii Kasian
committed
Merge branch 'MAGETWO-29334' into S69
2 parents d6d4a1d + 18d0985 commit 30517b5

File tree

2 files changed

+41
-9
lines changed
  • app/code/Magento/GroupedProduct
    • Model/Product/Initialization/Helper/ProductLinks/Plugin
    • Test/Unit/Model/Product/Initialization/Helper/ProductLinks/Plugin

2 files changed

+41
-9
lines changed

app/code/Magento/GroupedProduct/Model/Product/Initialization/Helper/ProductLinks/Plugin/Grouped.php

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
*/
66
namespace Magento\GroupedProduct\Model\Product\Initialization\Helper\ProductLinks\Plugin;
77

8+
use Magento\GroupedProduct\Model\Product\Type\Grouped as TypeGrouped;
9+
810
class Grouped
911
{
1012
/**
@@ -22,8 +24,9 @@ public function beforeInitializeLinks(
2224
\Magento\Catalog\Model\Product $product,
2325
array $links
2426
) {
25-
if (isset($links['associated']) && !$product->getGroupedReadonly()) {
26-
$product->setGroupedLinkData((array)$links['associated']);
27+
if ($product->getTypeId() == TypeGrouped::TYPE_CODE && !$product->getGroupedReadonly()) {
28+
$links = isset($links['associated']) ? $links['associated'] : [];
29+
$product->setGroupedLinkData($links);
2730
}
2831
}
2932
}

app/code/Magento/GroupedProduct/Test/Unit/Model/Product/Initialization/Helper/ProductLinks/Plugin/GroupedTest.php

Lines changed: 36 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
*/
77
namespace Magento\GroupedProduct\Test\Unit\Model\Product\Initialization\Helper\ProductLinks\Plugin;
88

9+
use Magento\GroupedProduct\Model\Product\Type\Grouped;
10+
use Magento\Catalog\Model\Product\Type;
911

1012
class GroupedTest extends \PHPUnit_Framework_TestCase
1113
{
@@ -15,20 +17,20 @@ class GroupedTest extends \PHPUnit_Framework_TestCase
1517
protected $model;
1618

1719
/**
18-
* @var \PHPUnit_Framework_MockObject_MockObject
20+
* @var \Magento\Catalog\Model\Product|\PHPUnit_Framework_MockObject_MockObject
1921
*/
2022
protected $productMock;
2123

2224
/**
23-
* @var \PHPUnit_Framework_MockObject_MockObject
25+
* @var \Magento\Catalog\Model\Product\Initialization\Helper\ProductLinks|\PHPUnit_Framework_MockObject_MockObject
2426
*/
2527
protected $subjectMock;
2628

2729
protected function setUp()
2830
{
2931
$this->productMock = $this->getMock(
3032
'Magento\Catalog\Model\Product',
31-
['getGroupedReadonly', 'setGroupedLinkData', '__wakeup'],
33+
['getGroupedReadonly', 'setGroupedLinkData', '__wakeup', 'getTypeId'],
3234
[],
3335
'',
3436
false
@@ -43,22 +45,49 @@ protected function setUp()
4345
$this->model = new \Magento\GroupedProduct\Model\Product\Initialization\Helper\ProductLinks\Plugin\Grouped();
4446
}
4547

46-
public function testBeforeInitializeLinksRequestDoesNotHaveGrouped()
48+
/**
49+
* @dataProvider productTypeDataProvider
50+
*/
51+
public function testBeforeInitializeLinksRequestDoesNotHaveGrouped($productType)
4752
{
53+
$this->productMock->expects($this->once())->method('getTypeId')->will($this->returnValue($productType));
4854
$this->productMock->expects($this->never())->method('getGroupedReadonly');
4955
$this->productMock->expects($this->never())->method('setGroupedLinkData');
5056
$this->model->beforeInitializeLinks($this->subjectMock, $this->productMock, []);
5157
}
5258

53-
public function testBeforeInitializeLinksRequestHasGrouped()
59+
public function productTypeDataProvider()
5460
{
61+
return [
62+
[Type::TYPE_SIMPLE],
63+
[Type::TYPE_BUNDLE],
64+
[Type::TYPE_VIRTUAL]
65+
];
66+
}
67+
68+
/**
69+
* @dataProvider linksDataProvider
70+
*/
71+
public function testBeforeInitializeLinksRequestHasGrouped($linksData)
72+
{
73+
$this->productMock->expects($this->once())->method('getTypeId')->will($this->returnValue(Grouped::TYPE_CODE));
5574
$this->productMock->expects($this->once())->method('getGroupedReadonly')->will($this->returnValue(false));
56-
$this->productMock->expects($this->once())->method('setGroupedLinkData')->with(['value']);
57-
$this->model->beforeInitializeLinks($this->subjectMock, $this->productMock, ['associated' => 'value']);
75+
$this->productMock->expects($this->once())->method('setGroupedLinkData')->with($linksData);
76+
$this->model->beforeInitializeLinks($this->subjectMock, $this->productMock, ['associated' => $linksData]);
77+
}
78+
79+
public function linksDataProvider()
80+
{
81+
return [
82+
[['associated' => [5 => ['id' => '2', 'qty' => '100', 'position' => '1']]]],
83+
[['associated' => []]],
84+
[[]]
85+
];
5886
}
5987

6088
public function testBeforeInitializeLinksProductIsReadonly()
6189
{
90+
$this->productMock->expects($this->once())->method('getTypeId')->will($this->returnValue(Grouped::TYPE_CODE));
6291
$this->productMock->expects($this->once())->method('getGroupedReadonly')->will($this->returnValue(true));
6392
$this->productMock->expects($this->never())->method('setGroupedLinkData');
6493
$this->model->beforeInitializeLinks($this->subjectMock, $this->productMock, ['associated' => 'value']);

0 commit comments

Comments
 (0)