7
7
8
8
namespace Magento \Catalog \Test \Unit \Model \Attribute \Backend \TierPrice ;
9
9
10
- use Magento \Framework \TestFramework \Unit \Helper \ObjectManager ;
11
- use Magento \Catalog \Model \Product \Attribute \Backend \TierPrice \UpdateHandler ;
12
- use Magento \Store \Model \StoreManagerInterface ;
13
10
use Magento \Catalog \Api \ProductAttributeRepositoryInterface ;
11
+ use Magento \Catalog \Model \Product \Attribute \Backend \TierPrice \UpdateHandler ;
12
+ use Magento \Catalog \Model \ResourceModel \Product \Attribute \Backend \Tierprice ;
14
13
use Magento \Customer \Api \GroupManagementInterface ;
15
14
use Magento \Framework \EntityManager \MetadataPool ;
16
- use Magento \Catalog \Model \ResourceModel \Product \Attribute \Backend \Tierprice ;
15
+ use Magento \Framework \TestFramework \Unit \Helper \ObjectManager ;
16
+ use Magento \Store \Model \StoreManagerInterface ;
17
17
18
18
/**
19
19
* Unit tests for \Magento\Catalog\Model\Product\Attribute\Backend\TierPrice\UpdateHandler
@@ -95,20 +95,27 @@ protected function setUp()
95
95
);
96
96
}
97
97
98
- public function testExecute (): void
99
- {
100
- $ newTierPrices = [
101
- ['website_id ' => 0 , 'price_qty ' => 2 , 'cust_group ' => 0 , 'price ' => 15 ],
102
- ['website_id ' => 0 , 'price_qty ' => 3 , 'cust_group ' => 3200 , 'price ' => null , 'percentage_value ' => 20 ]
103
- ];
104
- $ priceIdToDelete = 2 ;
105
- $ originalTierPrices = [
106
- ['price_id ' => 1 , 'website_id ' => 0 , 'price_qty ' => 2 , 'cust_group ' => 0 , 'price ' => 10 ],
107
- ['price_id ' => $ priceIdToDelete , 'website_id ' => 0 , 'price_qty ' => 4 , 'cust_group ' => 0 , 'price ' => 20 ],
108
- ];
109
- $ linkField = 'entity_id ' ;
110
- $ productId = 10 ;
111
- $ originalProductId = 11 ;
98
+ /**
99
+ * Verify update handle.
100
+ *
101
+ * @param array $newTierPrices
102
+ * @param array $originalTierPrices
103
+ * @param int $priceIdToDelete
104
+ * @param string $linkField
105
+ * @param int $productId
106
+ * @param int $originalProductId
107
+ * @throws \Magento\Framework\Exception\InputException
108
+ *
109
+ * @dataProvider configDataProvider
110
+ */
111
+ public function testExecute (
112
+ $ newTierPrices ,
113
+ $ originalTierPrices ,
114
+ $ priceIdToDelete ,
115
+ $ linkField ,
116
+ $ productId ,
117
+ $ originalProductId
118
+ ): void {
112
119
113
120
/** @var \PHPUnit_Framework_MockObject_MockObject $product */
114
121
$ product = $ this ->getMockBuilder (\Magento \Catalog \Api \Data \ProductInterface::class)
@@ -128,8 +135,12 @@ public function testExecute(): void
128
135
['entity_id ' , $ originalProductId ]
129
136
]
130
137
);
138
+
131
139
$ product ->expects ($ this ->atLeastOnce ())->method ('getStoreId ' )->willReturn (0 );
132
- $ product ->expects ($ this ->atLeastOnce ())->method ('setData ' )->with ('tier_price_changed ' , 1 );
140
+
141
+ $ product ->expects ($ this ->atLeastOnce ())
142
+ ->method ('setData ' )
143
+ ->with ('tier_price_changed ' , 1 );
133
144
$ store = $ this ->getMockBuilder (\Magento \Store \Api \Data \StoreInterface::class)
134
145
->disableOriginalConstructor ()
135
146
->setMethods (['getWebsiteId ' ])
@@ -163,11 +174,12 @@ public function testExecute(): void
163
174
$ this ->tierPriceResource ->expects ($ this ->exactly (2 ))->method ('savePriceData ' )->willReturnSelf ();
164
175
$ this ->tierPriceResource ->expects ($ this ->once ())->method ('deletePriceData ' )
165
176
->with ($ productId , null , $ priceIdToDelete );
166
-
167
177
$ this ->assertEquals ($ product , $ this ->updateHandler ->execute ($ product ));
168
178
}
169
179
170
180
/**
181
+ * Verify update handle with exception.
182
+ *
171
183
* @expectedException \Magento\Framework\Exception\InputException
172
184
* @expectedExceptionMessage Tier prices data should be array, but actually other type is received
173
185
*/
@@ -190,4 +202,88 @@ public function testExecuteWithException(): void
190
202
191
203
$ this ->updateHandler ->execute ($ product );
192
204
}
205
+
206
+ /**
207
+ * Returns test parameters.
208
+ *
209
+ * @return array
210
+ */
211
+ public function configDataProvider ()
212
+ {
213
+ return [
214
+ [
215
+ [
216
+ [
217
+ 'website_id ' => 0 ,
218
+ 'price_qty ' => 2 ,
219
+ 'cust_group ' => 0 ,
220
+ 'price ' => 15
221
+ ],
222
+ [
223
+ 'website_id ' => 0 ,
224
+ 'price_qty ' => 3 ,
225
+ 'cust_group ' => 3200 ,
226
+ 'price ' => null ,
227
+ 'percentage_value ' => 20
228
+ ]
229
+ ],
230
+ [
231
+ [
232
+ 'price_id ' => 1 ,
233
+ 'website_id ' => 0 ,
234
+ 'price_qty ' => 2 ,
235
+ 'cust_group ' => 0 ,
236
+ 'price ' => 10 ],
237
+ [
238
+ 'price_id ' => 2 ,
239
+ 'website_id ' => 0 ,
240
+ 'price_qty ' => 4 ,
241
+ 'cust_group ' => 0 ,
242
+ 'price ' => 20
243
+ ],
244
+ ],
245
+ 2 ,
246
+ 'entity_id ' ,
247
+ 10 ,
248
+ 11
249
+ ],
250
+ [
251
+ [
252
+ [
253
+ 'website_id ' => 0 ,
254
+ 'price_qty ' => 2 ,
255
+ 'cust_group ' => 0 ,
256
+ 'price ' => 0
257
+ ],
258
+ [
259
+ 'website_id ' => 0 ,
260
+ 'price_qty ' => 3 ,
261
+ 'cust_group ' => 3200 ,
262
+ 'price ' => null ,
263
+ 'percentage_value ' => 20
264
+ ]
265
+ ],
266
+ [
267
+ [
268
+ 'price_id ' => 1 ,
269
+ 'website_id ' => 0 ,
270
+ 'price_qty ' => 2 ,
271
+ 'cust_group ' => 0 ,
272
+ 'price ' => 10
273
+ ],
274
+ [
275
+ 'price_id ' => 2 ,
276
+ 'website_id ' => 0 ,
277
+ 'price_qty ' => 4 ,
278
+ 'cust_group ' => 0 ,
279
+ 'price ' => 20
280
+ ],
281
+ ],
282
+ 2 ,
283
+ 'entity_id ' ,
284
+ 10 ,
285
+ 11
286
+ ]
287
+ ];
288
+ }
193
289
}
0 commit comments