You are here

public function JuiceboxFileCase::testFile in Juicebox HTML5 Responsive Image Galleries 7.2

Test the field formatter with a file field and file upload widget.

File

tests/JuiceboxFileCase.test, line 37
Test case for Juicebox file handling.

Class

JuiceboxFileCase
Class to define test case for Juicebox file handling.

Code

public function testFile() {

  // Setup a content type with image data. Use the "file" type and widget.
  $instance = $this
    ->initFieldInstance('article', strtolower($this
    ->randomName(10)), 'file', 'file_generic');
  $this
    ->activateJuiceboxFieldFormatter($instance);

  // Create a new node with an image attached.
  $test_image = current($this
    ->drupalGetTestFiles('image'));
  $node = $this
    ->createNodeWithImage($instance, $test_image);
  $xml_path = 'juicebox/xml/field/node/' . $node->nid . '/' . $instance['field_name'] . '/full';

  // Get raw file data expected in the node.
  $items = field_get_items('node', $node, $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('node/' . $node->nid);
  $this
    ->assertRaw(trim(json_encode(array(
    'configUrl' => url($xml_path),
  )), '{}"'), 'Gallery setting found in Drupal.settings.');
  $this
    ->assertRaw('id="field--node--' . $node->nid . '--' . str_replace('_', '-', $instance['field_name']) . '--full"', 'Embed code wrapper 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.');
  $this
    ->assertRaw('<juicebox gallerywidth="100%" galleryheight="100%" backgroundcolor="#222222" textcolor="rgba(255,255,255,1)" thumbframecolor="rgba(255,255,255,.5)" showopenbutton="TRUE" showexpandbutton="TRUE" showthumbsbutton="TRUE" usethumbdots="FALSE" usefullscreenexpand="FALSE">', 'Expected default configuration options set in XML.');
}