You are here

public function ImageLinkFormatterTestCase::assertRawImageLink in Image Link Formatter 7

Assert whether an Image wrapped in a Link is found in page's raw markup.

The markup generated by Image Link Formatter is programmatically generated to what it should be in 'theory' and then compared with what is actually generated by the module and displayed in the page, in the raw HTML markup.

Parameters

object $node: The node to which the Image and Link fields are attached.

array $link_field: Link field instance attached to the content type of the node.

$message: (optional) The message to display upon assertion.

int $delta: (optional) The index of the field value, whether Image or Link fields.

1 call to ImageLinkFormatterTestCase::assertRawImageLink()
ImageLinkFormatterFieldUITestCase::testFormatterManageDisplaySettings in ./image_link_formatter.test
Test Image Link formatter manage display settings.

File

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

Class

ImageLinkFormatterTestCase
Provides common functionality for the Image Link Formatter test classes.

Code

public function assertRawImageLink($node, $link_field, $message = '', $delta = 0) {

  // Create programmatically the markup that should be generated by ILF.
  // Create the HTML markup for the Image.
  $image_info = array(
    'path' => $node->{$this->fieldImageName}[LANGUAGE_NONE][$delta]['uri'],
    'width' => 40,
    'height' => 20,
  );

  // Add to the image its ALT attribute if there is any.
  if (!empty($node->{$this->fieldImageName}[LANGUAGE_NONE][$delta]['alt'])) {
    $image_info['alt'] = $node->{$this->fieldImageName}[LANGUAGE_NONE][$delta]['alt'];
  }

  // Add to the image its TITLE attribute if there is any.
  if (!empty($node->{$this->fieldImageName}[LANGUAGE_NONE][$delta]['title'])) {
    $image_info['title'] = $node->{$this->fieldImageName}[LANGUAGE_NONE][$delta]['title'];
  }

  // Programmatically create the image markup.
  $default_image_output = theme('image', $image_info);

  // Create the HTML markup of the Link.
  // Parse the URL to separate its components: query, fragment, etc...
  $url = drupal_parse_url($node->{$this->fieldLinkName}[LANGUAGE_NONE][$delta]['url']);

  // Test fragment, query, rel, class, title and target attributes.
  $options = array(
    'html' => TRUE,
    'fragment' => $url['fragment'],
    'query' => $url['query'],
    'attributes' => array(),
  );

  // Watchout: the order of the attributes is important.
  // Add to the link its TARGET attribute if there is any.
  if (!empty($node->{$this->fieldLinkName}[LANGUAGE_NONE][$delta]['attributes']['target'])) {
    $options['attributes']['target'] = $node->{$this->fieldLinkName}[LANGUAGE_NONE][$delta]['attributes']['target'];
  }

  // Add to the link its TITLE attribute if there is any.
  if (!empty($node->{$this->fieldLinkName}[LANGUAGE_NONE][$delta]['attributes']['title'])) {
    $options['attributes']['title'] = $node->{$this->fieldLinkName}[LANGUAGE_NONE][$delta]['attributes']['title'];
  }

  // Add to the link its REL attribute if there is any.
  if (!empty($link_field['settings']['attributes']['rel'])) {
    $options['attributes']['rel'] = $link_field['settings']['attributes']['rel'];
  }

  // Add to the link its CLASS attribute if there is any.
  if (!empty($link_field['settings']['attributes']['class'])) {
    $options['attributes']['class'] = $link_field['settings']['attributes']['class'];
  }

  // Programmatically create the markup for the image with the link.
  $link_output = l($default_image_output, $url['path'], $options);

  // Check if the image link formatter generated the expected markup.
  $this
    ->assertRaw($link_output, format_string("!message</br>The <em>Image Link Formatter</em> markup found was:<br/><pre>@link_output</pre>", array(
    '!message' => $message,
    '@link_output' => $link_output,
  )));

  // Print the markup output, just for debugging purposes.
  $this
    ->verbose(t("The <em>Image Link Formatter</em> markup found was:<br/><pre>!link_output</pre>", array(
    '!link_output' => $link_output,
  )));
}