You are here

public function CommerceCartTestCaseMultiProducts::testCommerceCartOrder in Commerce Core 7

Test if the product is present in the order stored in db.

File

modules/cart/tests/commerce_cart.test, line 295
Functional tests for the commerce cart module.

Class

CommerceCartTestCaseMultiProducts
Test cart features for a product display that has several products attached.

Code

public function testCommerceCartOrder() {
  $products_in_cart = array();

  // Load the current order of the user.
  $order = commerce_cart_order_load($this->store_customer->uid);

  // Check if the user has at least one order in cart status.
  $this
    ->assertTrue(commerce_cart_order_is_cart($order), t('User has currently an order in cart status.'));

  // Get the products out of the order and store them in an array.
  foreach (entity_metadata_wrapper('commerce_order', $order)->commerce_line_items as $delta => $line_item_wrapper) {
    if (in_array($line_item_wrapper
      ->getBundle(), commerce_product_line_item_types())) {
      $product = $line_item_wrapper->commerce_product
        ->value();
      $products_in_cart[$product->product_id] = $product;
    }
  }

  // Check if the product is in the products array for the order.
  $this
    ->assertTrue(array_key_exists($this->products[2]->product_id, $products_in_cart), t('Product is actually in the cart'));
}