You are here

public function CommerceCartTestCaseSimpleProduct::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 128
Functional tests for the commerce cart module.

Class

CommerceCartTestCaseSimpleProduct
Test cart features for a product display that only has one product attached.

Code

public function testCommerceCartOrder() {

  // Load the current order of the user.
  $order = commerce_cart_order_load($this->store_customer->uid);
  $products = array();
  $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[$product->product_id] = $product;
    }
  }

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