Skip to content

Commit 2fc33b4

Browse files
committed
Covering the successfully adding a valid coupon to cart by an integration test
1 parent 2fcf9b7 commit 2fc33b4

File tree

1 file changed

+31
-0
lines changed

1 file changed

+31
-0
lines changed

dev/tests/integration/testsuite/Magento/Checkout/Controller/Cart/Index/CouponPostTest.php

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,4 +36,35 @@ public function testExecute()
3636
\Magento\Framework\Message\MessageInterface::TYPE_ERROR
3737
);
3838
}
39+
40+
/**
41+
* Testing by adding a valid coupon to cart
42+
*
43+
* @magentoDataFixture Magento/Checkout/_files/quote_with_virtual_product_and_address.php
44+
* @magentoDataFixture Magento/Usps/Fixtures/cart_rule_coupon_free_shipping.php
45+
* @return void
46+
*/
47+
public function testAddingValidCoupon(): void
48+
{
49+
/** @var $session \Magento\Checkout\Model\Session */
50+
$session = $this->_objectManager->create(\Magento\Checkout\Model\Session::class);
51+
$quote = $session->getQuote();
52+
$quote->setData('trigger_recollect', 1)->setTotalsCollectedFlag(true);
53+
54+
$couponCode = 'IMPHBR852R61';
55+
$inputData = [
56+
'remove' => 0,
57+
'coupon_code' => $couponCode
58+
];
59+
$this->getRequest()->setMethod(HttpRequest::METHOD_POST);
60+
$this->getRequest()->setPostValue($inputData);
61+
$this->dispatch(
62+
'checkout/cart/couponPost/'
63+
);
64+
65+
$this->assertSessionMessages(
66+
$this->equalTo(['You used coupon code "' . $couponCode . '".']),
67+
\Magento\Framework\Message\MessageInterface::TYPE_SUCCESS
68+
);
69+
}
3970
}

0 commit comments

Comments
 (0)