-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Issue #2910738 by subhojit777: Ajaxify the confirmation message
- Loading branch information
1 parent
f6bb177
commit e77d260
Showing
4 changed files
with
148 additions
and
42 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
<?php | ||
|
||
namespace Drupal\Tests\dc_ajax_add_cart\Functional; | ||
|
||
use Drupal\Tests\commerce\FunctionalJavascript\JavascriptTestTrait; | ||
use Drupal\Tests\commerce_cart\Functional\CartBrowserTestBase; | ||
|
||
/** | ||
* Base class for ajax add cart tests. | ||
*/ | ||
abstract class AjaxAddCartTestBase extends CartBrowserTestBase { | ||
|
||
use JavascriptTestTrait; | ||
|
||
/** | ||
* Modules to enable. | ||
* | ||
* @var array | ||
*/ | ||
public static $modules = [ | ||
'commerce_product', | ||
'commerce_cart', | ||
'dc_ajax_add_cart', | ||
'dc_ajax_add_cart_test', | ||
]; | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
protected function setUp() { | ||
parent::setUp(); | ||
|
||
// Change commerce_product variation view display to dc_ajax_add_cart. | ||
\Drupal::entityTypeManager() | ||
->getStorage('entity_view_display') | ||
->load('commerce_product.default.default') | ||
->setComponent('variations', [ | ||
'type' => 'dc_ajax_add_cart', | ||
'settings' => [ | ||
'default_quantity' => '1', | ||
'combine' => TRUE, | ||
'show_quantity' => FALSE, | ||
], | ||
'weight' => 0, | ||
'label' => 'hidden', | ||
'region' => 'content', | ||
]) | ||
->save(); | ||
} | ||
|
||
} |
49 changes: 49 additions & 0 deletions
49
tests/src/FunctionalJavascript/AjaxAddCartConfirmationMessageTest.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
<?php | ||
|
||
namespace Drupal\Tests\dc_ajax_add_cart\FunctionalJavascript; | ||
|
||
use Drupal\commerce_order\Entity\Order; | ||
use Drupal\Tests\dc_ajax_add_cart\Functional\AjaxAddCartTestBase; | ||
|
||
/** | ||
* Ajax add cart confirmation message tests. | ||
* | ||
* @TODO The default `testing` profile is unable to render the ajax confirmation | ||
* message. Find out why this is happening, and move this test inside | ||
* `AjaxAddCartTest`. | ||
* | ||
* @ingroup dc_ajax_add_cart | ||
* | ||
* @group dc_ajax_add_cart | ||
*/ | ||
class AjaxAddCartConfirmationMessageTest extends AjaxAddCartTestBase { | ||
|
||
/** | ||
* Profile to be used for testing. | ||
* | ||
* @var string | ||
*/ | ||
protected $profile = 'standard'; | ||
|
||
/** | ||
* Tests whether the confirmation message appears after product added to cart. | ||
*/ | ||
public function testConfirmationMessage() { | ||
$this->drupalGet("product/{$this->variation->getProduct()->id()}"); | ||
$ajax_add_cart_button = $this->getSession()->getPage()->findButton('Add to cart'); | ||
|
||
$ajax_add_cart_button->click(); | ||
$this->waitForAjaxToFinish(); | ||
|
||
/* | ||
* Confirm that the initial add to cart submit works. | ||
*/ | ||
$this->cart = Order::load($this->cart->id()); | ||
$order_items = $this->cart->getItems(); | ||
$this->assertOrderItemInOrder($this->variation, $order_items[0]); | ||
|
||
// Confirm that the confirmation message has appeared. | ||
$this->assertSession()->pageTextContains("{$this->variation->getProduct()->label()} added to your cart."); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters