You are here

public function JuiceboxViewsCase::testViews in Juicebox HTML5 Responsive Image Galleries 7.2

Test using pre-packaged base Juicebox view.

File

tests/JuiceboxViewsCase.test, line 41
Test case for integration with File Entity module.

Class

JuiceboxViewsCase
Class to define test case for integration with File Entity module.

Code

public function testViews() {
  $xml_path = 'juicebox/xml/viewsstyle/juicebox_views_test/page';

  // Get the urls to the test image and thumb derivative used by default.
  $items = field_get_items('node', $this->node, $this->instance['field_name']);
  $item = reset($items);
  $test_image_url = image_style_url('juicebox_medium', $item['uri']);
  $test_thumb_url = image_style_url('juicebox_square_thumbnail', $item['uri']);

  // Check for correct embed markup.
  $this
    ->drupalGet('juicebox-views-test');
  $this
    ->assertRaw(trim(json_encode(array(
    'configUrl' => url($xml_path),
  )), '{}"'), 'Gallery setting found in Drupal.settings.');
  $this
    ->assertRaw('id="viewsstyle--juicebox-views-test--page"', 'Embed code wrapper found.');
  $this
    ->assertRaw('<li class="gallery_config', 'Example contextual link for gallery configuration found.');
  $this
    ->assertRaw(check_plain($test_image_url), 'Test image found in embed code');

  // Check for correct XML.
  $this
    ->drupalGet($xml_path);
  $this
    ->assertRaw('<?xml version="1.0" encoding="UTF-8"?>', 'Valid XML detected.');
  $this
    ->assertRaw('imageURL="' . check_plain($test_image_url), 'Test image found in XML.');
  $this
    ->assertRaw('thumbURL="' . check_plain($test_thumb_url), 'Test thumbnail found in XML.');

  // The node's title and body are mapped to the image title and caption. Most
  // formatting should be maintained in the caption because it's based on
  // a body field (with default settings to use "filtered html" text format).
  // Note however that our Juicebox markup filter should have stripped the
  // block-level p tags that were *added* by default by the text format.
  $this
    ->assertRaw('<title><![CDATA[' . $this->node->title . ']]></title>', 'Image title text found in XML.');
  $this
    ->assertRaw('<caption><![CDATA[Some body content on node ' . $this->node->nid . ' <strong>with formatting</strong>]]></caption>', 'Image caption text found in XML.');

  // Now test the toggle for the Juicebox markup filter.
  $edit = array(
    'juicebox_apply_markup_filter' => FALSE,
  );
  $this
    ->drupalPost('admin/config/media/juicebox', $edit, t('Save configuration'));

  // With the filter off, the p tags in our example caption should come
  // through.
  $this
    ->drupalGet($xml_path);
  $this
    ->assertRaw('<p>Some body content on node ' . $this->node->nid . ' <strong>with formatting</strong></p>', 'Formatted image caption text found in XML.');
}