You are here

public function AddToCartFormTest::testExposedOrderItemFields in Commerce Core 8.2

Tests ability to expose order item fields on the add to cart form.

File

modules/cart/tests/src/Functional/AddToCartFormTest.php, line 136

Class

AddToCartFormTest
Tests the add to cart form.

Namespace

Drupal\Tests\commerce_cart\Functional

Code

public function testExposedOrderItemFields() {

  /** @var \Drupal\Core\Entity\Entity\EntityFormDisplay $order_item_form_display */
  $order_item_form_display = EntityFormDisplay::load('commerce_order_item.default.add_to_cart');
  $order_item_form_display
    ->setComponent('quantity', [
    'type' => 'commerce_quantity',
  ]);
  $order_item_form_display
    ->save();

  // Confirm that the given quantity was accepted and saved.
  $this
    ->postAddToCart($this->variation
    ->getProduct(), [
    'quantity[0][value]' => 3,
  ]);
  $this->cart = Order::load($this->cart
    ->id());
  $order_items = $this->cart
    ->getItems();
  $this
    ->assertOrderItemInOrder($this->variation, $order_items[0], 3);

  // Confirm that a zero quantity isn't accepted.
  $this
    ->postAddToCart($this->variation
    ->getProduct(), [
    'quantity[0][value]' => 0,
  ]);
  $this
    ->assertSession()
    ->pageTextContains('Quantity must be higher than or equal to 1.');
}