EmptyCartButtonTest.php in Commerce Core 8.2
File
modules/cart/tests/src/Functional/EmptyCartButtonTest.php
View source
<?php
namespace Drupal\Tests\commerce_cart\Functional;
use Drupal\Tests\commerce_order\Functional\OrderBrowserTestBase;
class EmptyCartButtonTest extends OrderBrowserTestBase {
protected $cart;
protected $cartManager;
public static $modules = [
'commerce_cart_test',
];
protected function setUp() : void {
parent::setUp();
$this->cart = $this->container
->get('commerce_cart.cart_provider')
->createCart('default', $this->store);
$this->cartManager = $this->container
->get('commerce_cart.cart_manager');
}
public function testEmptyCartButton() {
$this
->drupalLogin($this->adminUser);
$second_variation = $this
->createEntity('commerce_product_variation', [
'type' => 'default',
'sku' => $this
->randomMachineName(),
'price' => [
'number' => 222,
'currency_code' => 'USD',
],
]);
$this
->createEntity('commerce_product', [
'type' => 'default',
'title' => $this
->randomMachineName(),
'stores' => [
$this->store,
],
'variations' => [
$second_variation,
],
]);
$this->cartManager
->addEntity($this->cart, $this->variation);
$this->cartManager
->addEntity($this->cart, $second_variation);
$this
->drupalGet('test-empty-cart-button-form/' . $this->cart
->id());
$this
->assertSession()
->pageTextContains('$999.00');
$this
->assertSession()
->pageTextContains('$222.00');
$this
->assertSession()
->buttonExists('Empty cart');
$this
->submitForm([], t('Empty cart'));
$this
->assertSession()
->pageTextContains(t('Your shopping cart is empty.'));
}
}