6
6
*/
7
7
namespace Magento \GroupedProduct \Test \Unit \Model \Product \Initialization \Helper \ProductLinks \Plugin ;
8
8
9
+ use Magento \GroupedProduct \Model \Product \Type \Grouped ;
10
+ use Magento \Catalog \Model \Product \Type ;
9
11
10
12
class GroupedTest extends \PHPUnit_Framework_TestCase
11
13
{
@@ -15,20 +17,20 @@ class GroupedTest extends \PHPUnit_Framework_TestCase
15
17
protected $ model ;
16
18
17
19
/**
18
- * @var \PHPUnit_Framework_MockObject_MockObject
20
+ * @var \Magento\Catalog\Model\Product|\ PHPUnit_Framework_MockObject_MockObject
19
21
*/
20
22
protected $ productMock ;
21
23
22
24
/**
23
- * @var \PHPUnit_Framework_MockObject_MockObject
25
+ * @var \Magento\Catalog\Model\Product\Initialization\Helper\ProductLinks|\ PHPUnit_Framework_MockObject_MockObject
24
26
*/
25
27
protected $ subjectMock ;
26
28
27
29
protected function setUp ()
28
30
{
29
31
$ this ->productMock = $ this ->getMock (
30
32
'Magento\Catalog\Model\Product ' ,
31
- ['getGroupedReadonly ' , 'setGroupedLinkData ' , '__wakeup ' ],
33
+ ['getGroupedReadonly ' , 'setGroupedLinkData ' , '__wakeup ' , ' getTypeId ' ],
32
34
[],
33
35
'' ,
34
36
false
@@ -43,22 +45,49 @@ protected function setUp()
43
45
$ this ->model = new \Magento \GroupedProduct \Model \Product \Initialization \Helper \ProductLinks \Plugin \Grouped ();
44
46
}
45
47
46
- public function testBeforeInitializeLinksRequestDoesNotHaveGrouped ()
48
+ /**
49
+ * @dataProvider productTypeDataProvider
50
+ */
51
+ public function testBeforeInitializeLinksRequestDoesNotHaveGrouped ($ productType )
47
52
{
53
+ $ this ->productMock ->expects ($ this ->once ())->method ('getTypeId ' )->will ($ this ->returnValue ($ productType ));
48
54
$ this ->productMock ->expects ($ this ->never ())->method ('getGroupedReadonly ' );
49
55
$ this ->productMock ->expects ($ this ->never ())->method ('setGroupedLinkData ' );
50
56
$ this ->model ->beforeInitializeLinks ($ this ->subjectMock , $ this ->productMock , []);
51
57
}
52
58
53
- public function testBeforeInitializeLinksRequestHasGrouped ()
59
+ public function productTypeDataProvider ()
54
60
{
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 ));
55
74
$ 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
+ ];
58
86
}
59
87
60
88
public function testBeforeInitializeLinksProductIsReadonly ()
61
89
{
90
+ $ this ->productMock ->expects ($ this ->once ())->method ('getTypeId ' )->will ($ this ->returnValue (Grouped::TYPE_CODE ));
62
91
$ this ->productMock ->expects ($ this ->once ())->method ('getGroupedReadonly ' )->will ($ this ->returnValue (true ));
63
92
$ this ->productMock ->expects ($ this ->never ())->method ('setGroupedLinkData ' );
64
93
$ this ->model ->beforeInitializeLinks ($ this ->subjectMock , $ this ->productMock , ['associated ' => 'value ' ]);
0 commit comments