You are here

public function ProductTest::testProductQuantity in Ubercart 8.4

Tests product add-to-cart quantity.

File

uc_product/tests/src/Functional/ProductTest.php, line 260

Class

ProductTest
Tests the product content type.

Namespace

Drupal\Tests\uc_product\Functional

Code

public function testProductQuantity() {

  /** @var \Drupal\Tests\WebAssert $assert */
  $assert = $this
    ->assertSession();
  $edit = [
    'uc_product_add_to_cart_qty' => TRUE,
  ];
  $this
    ->drupalGet('admin/store/config/products');
  $this
    ->submitForm($edit, 'Save configuration');

  // Check zero quantity message.
  $this
    ->addToCart($this->product, [
    'qty' => 0,
  ]);
  $assert
    ->pageTextContains('The quantity cannot be zero.');

  // Check invalid quantity messages.
  $this
    ->addToCart($this->product, [
    'qty' => 'x',
  ]);
  $assert
    ->pageTextContains('The quantity must be an integer.');
  $this
    ->addToCart($this->product, [
    'qty' => '1a',
  ]);
  $assert
    ->pageTextContains('The quantity must be an integer.');

  // Check cart add message.
  $this
    ->addToCart($this->product, [
    'qty' => 1,
  ]);
  $assert
    ->pageTextContains($this->product
    ->getTitle() . ' added to your shopping cart.');

  // Check cart update message.
  $this
    ->addToCart($this->product, [
    'qty' => 1,
  ]);
  $assert
    ->pageTextContains('Your item(s) have been updated.');
}