Skip to content

Commit 9eee987

Browse files
committed
MC-19255: API functional tests to cover cart promotions
- added additional validation for no discount
1 parent d91a70f commit 9eee987

File tree

4 files changed

+74
-0
lines changed

4 files changed

+74
-0
lines changed

dev/tests/api-functional/testsuite/Magento/GraphQl/Quote/CartPromotionsTest.php

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -335,6 +335,36 @@ public function testCartPromotionsWithCoupons()
335335
$this->assertEquals($response['cart']['prices']['discounts'][0]['amount']['value'], 5);
336336
}
337337

338+
/**
339+
* If no discount is applicable to the cart, row total discount should be zero and no rule label shown
340+
*
341+
* @magentoApiDataFixture Magento/Catalog/_files/multiple_products.php
342+
* @magentoApiDataFixture Magento/SalesRule/_files/buy_3_get_1_free.php
343+
*/
344+
public function testCartPromotionsWhenNoDiscountIsAvailable()
345+
{
346+
$objectManager = Bootstrap::getObjectManager();
347+
/** @var ProductRepositoryInterface $productRepository */
348+
$productRepository = $objectManager->get(ProductRepositoryInterface::class);
349+
/** @var Product $prod2 */
350+
$prod1 = $productRepository->get('simple1');
351+
$prod2 = $productRepository->get('simple2');
352+
$productsInCart = [$prod1, $prod2];
353+
$prod2->setVisibility(Visibility::VISIBILITY_BOTH);
354+
$productRepository->save($prod2);
355+
$skus =['simple1', 'simple2'];
356+
$qty = 2;
357+
$cartId = $this->createEmptyCart();
358+
$this->addMultipleSimpleProductsToCart($cartId, $qty, $skus[0], $skus[1]);
359+
$query = $this->getCartItemPricesQuery($cartId);
360+
$response = $this->graphQlMutation($query);
361+
$this->assertCount(2, $response['cart']['items']);
362+
foreach ($response['cart']['items'] as $cartItems) {
363+
$this->assertEquals(0, $cartItems['prices']['total_item_discount']['value']);
364+
$this->assertNull($cartItems['prices']['discounts']);
365+
}
366+
}
367+
338368
/**
339369
* Validating if the discount label in the response shows the default value if no label is available on cart rule
340370
*
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
declare(strict_types=1);
7+
8+
use Magento\Customer\Model\GroupManagement;
9+
use Magento\SalesRule\Model\Rule;
10+
use Magento\Store\Model\StoreManagerInterface;
11+
use Magento\TestFramework\Helper\Bootstrap;
12+
13+
$objectManager = Bootstrap::getObjectManager();
14+
15+
/** @var Rule $salesRule */
16+
$salesRule = $objectManager->create(Rule::class);
17+
$salesRule->setData(
18+
[
19+
'name' => 'Buy 3 And Get 1 Free',
20+
'is_active' => 1,
21+
'customer_group_ids' => [GroupManagement::NOT_LOGGED_IN_ID],
22+
'coupon_type' => Rule::COUPON_TYPE_NO_COUPON,
23+
'conditions' => [],
24+
'simple_action' => Rule::BUY_X_GET_Y_ACTION,
25+
'discount_amount' => 1,
26+
'discount_step' => 3,
27+
'stop_rules_processing' => 0,
28+
'store_labels' => [0 => ' Get 1 item free for every 3 you buy'],
29+
'website_ids' => [
30+
$objectManager->get(StoreManagerInterface::class)->getWebsite()->getId(),
31+
],
32+
]
33+
);
34+
$objectManager->get(\Magento\SalesRule\Model\ResourceModel\Rule::class)->save($salesRule);
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
declare(strict_types=1);
7+
8+
// phpcs:ignore Magento2.Security.IncludeFile
9+
require __DIR__ . '/rules_rollback.php';

dev/tests/integration/testsuite/Magento/SalesRule/_files/cart_rule_10_percent_off_qty_more_than_2_items.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
'discount_amount' => 10,
2828
'discount_step' => 0,
2929
'stop_rules_processing' => 1,
30+
'is_advanced' => 1,
3031
'website_ids' => [$websiteId],
3132
'store_labels' => [
3233

0 commit comments

Comments
 (0)