You are here

public function JuiceboxFieldFormatterCase::testFieldFormatterConf in Juicebox HTML5 Responsive Image Galleries 7.2

Test configuration options that are specific to the Juicebox field formatter.

File

tests/JuiceboxFieldFormatterCase.test, line 70
Test case for Juicebox field formatter.

Class

JuiceboxFieldFormatterCase
Class to define test case for Juicebox field formatter.

Code

public function testFieldFormatterConf() {
  $instance = $this->instance;
  $node = $this->node;

  // Alter field formatter specific settings to contain custom values.
  $this
    ->drupalPostAJAX('admin/structure/types/manage/' . $instance['bundle'] . '/display', array(), $instance['field_name'] . '_formatter_settings_edit', NULL, array(), array(), 'field-ui-display-overview-form');
  $edit = array(
    'fields[' . $instance['field_name'] . '][settings_edit_form][settings][image_style]' => '',
    'fields[' . $instance['field_name'] . '][settings_edit_form][settings][thumb_style]' => 'thumbnail',
    'fields[' . $instance['field_name'] . '][settings_edit_form][settings][caption_source]' => 'alt',
    'fields[' . $instance['field_name'] . '][settings_edit_form][settings][title_source]' => 'title',
  );
  $this
    ->drupalPost(NULL, $edit, t('Save'));
  $this
    ->assertText(t('Your settings have been saved.'), 'Gallery configuration changes saved.');

  // Get the urls to the image and thumb derivatives expected.
  $items = field_get_items('node', $node, $instance['field_name']);
  $item = reset($items);
  $test_formatted_image_url = file_create_url($item['uri']);
  $test_formatted_thumb_url = image_style_url('thumbnail', $item['uri']);

  // Check for correct embed markup.
  $this
    ->drupalGet('node/' . $node->nid);
  $this
    ->assertRaw(check_plain($test_formatted_image_url), 'Test styled image found in embed code');

  // Check for correct XML.
  $this
    ->drupalGet('juicebox/xml/field/node/' . $node->nid . '/' . $instance['field_name'] . '/full');
  $this
    ->assertRaw('imageURL="' . check_plain($test_formatted_image_url), 'Test styled image found in XML.');
  $this
    ->assertRaw('thumbURL="' . check_plain($test_formatted_thumb_url), 'Test styled thumbnail found in XML.');

  // Note the intended title and caption text does not contain any block-level
  // tags as long as the global title and caption output filter is working.
  // So this acts as a test for that feature as well.
  $this
    ->assertRaw('<title><![CDATA[Some title text for field ' . $instance['field_name'] . ' on node ' . $node->nid . ']]></title>', 'Image title text found in XML');
  $this
    ->assertRaw('<caption><![CDATA[Some alt text for field ' . $instance['field_name'] . ' on node ' . $node->nid . ' &lt;strong&gt;with formatting&lt;/strong&gt;]]></caption>', 'Image caption text found in XML');

  // Now that we have title and caption data set, also ensure this text can
  // be found in search results. First we update the search index by marking
  // our test node as dirty and running cron.
  $this
    ->drupalPost('node/' . $node->nid . '/edit', NULL, t('Save'));
  $this
    ->cronRun();
  $this
    ->drupalPost('search', array(
    'keys' => '"Some title text"',
  ), t('Search'));
  $this
    ->assertText('Test Juicebox Gallery Node', 'Juicebox node found in search for title text.');

  // The Juicebox javascript should have been excluded from the search results
  // page.
  $this
    ->assertNoRaw('"configUrl":"', 'Juicebox Drupal.settings vars not included on search result page.');
}