@@ -29,6 +29,21 @@ class BundleTest extends \PHPUnit_Framework_TestCase
29
29
*/
30
30
protected $ subjectMock ;
31
31
32
+ /**
33
+ * @var array
34
+ */
35
+ protected $ bundleSelections ;
36
+
37
+ /**
38
+ * @var array
39
+ */
40
+ protected $ bundleOptionsRaw ;
41
+
42
+ /**
43
+ * @var array
44
+ */
45
+ protected $ bundleOptionsCleaned ;
46
+
32
47
protected function setUp ()
33
48
{
34
49
$ this ->requestMock = $ this ->getMock ('Magento\Framework\App\Request\Http ' , [], [], '' , false );
@@ -74,21 +89,35 @@ protected function setUp()
74
89
$ storeManager ,
75
90
$ customOptionFactory
76
91
);
92
+
93
+ $ this ->bundleSelections = [
94
+ ['postValue ' ],
95
+ ];
96
+ $ this ->bundleOptionsRaw = [
97
+ 'bundle_options ' => [
98
+ [
99
+ 'title ' => 'Test Option ' ,
100
+ 'bundle_selections ' => $ this ->bundleSelections ,
101
+ ],
102
+ ],
103
+ ];
104
+ $ this ->bundleOptionsCleaned = $ this ->bundleOptionsRaw ['bundle_options ' ];
105
+ unset($ this ->bundleOptionsCleaned [0 ]['bundle_selections ' ]);
77
106
}
78
107
79
108
public function testAfterInitializeIfBundleAnsCustomOptionsAndBundleSelectionsExist ()
80
109
{
81
110
$ productOptionsBefore = [0 => ['key ' => 'value ' ], 1 => ['is_delete ' => false ]];
82
- $ postValue = 'postValue ' ;
83
111
$ valueMap = [
84
- ['bundle_options ' , null , $ postValue ],
85
- ['bundle_selections ' , null , $ postValue ],
112
+ ['bundle_options ' , null , $ this ->bundleOptionsRaw ],
86
113
['affect_bundle_product_selections ' , null , 1 ],
87
114
];
88
115
$ this ->requestMock ->expects ($ this ->any ())->method ('getPost ' )->will ($ this ->returnValueMap ($ valueMap ));
89
116
$ this ->productMock ->expects ($ this ->any ())->method ('getCompositeReadonly ' )->will ($ this ->returnValue (false ));
90
- $ this ->productMock ->expects ($ this ->once ())->method ('setBundleOptionsData ' )->with ($ postValue );
91
- $ this ->productMock ->expects ($ this ->once ())->method ('setBundleSelectionsData ' )->with ($ postValue );
117
+ $ this ->productMock ->expects ($ this ->once ())
118
+ ->method ('setBundleOptionsData ' )
119
+ ->with ($ this ->bundleOptionsCleaned );
120
+ $ this ->productMock ->expects ($ this ->once ())->method ('setBundleSelectionsData ' )->with ([$ this ->bundleSelections ]);
92
121
$ this ->productMock ->expects ($ this ->once ())->method ('getPriceType ' )->will ($ this ->returnValue (0 ));
93
122
$ this ->productMock ->expects ($ this ->any ())->method ('getOptionsReadonly ' )->will ($ this ->returnValue (false ));
94
123
$ this ->productMock ->expects ($ this ->once ())->method ('setCanSaveCustomOptions ' )->with (true );
@@ -106,40 +135,21 @@ public function testAfterInitializeIfBundleAnsCustomOptionsAndBundleSelectionsEx
106
135
107
136
public function testAfterInitializeIfBundleSelectionsAndCustomOptionsExist ()
108
137
{
109
- $ postValue = 'postValue ' ;
138
+ $ bundleOptionsRawWithoutSelections = $ this ->bundleOptionsRaw ;
139
+ $ bundleOptionsRawWithoutSelections ['bundle_options ' ][0 ]['bundle_selections ' ] = false ;
110
140
$ valueMap = [
111
- ['bundle_options ' , null , $ postValue ],
112
- ['bundle_selections ' , null , false ],
141
+ ['bundle_options ' , null , $ bundleOptionsRawWithoutSelections ],
113
142
['affect_bundle_product_selections ' , null , false ],
114
143
];
115
144
$ this ->requestMock ->expects ($ this ->any ())->method ('getPost ' )->will ($ this ->returnValueMap ($ valueMap ));
116
145
$ this ->productMock ->expects ($ this ->any ())->method ('getCompositeReadonly ' )->will ($ this ->returnValue (false ));
117
- $ this ->productMock ->expects ($ this ->once ())->method ('setBundleOptionsData ' )->with ($ postValue );
146
+ $ this ->productMock ->expects ($ this ->never ())
147
+ ->method ('setBundleOptionsData ' )
148
+ ->with ($ this ->bundleOptionsCleaned );
118
149
$ this ->productMock ->expects ($ this ->never ())->method ('setBundleSelectionsData ' );
119
150
$ this ->productMock ->expects ($ this ->once ())->method ('getPriceType ' )->will ($ this ->returnValue (2 ));
120
151
$ this ->productMock ->expects ($ this ->any ())->method ('getOptionsReadonly ' )->will ($ this ->returnValue (true ));
121
152
$ this ->productMock ->expects ($ this ->once ())->method ('setCanSaveBundleSelections ' )->with (false );
122
153
$ this ->model ->afterInitialize ($ this ->subjectMock , $ this ->productMock );
123
154
}
124
-
125
- public function testAfterInitializeIfCustomAndBundleOptionNotExist ()
126
- {
127
- $ postValue = 'postValue ' ;
128
- $ valueMap = [
129
- ['bundle_options ' , null , false ],
130
- ['bundle_selections ' , null , $ postValue ],
131
- ['affect_bundle_product_selections ' , null , 1 ],
132
- ];
133
- $ this ->requestMock ->expects ($ this ->any ())->method ('getPost ' )->will ($ this ->returnValueMap ($ valueMap ));
134
- $ this ->productMock ->expects ($ this ->any ())->method ('getCompositeReadonly ' )->will ($ this ->returnValue (false ));
135
- $ this ->productMock ->expects ($ this ->never ())->method ('setBundleOptionsData ' );
136
- $ this ->productMock ->expects ($ this ->once ())->method ('setBundleSelectionsData ' )->with ($ postValue );
137
- $ this ->productMock ->expects ($ this ->once ())->method ('getPriceType ' )->will ($ this ->returnValue (0 ));
138
- $ this ->productMock ->expects ($ this ->any ())->method ('getOptionsReadonly ' )->will ($ this ->returnValue (false ));
139
- $ this ->productMock ->expects ($ this ->once ())->method ('setCanSaveCustomOptions ' )->with (true );
140
- $ this ->productMock ->expects ($ this ->once ())->method ('getProductOptions ' )->will ($ this ->returnValue (false ));
141
- $ this ->productMock ->expects ($ this ->never ())->method ('setProductOptions ' );
142
- $ this ->productMock ->expects ($ this ->once ())->method ('setCanSaveBundleSelections ' )->with (true );
143
- $ this ->model ->afterInitialize ($ this ->subjectMock , $ this ->productMock );
144
- }
145
155
}
0 commit comments