You are here

public function JuiceboxConfCase::testConfigLite in Juicebox HTML5 Responsive Image Galleries 8.2

Same name and namespace in other branches
  1. 8.3 tests/src/Functional/JuiceboxConfCase.php \Drupal\Tests\juicebox\Functional\JuiceboxConfCase::testConfigLite()

Test common Lite configuration logic for a Juicebox formatter.

File

tests/src/Functional/JuiceboxConfCase.php, line 52

Class

JuiceboxConfCase
Tests gallery-specific configuration logic for Juicebox galleries.

Namespace

Drupal\Tests\juicebox\Functional

Code

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

  // Check control case as anon user without custom configuration. This will
  // also prime the cache in order to test cache tag invalidation once the
  // settings are altered.
  $this
    ->drupalGet('node/' . $node
    ->id());
  $this
    ->assertRaw(trim(json_encode([
    'gallerywidth' => '100%',
    'galleryheight' => '100%',
    'backgroundcolor' => '#222222',
  ]), '{}'), 'Expected default configuration options found in Drupal.settings.');
  $this
    ->drupalGet('juicebox/xml/field/node/' . $node
    ->id() . '/' . $this->instFieldName . '/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
    ->drupalLogin($this->webUser);
  $this
    ->drupalGet('admin/structure/types/manage/' . $this->instBundle . '/display');
  $this
    ->submitForm([], $this->instFieldName . '_settings_edit', 'entity-view-display-edit-form');
  $edit = [
    'fields[' . $this->instFieldName . '][settings_edit_form][settings][jlib_galleryWidth]' => '50%',
    'fields[' . $this->instFieldName . '][settings_edit_form][settings][jlib_galleryHeight]' => '200px',
    'fields[' . $this->instFieldName . '][settings_edit_form][settings][jlib_backgroundColor]' => 'red',
    'fields[' . $this->instFieldName . '][settings_edit_form][settings][jlib_textColor]' => 'green',
    'fields[' . $this->instFieldName . '][settings_edit_form][settings][jlib_thumbFrameColor]' => 'blue',
    'fields[' . $this->instFieldName . '][settings_edit_form][settings][jlib_showOpenButton]' => FALSE,
    'fields[' . $this->instFieldName . '][settings_edit_form][settings][jlib_showExpandButton]' => FALSE,
    'fields[' . $this->instFieldName . '][settings_edit_form][settings][jlib_showThumbsButton]' => FALSE,
    'fields[' . $this->instFieldName . '][settings_edit_form][settings][jlib_useThumbDots]' => TRUE,
    'fields[' . $this->instFieldName . '][settings_edit_form][settings][jlib_useFullscreenExpand]' => TRUE,
  ];
  $this
    ->submitForm($edit, 'Save');
  $this
    ->assertText(t('Your settings have been saved.'), 'Gallery configuration changes saved.');

  // Now check the resulting XML again as an anon user.
  $this
    ->drupalLogout();

  // Check for correct embed markup.
  $this
    ->drupalGet('node/' . $node
    ->id());
  $this
    ->assertRaw(trim(json_encode([
    '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
    ->id() . '/' . $this->instFieldName . '/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.');
}