public function CommerceAvailabilityExistingRightsTest::testAddToCart in Commerce License 8.2
Tests a product is not to the cart when the user has existing rights.
File
- tests/
src/ Kernel/ CommerceAvailabilityExistingRightsTest.php, line 122
Class
- CommerceAvailabilityExistingRightsTest
- Tests a product is not added to the cart when the user has existing rights.
Namespace
Drupal\Tests\commerce_license\KernelCode
public function testAddToCart() {
$this->store = $this
->createStore();
$customer = $this
->createUser();
$cart_order = $this->container
->get('commerce_cart.cart_provider')
->createCart('license_order_type', $this->store, $customer);
$this->cartManager = $this->container
->get('commerce_cart.cart_manager');
// Tell our test license type plugin to report that the user has existing
// rights.
\Drupal::state()
->set('commerce_license_test.existing_rights_check_config', TRUE);
// Try to add the product to the cart.
$this->cartManager
->addEntity($cart_order, $this->variation);
$cart_order = $this
->reloadEntity($cart_order);
$this
->assertTrue(\Drupal::state()
->get('commerce_license_test.called.checkUserHasExistingRights'), "The checkUserHasExistingRights() method was called on the license type plugin.");
$this
->assertCount(0, $cart_order
->getItems(), "The product was not added to the cart.");
// Tell our test license type plugin to report that the user does not have
// existing rights.
\Drupal::state()
->set('commerce_license_test.existing_rights_check_config', FALSE);
// Try to add the product to the cart.
$this->cartManager
->addEntity($cart_order, $this->variation);
$cart_order = $this
->reloadEntity($cart_order);
$this
->assertCount(1, $cart_order
->getItems(), "The product was added to the cart.");
}