You are here

public function CommerceProductReferenceAdminTest::testCommerceProductReferenceReferenceProducts in Commerce Core 7

Test adding some referenced products.

File

modules/product_reference/tests/commerce_product_reference.test, line 194
Tests for adding and displaying product reference fields.

Class

CommerceProductReferenceAdminTest
Functional tests for the Product Reference module.

Code

public function testCommerceProductReferenceReferenceProducts() {

  // Add a new product
  $new_product = $this
    ->createDummyProduct('PROD-04', 'Product Four');
  $product_title = t('@sku: @title', array(
    '@sku' => $new_product->sku,
    '@title' => $new_product->title,
  ));

  // Check at database level
  $field_products = commerce_product_match_products($this->field, NULL, $new_product->sku, 'equals');
  $this
    ->assertFalse(empty($field_products), t('Product is in the available products of the field'));

  // Check if it is in the reference field for product displays.
  $this
    ->drupalGet('admin/structure/types/manage/' . strtr($this->display_type->type, '_', '-') . '/fields/' . $this->field_name);
  $select_options = $this
    ->xpath("//select[@id='edit-field-product-und']//option");
  $this
    ->assertTrue(in_array($product_title, $select_options), t('Product is available in the select'));

  // Check if it is in the product display creation select form.
  $this
    ->drupalGet('node/add/' . strtr($this->display_type->type, '_', '-'));
  $select_options = $this
    ->xpath("//select[@id='edit-field-product-und']//option");
  $this
    ->assertTrue(in_array($product_title, $select_options), t('Product is available in the select'));
}