1515use Magento \ConfigurableProduct \Api \LinkManagementInterface ;
1616use Magento \ConfigurableProduct \Model \LinkManagement ;
1717use Magento \Customer \Model \Group ;
18+ use Magento \Integration \Api \CustomerTokenServiceInterface ;
19+ use Magento \GraphQl \Customer \LockCustomer ;
1820use Magento \Framework \ObjectManager \ObjectManager ;
1921use Magento \TestFramework \Helper \Bootstrap ;
2022use Magento \TestFramework \TestCase \GraphQlAbstract ;
@@ -27,11 +29,23 @@ class ProductPriceTest extends GraphQlAbstract
2729 /** @var ProductRepositoryInterface $productRepository */
2830 private $ productRepository ;
2931
32+ /**
33+ * @var CustomerTokenServiceInterface
34+ */
35+ private $ customerTokenService ;
36+
37+ /**
38+ * @var LockCustomer
39+ */
40+ private $ lockCustomer ;
41+
3042 protected function setUp (): void
3143 {
3244 $ this ->objectManager = Bootstrap::getObjectManager ();
3345 /** @var ProductRepositoryInterface $productRepository */
3446 $ this ->productRepository = $ this ->objectManager ->get (ProductRepositoryInterface::class);
47+ $ this ->customerTokenService = $ this ->objectManager ->get (CustomerTokenServiceInterface::class);
48+ $ this ->lockCustomer = $ this ->objectManager ->get (LockCustomer::class);
3549 }
3650
3751 /**
@@ -235,10 +249,20 @@ public function testMultipleProductTypes()
235249 * Simple products with special price and tier price with % discount
236250 *
237251 * @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
239259 */
240- public function testSimpleProductsWithSpecialPriceAndTierPrice ()
241- {
260+ public function testSimpleProductsWithSpecialPriceAndTierPrice (
261+ int $ customerGroup ,
262+ array $ expectedPriceRange ,
263+ array $ expectedTierPrices ,
264+ array $ customerData
265+ ) {
242266 $ skus = ["simple1 " , "simple2 " ];
243267 $ tierPriceFactory = $ this ->objectManager ->get (ProductTierPriceInterfaceFactory::class);
244268
@@ -249,7 +273,7 @@ public function testSimpleProductsWithSpecialPriceAndTierPrice()
249273 $ tierPrices [] = $ tierPriceFactory ->create (
250274 [
251275 'data ' => [
252- 'customer_group_id ' => \ Magento \ Customer \ Model \Group:: CUST_GROUP_ALL ,
276+ 'customer_group_id ' => $ customerGroup ,
253277 'qty ' => 2
254278 ]
255279 ]
@@ -260,97 +284,137 @@ public function testSimpleProductsWithSpecialPriceAndTierPrice()
260284 $ simpleProduct ->setTierPrices ($ tierPrices );
261285 $ this ->productRepository ->save ($ simpleProduct );
262286 }
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+
263297 $ query = $ this ->getProductQuery ($ skus );
264- $ result = $ this ->graphQlQuery ($ query );
298+ $ result = $ this ->graphQlQuery ($ query, [], '' , $ headerMap );
265299 $ this ->assertArrayNotHasKey ('errors ' , $ result );
266300 $ this ->assertCount (2 , $ result ['products ' ]['items ' ]);
267301
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+ ]
276333 ],
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+ ]
280345 ]
281346 ],
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+ ]
285354 ],
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+ ]
292361 ]
293- ]
362+ ],
363+ 'customer_data ' => []
294364 ],
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+ ]
302379 ],
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+ ]
306391 ]
307392 ],
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+ ]
311400 ],
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+ ]
318407 ]
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 '
331412 ]
332413 ],
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- ]
344414 ];
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- }
352415 }
353416
417+
354418 /**
355419 * Check the pricing for a grouped product with simple products having special price set
356420 *
0 commit comments