You are here

function CommerceCartTestCaseAttributes::setUp in Commerce Core 7

Implementation of setUp().

Overrides DrupalWebTestCase::setUp

File

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

Class

CommerceCartTestCaseAttributes
Test cart features for a product with attributes.

Code

function setUp() {
  parent::setUpHelper('all');

  // Create a dummy product display content type.
  $this
    ->createDummyProductDisplayContentType('product_display', TRUE, 'field_product', FIELD_CARDINALITY_UNLIMITED);

  // Create the fields and bind them to the product.
  $this->fields['field_1'] = array(
    'field_name' => 'field_1',
    'type' => 'list_text',
    'cardinality' => 1,
    'settings' => array(
      'allowed_values' => array(
        'field_1_value_1' => 'field_1_value_1',
        'field_1_value_2' => 'field_1_value_2',
      ),
    ),
  );
  $this->fields['field_1'] = field_create_field($this->fields['field_1']);
  $this->fields['field_2'] = array(
    'field_name' => 'field_2',
    'type' => 'list_text',
    'cardinality' => 1,
    'settings' => array(
      'allowed_values' => array(
        'field_2_value_1' => 'field_2_value_1',
        'field_2_value_2' => 'field_2_value_2',
      ),
    ),
  );
  $this->fields['field_2'] = field_create_field($this->fields['field_2']);
  foreach ($this->fields as $field) {
    $instance = array(
      'field_name' => $field['field_name'],
      'entity_type' => 'commerce_product',
      'bundle' => 'product',
      'label' => $field['field_name'] . '_label',
      'description' => $field['field_name'] . '_description',
      'required' => TRUE,
      'widget' => array(
        'module' => 'options',
        'type' => 'options_select',
      ),
      'commerce_cart_settings' => array(
        'attribute_field' => TRUE,
        'attribute_widget' => 'select',
      ),
    );
    field_create_instance($instance);
  }

  // Populate the different values for the fields and create products.
  foreach ($this->fields['field_1']['settings']['allowed_values'] as $field_1_value) {
    foreach ($this->fields['field_2']['settings']['allowed_values'] as $field_2_value) {
      $product = $this
        ->createDummyProduct('PROD-' . $field_1_value . '-' . $field_2_value, $field_1_value . '_' . $field_2_value);
      $product->field_1[LANGUAGE_NONE][0]['value'] = $field_1_value;
      $product->field_2[LANGUAGE_NONE][0]['value'] = $field_2_value;
      $product->is_new = FALSE;
      commerce_product_save($product);
      $this->products[$product->product_id] = $product;
    }
  }

  // Create dummy product display node.
  $this->product_node = $this
    ->createDummyProductNode(array_keys($this->products), 'Combined Product');

  // Log as a normal user to test cart process.
  $this
    ->drupalLogin($this->store_customer);
}