You are here

public function CommerceProductReferenceAdminTest::testCommerceProductReferenceTitleLinkFormatter in Commerce Core 7

Test the title link formatter.

File

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

Class

CommerceProductReferenceAdminTest
Functional tests for the Product Reference module.

Code

public function testCommerceProductReferenceTitleLinkFormatter() {

  // Go to manage fields screen of the product display.
  $this
    ->drupalGet('admin/structure/types/manage/' . strtr($this->display_type->type, '_', '-') . '/display');

  // Change the default value for SKU with link.
  $this
    ->drupalPost(NULL, array(
    'fields[field_product][type]' => 'commerce_product_reference_title_link',
  ), t('Save'));

  // Check if the value has been saved.
  $this
    ->assertText(t('Your settings have been saved.'), t('Settings saved message displayed'));
  $this
    ->assertOptionSelected('edit-fields-field-product-type', 'commerce_product_reference_title_link', t('Correct value is selected.'));

  // Clear field's cache and reload field instance information just saved.
  field_cache_clear();
  $field_instance = field_info_instance('node', $this->field_name, $this->display_type->type);

  // Check if the value has been stored in db.
  $this
    ->assertTrue($field_instance['display']['default']['type'] == 'commerce_product_reference_title_link', t('Option correctly stored in db'));

  // Create a product display using one product already generated.
  $product = reset($this->products);
  $product_node = $this
    ->createDummyProductNode(array(
    $product->product_id,
  ), $product->title);

  // Access to the product display node.
  $this
    ->drupalGet('node/' . $product_node->nid);

  // Generate and check the expected ouptut.
  $render = array(
    '#type' => 'link',
    '#title' => $product->title,
    '#href' => 'admin/commerce/products/' . $product->product_id,
  );
  $this
    ->assertRaw(drupal_render($render), t('Title Link is displayed correctly'));
}