Skip to content

Commit 97c6b0a

Browse files
committed
Add integration tests covering the success message after adding a product to cart
1 parent c67a76f commit 97c6b0a

File tree

1 file changed

+65
-0
lines changed
  • dev/tests/integration/testsuite/Magento/Checkout/Controller

1 file changed

+65
-0
lines changed

dev/tests/integration/testsuite/Magento/Checkout/Controller/CartTest.php

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -300,6 +300,71 @@ public function addAddProductDataProvider()
300300
];
301301
}
302302

303+
/**
304+
* Test for \Magento\Checkout\Controller\Cart\Add::execute() with simple product and activated redirect to cart
305+
*
306+
* @magentoDataFixture Magento/Catalog/_files/products.php
307+
* @magentoConfigFixture current_store checkout/cart/redirect_to_cart 1
308+
* @magentoAppIsolation enabled
309+
*/
310+
public function testMessageAtAddToCartWithRedirect()
311+
{
312+
$formKey = $this->_objectManager->get(FormKey::class);
313+
$postData = [
314+
'qty' => '1',
315+
'product' => '1',
316+
'custom_price' => 1,
317+
'form_key' => $formKey->getFormKey(),
318+
'isAjax' => 1
319+
];
320+
\Magento\TestFramework\Helper\Bootstrap::getInstance()->loadArea('frontend');
321+
$this->getRequest()->setPostValue($postData);
322+
323+
$this->dispatch('checkout/cart/add');
324+
325+
$this->assertEquals('{"backUrl":"http:\/\/localhost\/index.php\/checkout\/cart\/"}', $this->getResponse()->getBody());
326+
327+
$this->assertSessionMessages(
328+
$this->contains(
329+
'You added Simple Product to your shopping cart.'
330+
),
331+
\Magento\Framework\Message\MessageInterface::TYPE_SUCCESS
332+
);
333+
}
334+
335+
/**
336+
* Test for \Magento\Checkout\Controller\Cart\Add::execute() with simple product and deactivated redirect to cart
337+
*
338+
* @magentoDataFixture Magento/Catalog/_files/products.php
339+
* @magentoConfigFixture current_store checkout/cart/redirect_to_cart 0
340+
* @magentoAppIsolation enabled
341+
*/
342+
public function testMessageAtAddToCartWithoutRedirect()
343+
{
344+
$formKey = $this->_objectManager->get(FormKey::class);
345+
$postData = [
346+
'qty' => '1',
347+
'product' => '1',
348+
'custom_price' => 1,
349+
'form_key' => $formKey->getFormKey(),
350+
'isAjax' => 1
351+
];
352+
\Magento\TestFramework\Helper\Bootstrap::getInstance()->loadArea('frontend');
353+
$this->getRequest()->setPostValue($postData);
354+
355+
$this->dispatch('checkout/cart/add');
356+
357+
$this->assertFalse($this->getResponse()->isRedirect());
358+
$this->assertEquals('[]', $this->getResponse()->getBody());
359+
360+
$this->assertSessionMessages(
361+
$this->contains(
362+
"\n" . 'You added Simple Product to your <a href="http://localhost/index.php/checkout/cart/">shopping cart</a>.'
363+
),
364+
\Magento\Framework\Message\MessageInterface::TYPE_SUCCESS
365+
);
366+
}
367+
303368
/**
304369
* @covers \Magento\Checkout\Controller\Cart\Addgroup::execute()
305370
*

0 commit comments

Comments
 (0)