JuiceboxConfCase.test in Juicebox HTML5 Responsive Image Galleries 7.2
Test case for gallery-specific Juicebox configuration options.
File
tests/JuiceboxConfCase.testView source
<?php
/**
* @file
* Test case for gallery-specific Juicebox configuration options.
*/
/**
* Class to define test case for gallery-specific Juicebox configuration
* options.
*/
class JuiceboxConfCase extends JuiceboxBaseCase {
/**
* Define test case info.
*/
public static function getInfo() {
return array(
'name' => 'Juicebox gallery configuration tests',
'description' => 'Tests gallery-specific configuration logic for Juicebox galleries.',
'group' => 'Juicebox',
);
}
/**
* Define setup tasks.
*/
public function setUp() {
parent::setUp('juicebox');
// Create and login user.
$this->webUser = $this
->drupalCreateUser(array(
'access content',
'access administration pages',
'administer site configuration',
'administer content types',
'administer nodes',
'create article content',
'edit any article content',
'delete any article content',
'administer image styles',
'administer fields',
));
$this
->drupalLogin($this->webUser);
// Prep an article with an image field and activate the Juicebox display
// formatter for it.
$this
->prepArticle();
$this
->activateJuiceboxFieldFormatter($this->instance);
}
/**
* Test common Lite configuration logic for a Juicebox formatter.
*/
public function testConfigLite() {
$instance = $this->instance;
$node = $this->node;
// Check control case without custom configuration.
$this
->drupalGet('node/' . $node->nid);
$this
->assertRaw(trim(json_encode(array(
'gallerywidth' => '100%',
'galleryheight' => '100%',
'backgroundcolor' => '#222222',
)), '{}'), 'Expected default configuration options found in Drupal.settings.');
$this
->drupalGet('juicebox/xml/field/node/' . $node->nid . '/' . $instance['field_name'] . '/full');
$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.');
// Alter 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][jlib_galleryWidth]' => '50%',
'fields[' . $instance['field_name'] . '][settings_edit_form][settings][jlib_galleryHeight]' => '200px',
'fields[' . $instance['field_name'] . '][settings_edit_form][settings][jlib_backgroundColor]' => 'red',
'fields[' . $instance['field_name'] . '][settings_edit_form][settings][jlib_textColor]' => 'green',
'fields[' . $instance['field_name'] . '][settings_edit_form][settings][jlib_thumbFrameColor]' => 'blue',
'fields[' . $instance['field_name'] . '][settings_edit_form][settings][jlib_showOpenButton]' => FALSE,
'fields[' . $instance['field_name'] . '][settings_edit_form][settings][jlib_showExpandButton]' => FALSE,
'fields[' . $instance['field_name'] . '][settings_edit_form][settings][jlib_showThumbsButton]' => FALSE,
'fields[' . $instance['field_name'] . '][settings_edit_form][settings][jlib_useThumbDots]' => TRUE,
'fields[' . $instance['field_name'] . '][settings_edit_form][settings][jlib_useFullscreenExpand]' => TRUE,
);
$this
->drupalPost(NULL, $edit, t('Save'));
$this
->assertText(t('Your settings have been saved.'), 'Gallery configuration changes saved.');
// Check for correct embed markup.
$this
->drupalGet('node/' . $node->nid);
$this
->assertRaw(trim(json_encode(array(
'gallerywidth' => '50%',
'galleryheight' => '200px',
'backgroundcolor' => 'red',
)), '{}'), 'Expected custom Lite configuration options found in Drupal.settings.');
// Check for correct XML.
$this
->drupalGet('juicebox/xml/field/node/' . $node->nid . '/' . $instance['field_name'] . '/full');
$this
->assertRaw('<juicebox gallerywidth="50%" galleryheight="200px" backgroundcolor="red" textcolor="green" thumbframecolor="blue" showopenbutton="FALSE" showexpandbutton="FALSE" showthumbsbutton="FALSE" usethumbdots="TRUE" usefullscreenexpand="TRUE">', 'Expected custom Lite configuration options set in XML.');
}
/**
* Test common Pro configuration logic for a Juicebox formatter.
*/
public function testConfigPro() {
$instance = $this->instance;
$node = $this->node;
// Set new manual options and also add a manual customization that's
// intended to override a custom Lite option.
$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][jlib_showExpandButton]' => FALSE,
'fields[' . $instance['field_name'] . '][settings_edit_form][settings][manual_config]' => "sHoWoPeNbUtToN=\"FALSE\"\nshowexpandbutton=\"TRUE\"\ngallerywidth=\"50%\"\nmyCustomSetting=\"boomsauce\"",
);
$this
->drupalPost(NULL, $edit, t('Save'));
$this
->assertText(t('Your settings have been saved.'), 'Gallery configuration changes saved.');
// Check for correct embed markup.
$this
->drupalGet('node/' . $node->nid);
$this
->assertRaw(trim(json_encode(array(
'gallerywidth' => '50%',
'galleryheight' => '100%',
'backgroundcolor' => '#222222',
)), '{}'), 'Expected custom configuration options found in Drupal.settings.');
// Check for correct XML.
$this
->drupalGet('juicebox/xml/field/node/' . $node->nid . '/' . $instance['field_name'] . '/full');
$this
->assertRaw('<juicebox gallerywidth="50%" galleryheight="100%" backgroundcolor="#222222" textcolor="rgba(255,255,255,1)" thumbframecolor="rgba(255,255,255,.5)" showopenbutton="FALSE" showexpandbutton="TRUE" showthumbsbutton="TRUE" usethumbdots="FALSE" usefullscreenexpand="FALSE" mycustomsetting="boomsauce">', 'Expected custom Pro configuration options set in XML.');
}
/**
* Test common Advanced configuration logic for a Juicebox formatter.
*/
public function testConfigAdvanced() {
$instance = $this->instance;
$node = $this->node;
// Get the urls to the main image with and without "large" styling.
$items = field_get_items('node', $node, $instance['field_name']);
$item = reset($items);
$test_image_url = file_create_url($item['uri']);
$test_image_url_formatted = image_style_url('medium', $item['uri']);
// Check control case without custom configuration.
$this
->drupalGet('juicebox/xml/field/node/' . $node->nid . '/' . $instance['field_name'] . '/full');
$this
->assertRaw('linkTarget="_blank"', 'Default linkTarget setting found.');
$this
->assertRaw('linkURL="' . $test_image_url, 'Test unstyled image found in XML');
// Set new advanced options.
$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]' => 'medium',
'fields[' . $instance['field_name'] . '][settings_edit_form][settings][linkurl_source]' => 'image_styled',
'fields[' . $instance['field_name'] . '][settings_edit_form][settings][linkurl_target]' => '_self',
'fields[' . $instance['field_name'] . '][settings_edit_form][settings][custom_parent_classes]' => 'my-custom-wrapper',
);
$this
->drupalPost(NULL, $edit, t('Save'));
$this
->assertText(t('Your settings have been saved.'), 'Gallery configuration changes saved.');
// Check case with custom configuration.
$this
->drupalGet('juicebox/xml/field/node/' . $node->nid . '/' . $instance['field_name'] . '/full');
$this
->assertRaw('linkTarget="_self"', 'Updated linkTarget setting found in XML.');
$this
->assertRaw('linkURL="' . check_plain($test_image_url_formatted), 'Test styled image found in XML for linkURL.');
// Also check for custom class in embed code.
$this
->drupalGet('node/' . $node->nid);
$this
->assertRaw('class="juicebox-parent my-custom-wrapper"', 'Custom class found in embed code.');
}
}
Classes
Name | Description |
---|---|
JuiceboxConfCase | Class to define test case for gallery-specific Juicebox configuration options. |