8
8
use \Magento \Catalog \Pricing \Price \CustomOptionPrice ;
9
9
10
10
use Magento \Framework \Pricing \PriceInfoInterface ;
11
+ use Magento \Catalog \Model \Product \Option \Value ;
11
12
12
13
/**
13
14
* Class OptionPriceTest
@@ -123,6 +124,46 @@ protected function setupOptions(array $optionsData)
123
124
return $ options ;
124
125
}
125
126
127
+ protected function setupSingleValueOptions ($ optionsData )
128
+ {
129
+ $ options = [];
130
+ foreach ($ optionsData as $ optionData ) {
131
+ $ optionItemMock = $ this ->getMockBuilder ('Magento\Catalog\Model\Product\Option ' )
132
+ ->disableOriginalConstructor ()
133
+ ->setMethods ([
134
+ 'getValues ' ,
135
+ '__wakeup ' ,
136
+ 'getIsRequire ' ,
137
+ 'getId ' ,
138
+ 'getType ' ,
139
+ 'getPriceType ' ,
140
+ 'getPrice ' ,
141
+ ])
142
+ ->getMock ();
143
+ $ optionItemMock ->expects ($ this ->any ())
144
+ ->method ('getId ' )
145
+ ->will ($ this ->returnValue ($ optionData ['id ' ]));
146
+ $ optionItemMock ->expects ($ this ->any ())
147
+ ->method ('getType ' )
148
+ ->will ($ this ->returnValue ($ optionData ['type ' ]));
149
+ $ optionItemMock ->expects ($ this ->any ())
150
+ ->method ('getIsRequire ' )
151
+ ->will ($ this ->returnValue ($ optionData ['is_require ' ]));
152
+ $ optionItemMock ->expects ($ this ->any ())
153
+ ->method ('getValues ' )
154
+ ->will ($ this ->returnValue (null ));
155
+ $ optionItemMock ->expects ($ this ->any ())
156
+ ->method ('getPriceType ' )
157
+ ->willReturn ($ optionData ['price_type ' ]);
158
+ $ optionItemMock ->expects ($ this ->any ())
159
+ ->method ('getPrice ' )
160
+ ->with ($ optionData ['price_type ' ] == Value::TYPE_PERCENT )
161
+ ->willReturn ($ optionData ['price ' ]);
162
+ $ options [] = $ optionItemMock ;
163
+ }
164
+ return $ options ;
165
+ }
166
+
126
167
/**
127
168
* Test getValue()
128
169
*/
@@ -133,7 +174,7 @@ public function testGetValue()
133
174
$ option1MinPrice = 10 ;
134
175
$ option1Type = 'select ' ;
135
176
136
- $ option2Id = ' 2 ' ;
177
+ $ option2Id = 2 ;
137
178
$ option2MaxPrice = 200 ;
138
179
$ option2MinPrice = 20 ;
139
180
$ option2Type = 'choice ' ;
@@ -154,7 +195,25 @@ public function testGetValue()
154
195
'is_require ' => false ,
155
196
]
156
197
];
198
+
199
+ $ singleValueOptionId = 3 ;
200
+ $ singleValueOptionPrice = '50 ' ;
201
+ $ singleValueOptionType = 'text ' ;
202
+
203
+ $ singleValueOptions = $ this ->setupSingleValueOptions (
204
+ [
205
+ [
206
+ 'id ' => $ singleValueOptionId ,
207
+ 'type ' => $ singleValueOptionType ,
208
+ 'price ' => $ singleValueOptionPrice ,
209
+ 'price_type ' => 'fixed ' ,
210
+ 'is_require ' => true ,
211
+ ],
212
+ ]
213
+ );
214
+
157
215
$ options = $ this ->setupOptions ($ optionsData );
216
+ $ options [] = $ singleValueOptions [0 ];
158
217
$ this ->product ->expects ($ this ->once ())
159
218
->method ('getOptions ' )
160
219
->will ($ this ->returnValue ($ options ));
@@ -171,6 +230,12 @@ public function testGetValue()
171
230
'type ' => $ option2Type ,
172
231
'min ' => 0. ,
173
232
'max ' => $ option2MaxPrice ,
233
+ ],
234
+ [
235
+ 'option_id ' => $ singleValueOptionId ,
236
+ 'type ' => $ singleValueOptionType ,
237
+ 'min ' => $ singleValueOptionPrice ,
238
+ 'max ' => $ singleValueOptionPrice ,
174
239
]
175
240
];
176
241
$ result = $ this ->object ->getValue ();
0 commit comments