@@ -300,6 +300,71 @@ public function addAddProductDataProvider()
300
300
];
301
301
}
302
302
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
+
303
368
/**
304
369
* @covers \Magento\Checkout\Controller\Cart\Addgroup::execute()
305
370
*
0 commit comments