You are here

public function ImageLinkFormatterFieldUITestCase::testFormatterManageDisplaySettings in Image Link Formatter 7

Test Image Link formatter manage display settings.

Ensure Image Link Formatter can be selected from the manage display pages and its settings form can be displayed and saved correctly. Check that the summary displays correctly and then test the display of a node's Image combined with a Link.

File

./image_link_formatter.test, line 296
Test the Image Link Formatter module.

Class

ImageLinkFormatterFieldUITestCase
Test Image Link Formatter's form and summary on the Manage display pages.

Code

public function testFormatterManageDisplaySettings() {
  $formatter = 'image_link_formatter';

  // Create a single value, not required, Link field.
  $link_field = $this
    ->createField($this->fieldLinkName, 'link_field', 'link_field');

  // Create a single value, not required, Image field.
  $this
    ->createField($this->fieldImageName, 'image', 'image_image', array(
    'uri_scheme' => 'public',
  ));

  // Now that the fields have been created, let's test the formatter.
  // Browse to the Manage Display page.
  $this
    ->drupalGet("admin/structure/types/manage/{$this->bundle}/display");

  // Change Image field's formatter to select image_link_formatter.
  $edit = array(
    'fields[' . $this->fieldImageName . '][type]' => $formatter,
    'refresh_rows' => $this->fieldImageName,
  );

  // Process the change through the AJAX form of the page.
  $this
    ->drupalPostAJAX(NULL, $edit, array(
    'op' => t('Refresh'),
  ));

  // Check if expected formatter is selected.
  $this
    ->assertFieldByName('fields[' . $this->fieldImageName . '][type]', $formatter, 'The Image Link Formatter is selected.');

  // Now edit the Image Link Formatter settings form.
  $this
    ->drupalPostAJAX(NULL, array(), $this->fieldImageName . '_formatter_settings_edit');

  // Display the page with the formatter settings form.
  $this
    ->verbose($this
    ->drupalGetContent());

  // No value should be selected for the image link.
  $this
    ->assertFieldByName('fields[' . $this->fieldImageName . '][settings_edit_form][settings][image_link]', "", 'Formatter <em>"Link image to"</em> is not yet configured.');

  // Select to link the image to the link field and submit the settings form.
  $edit = array(
    'fields[' . $this->fieldImageName . '][settings_edit_form][settings][image_link]' => $this->fieldLinkName,
  );
  $this
    ->drupalPostAJAX(NULL, $edit, array(
    $this->fieldImageName . '_formatter_settings_update' => t('Update'),
  ));

  // Display the page with the correct formatter summary.
  $this
    ->verbose($this
    ->drupalGetContent());

  // Hide the link and save all the formatter settings edited so far.
  $edit = array(
    'fields[' . $this->fieldLinkName . '][type]' => 'hidden',
  );
  $this
    ->drupalPost(NULL, $edit, t('Save'));
  $this
    ->assertRaw('Your settings have been saved.');

  // Check the formatter summary of the image field contains selected link.
  $link_field = field_info_instance('node', $this->fieldLinkName, $this->bundle);
  $this
    ->assertText("{$link_field['label']} ({$this->fieldLinkName})", format_string('The expected summary is displayed to <em>link image to</em> field: @field_label (@field_name).', array(
    '@field_label' => $link_field['label'],
    '@field_name' => $this->fieldLinkName,
  )));

  // Now check if these display settings display correctly in the front-end.
  // Create a new node with a single image and link.
  $nid = $this
    ->createNodeWithLinkImage();
  $node = node_load($nid, NULL, TRUE);

  // Check the Image and Link values displayed with ILF for a single value.
  $this
    ->assertRawImageLink($node, $link_field, format_string('The correct output was found for Image field <em>@field_name</em> displayed through the Image Link Formatter.', array(
    '@field_name' => $this->fieldImageName,
  )));
}