public function CartProviderTest::testCartValidation in Commerce Core 8.2
Tests cart validation.
@covers ::getCartIds @covers ::clearCaches
File
- modules/
cart/ tests/ src/ Kernel/ CartProviderTest.php, line 175
Class
- CartProviderTest
- Tests the cart provider.
Namespace
Drupal\Tests\commerce_cart\KernelCode
public function testCartValidation() {
// Locked carts should not be returned.
$cart = $this->cartProvider
->createCart('default', $this->store, $this->authenticatedUser);
$cart
->lock();
$cart
->save();
$this->cartProvider
->clearCaches();
$cart = $this->cartProvider
->getCart('default', $this->store, $this->authenticatedUser);
$this
->assertNull($cart);
// Carts that are no longer carts should not be returned.
$cart = $this->cartProvider
->createCart('default', $this->store, $this->authenticatedUser);
$cart->cart = FALSE;
$cart
->save();
$this->cartProvider
->clearCaches();
$cart = $this->cartProvider
->getCart('default', $this->store, $this->authenticatedUser);
$this
->assertNull($cart);
// Carts assigned to a different user should not be returned.
$cart = $this->cartProvider
->createCart('default', $this->store, $this->authenticatedUser);
$cart->uid = $this->anonymousUser
->id();
$cart
->save();
$this->cartProvider
->clearCaches();
$cart = $this->cartProvider
->getCart('default', $this->store, $this->authenticatedUser);
$this
->assertNull($cart);
// Canceled carts should not be returned.
$cart = $this->cartProvider
->createCart('default', $this->store, $this->authenticatedUser);
$cart->state = 'canceled';
$cart
->save();
$this->cartProvider
->clearCaches();
$cart = $this->cartProvider
->getCart('default', $this->store, $this->authenticatedUser);
$this
->assertNull($cart);
}