15
15
use Magento \ConfigurableProduct \Api \LinkManagementInterface ;
16
16
use Magento \ConfigurableProduct \Model \LinkManagement ;
17
17
use Magento \Customer \Model \Group ;
18
+ use Magento \Integration \Api \CustomerTokenServiceInterface ;
19
+ use Magento \GraphQl \Customer \LockCustomer ;
18
20
use Magento \Framework \ObjectManager \ObjectManager ;
19
21
use Magento \TestFramework \Helper \Bootstrap ;
20
22
use Magento \TestFramework \TestCase \GraphQlAbstract ;
@@ -27,11 +29,23 @@ class ProductPriceTest extends GraphQlAbstract
27
29
/** @var ProductRepositoryInterface $productRepository */
28
30
private $ productRepository ;
29
31
32
+ /**
33
+ * @var CustomerTokenServiceInterface
34
+ */
35
+ private $ customerTokenService ;
36
+
37
+ /**
38
+ * @var LockCustomer
39
+ */
40
+ private $ lockCustomer ;
41
+
30
42
protected function setUp (): void
31
43
{
32
44
$ this ->objectManager = Bootstrap::getObjectManager ();
33
45
/** @var ProductRepositoryInterface $productRepository */
34
46
$ this ->productRepository = $ this ->objectManager ->get (ProductRepositoryInterface::class);
47
+ $ this ->customerTokenService = $ this ->objectManager ->get (CustomerTokenServiceInterface::class);
48
+ $ this ->lockCustomer = $ this ->objectManager ->get (LockCustomer::class);
35
49
}
36
50
37
51
/**
@@ -235,10 +249,20 @@ public function testMultipleProductTypes()
235
249
* Simple products with special price and tier price with % discount
236
250
*
237
251
* @magentoApiDataFixture Magento/Catalog/_files/multiple_products.php
238
- * @SuppressWarnings(PHPMD.ExcessiveMethodLength)
252
+ * @magentoApiDataFixture Magento/Customer/_files/customer.php
253
+ * @param int $customerGroup
254
+ * @param array $expectedPriceRange
255
+ * @param array $expectedTierPrices
256
+ * @param array $customerData
257
+ * @param bool $isTierPriceExists
258
+ * @dataProvider priceDataProvider
239
259
*/
240
- public function testSimpleProductsWithSpecialPriceAndTierPrice ()
241
- {
260
+ public function testSimpleProductsWithSpecialPriceAndTierPrice (
261
+ int $ customerGroup ,
262
+ array $ expectedPriceRange ,
263
+ array $ expectedTierPrices ,
264
+ array $ customerData
265
+ ) {
242
266
$ skus = ["simple1 " , "simple2 " ];
243
267
$ tierPriceFactory = $ this ->objectManager ->get (ProductTierPriceInterfaceFactory::class);
244
268
@@ -249,7 +273,7 @@ public function testSimpleProductsWithSpecialPriceAndTierPrice()
249
273
$ tierPrices [] = $ tierPriceFactory ->create (
250
274
[
251
275
'data ' => [
252
- 'customer_group_id ' => \ Magento \ Customer \ Model \Group:: CUST_GROUP_ALL ,
276
+ 'customer_group_id ' => $ customerGroup ,
253
277
'qty ' => 2
254
278
]
255
279
]
@@ -260,97 +284,137 @@ public function testSimpleProductsWithSpecialPriceAndTierPrice()
260
284
$ simpleProduct ->setTierPrices ($ tierPrices );
261
285
$ this ->productRepository ->save ($ simpleProduct );
262
286
}
287
+
288
+ $ headerMap = [];
289
+ if (!empty ($ customerData )) {
290
+ $ customerToken = $ this ->customerTokenService ->createCustomerAccessToken (
291
+ $ customerData ['username ' ],
292
+ $ customerData ['password ' ]
293
+ );
294
+ $ headerMap = ['Authorization ' => 'Bearer ' . $ customerToken ];
295
+ }
296
+
263
297
$ query = $ this ->getProductQuery ($ skus );
264
- $ result = $ this ->graphQlQuery ($ query );
298
+ $ result = $ this ->graphQlQuery ($ query, [], '' , $ headerMap );
265
299
$ this ->assertArrayNotHasKey ('errors ' , $ result );
266
300
$ this ->assertCount (2 , $ result ['products ' ]['items ' ]);
267
301
268
- $ expectedPriceRange = [
269
- "simple1 " => [
270
- "minimum_price " => [
271
- "regular_price " => [
272
- "value " => 10
273
- ],
274
- "final_price " => [
275
- "value " => 5.99
302
+ foreach ($ result ['products ' ]['items ' ] as $ product ) {
303
+ $ this ->assertNotEmpty ($ product ['price_range ' ]);
304
+ $ this ->assertNotEmpty ($ product ['price_tiers ' ]);
305
+ $ this ->assertPrices ($ expectedPriceRange [$ product ['sku ' ]], $ product ['price_range ' ]);
306
+ $ this ->assertResponseFields ($ product ['price_tiers ' ], $ expectedTierPrices [$ product ['sku ' ]]);
307
+ }
308
+ }
309
+
310
+ /**
311
+ * Data provider for prices
312
+ *
313
+ * @return array
314
+ * @SuppressWarnings(PHPMD.ExcessiveMethodLength)
315
+ */
316
+ public function priceDataProvider () : array
317
+ {
318
+ return [
319
+ [
320
+ 'customer_group ' => Group::CUST_GROUP_ALL ,
321
+ 'expected_price_range ' => [
322
+ "simple1 " => [
323
+ "minimum_price " => [
324
+ "regular_price " => ["value " => 10 ],
325
+ "final_price " => ["value " => 5.99 ],
326
+ "discount " => ["amount_off " => 4.01 , "percent_off " => 40.1 ]
327
+ ],
328
+ "maximum_price " => [
329
+ "regular_price " => ["value " => 10 ],
330
+ "final_price " => ["value " => 5.99 ],
331
+ "discount " => ["amount_off " => 4.01 , "percent_off " => 40.1 ]
332
+ ]
276
333
],
277
- "discount " => [
278
- "amount_off " => 4.01 ,
279
- "percent_off " => 40.1
334
+ "simple2 " => [
335
+ "minimum_price " => [
336
+ "regular_price " => ["value " => 20 ],
337
+ "final_price " => ["value " => 15.99 ],
338
+ "discount " => ["amount_off " => 4.01 , "percent_off " => 20.05 ]
339
+ ],
340
+ "maximum_price " => [
341
+ "regular_price " => ["value " => 20 ],
342
+ "final_price " => ["value " => 15.99 ],
343
+ "discount " => ["amount_off " => 4.01 , "percent_off " => 20.05 ]
344
+ ]
280
345
]
281
346
],
282
- "maximum_price " => [
283
- "regular_price " => [
284
- "value " => 10
347
+ 'expected_tier_prices ' => [
348
+ "simple1 " => [
349
+ 0 => [
350
+ 'discount ' =>['amount_off ' => 1 , 'percent_off ' => 10 ],
351
+ 'final_price ' =>['value ' => 9 ],
352
+ 'quantity ' => 2
353
+ ]
285
354
],
286
- "final_price " => [
287
- " value " => 5.99
288
- ],
289
- " discount " => [
290
- " amount_off " => 4.01 ,
291
- " percent_off " => 40.1
355
+ "simple2 " => [
356
+ 0 => [
357
+ ' discount ' =>[ ' amount_off ' => 2 , ' percent_off ' => 10 ],
358
+ ' final_price ' =>[ ' value ' => 18 ],
359
+ ' quantity ' => 2
360
+ ]
292
361
]
293
- ]
362
+ ],
363
+ 'customer_data ' => []
294
364
],
295
- "simple2 " => [
296
- "minimum_price " => [
297
- "regular_price " => [
298
- "value " => 20
299
- ],
300
- "final_price " => [
301
- "value " => 15.99
365
+ [
366
+ 'customer_group ' => 1 ,
367
+ 'expected_price_range ' => [
368
+ "simple1 " => [
369
+ "minimum_price " => [
370
+ "regular_price " => ["value " => 10 ],
371
+ "final_price " => ["value " => 5.99 ],
372
+ "discount " => ["amount_off " => 4.01 , "percent_off " => 40.1 ]
373
+ ],
374
+ "maximum_price " => [
375
+ "regular_price " => ["value " => 10 ],
376
+ "final_price " => ["value " => 5.99 ],
377
+ "discount " => ["amount_off " => 4.01 , "percent_off " => 40.1 ]
378
+ ]
302
379
],
303
- "discount " => [
304
- "amount_off " => 4.01 ,
305
- "percent_off " => 20.05
380
+ "simple2 " => [
381
+ "minimum_price " => [
382
+ "regular_price " => ["value " => 20 ],
383
+ "final_price " => ["value " => 15.99 ],
384
+ "discount " => ["amount_off " => 4.01 , "percent_off " => 20.05 ]
385
+ ],
386
+ "maximum_price " => [
387
+ "regular_price " => ["value " => 20 ],
388
+ "final_price " => ["value " => 15.99 ],
389
+ "discount " => ["amount_off " => 4.01 , "percent_off " => 20.05 ]
390
+ ]
306
391
]
307
392
],
308
- "maximum_price " => [
309
- "regular_price " => [
310
- "value " => 20
393
+ 'expected_tier_prices ' => [
394
+ "simple1 " => [
395
+ 0 => [
396
+ 'discount ' =>['amount_off ' => 1 , 'percent_off ' => 10 ],
397
+ 'final_price ' =>['value ' => 9 ],
398
+ 'quantity ' => 2
399
+ ]
311
400
],
312
- "final_price " => [
313
- " value " => 15.99
314
- ],
315
- " discount " => [
316
- " amount_off " => 4.01 ,
317
- " percent_off " => 20.05
401
+ "simple2 " => [
402
+ 0 => [
403
+ ' discount ' =>[ ' amount_off ' => 2 , ' percent_off ' => 10 ],
404
+ ' final_price ' =>[ ' value ' => 18 ],
405
+ ' quantity ' => 2
406
+ ]
318
407
]
319
- ]
320
- ]
321
- ];
322
- $ expectedTierPrices = [
323
- "simple1 " => [
324
- 0 => [
325
- 'discount ' =>[
326
- 'amount_off ' => 1 ,
327
- 'percent_off ' => 10
328
- ],
329
- 'final_price ' =>['value ' => 9 ],
330
- 'quantity ' => 2
408
+ ],
409
+ 'customer_data ' => [
410
+ 'username ' => 'customer@example.com ' ,
411
+ 'password ' => 'password '
331
412
]
332
413
],
333
- "simple2 " => [
334
- 0 => [
335
- 'discount ' =>[
336
- 'amount_off ' => 2 ,
337
- 'percent_off ' => 10
338
- ],
339
- 'final_price ' =>['value ' => 18 ],
340
- 'quantity ' => 2
341
- ]
342
-
343
- ]
344
414
];
345
-
346
- foreach ($ result ['products ' ]['items ' ] as $ product ) {
347
- $ this ->assertNotEmpty ($ product ['price_range ' ]);
348
- $ this ->assertNotEmpty ($ product ['price_tiers ' ]);
349
- $ this ->assertPrices ($ expectedPriceRange [$ product ['sku ' ]], $ product ['price_range ' ]);
350
- $ this ->assertResponseFields ($ product ['price_tiers ' ], $ expectedTierPrices [$ product ['sku ' ]]);
351
- }
352
415
}
353
416
417
+
354
418
/**
355
419
* Check the pricing for a grouped product with simple products having special price set
356
420
*
0 commit comments