View source
<?php
namespace Drupal\Tests\juicebox\Functional;
use Drupal\file\Entity\File;
use Drupal\Component\Utility\Html;
class JuiceboxConfCase extends JuiceboxCaseTestBase {
public static $modules = [
'node',
'field_ui',
'image',
'juicebox',
];
public function setUp() {
parent::setUp();
$this->webUser = $this
->drupalCreateUser([
'access content',
'access administration pages',
'administer site configuration',
'administer content types',
'administer nodes',
'administer node fields',
'administer node display',
'bypass node access',
]);
$this
->drupalLogin($this->webUser);
$this
->initNode();
$this
->activateJuiceboxFieldFormatter();
$this
->createNodeWithFile();
$this
->drupalLogout();
}
public function testConfigLite() {
$node = $this->node;
$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.');
$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.');
$this
->drupalLogout();
$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.');
$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.');
}
public function testConfigPro() {
$node = $this->node;
$this
->drupalGet('node/' . $node
->id());
$this
->assertResponse(200, 'Control request of test node was successful.');
$this
->drupalGet('juicebox/xml/field/node/' . $node
->id() . '/' . $this->instFieldName . '/full');
$this
->assertResponse(200, 'Control request of XML was successful.');
$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_showExpandButton]' => FALSE,
'fields[' . $this->instFieldName . '][settings_edit_form][settings][manual_config]' => "sHoWoPeNbUtToN=\"FALSE\"\nshowexpandbutton=\"TRUE\"\ngallerywidth=\"50%\"\nmyCustomSetting=\"boomsauce\"",
];
$this
->submitForm($edit, 'Save');
$this
->assertText(t('Your settings have been saved.'), 'Gallery configuration changes saved.');
$this
->drupalLogout();
$this
->drupalGet('node/' . $node
->id());
$this
->assertRaw(trim(json_encode([
'gallerywidth' => '50%',
'galleryheight' => '100%',
'backgroundcolor' => '#222222',
]), '{}'), 'Expected custom configuration options found in Drupal.settings.');
$this
->drupalGet('juicebox/xml/field/node/' . $node
->id() . '/' . $this->instFieldName . '/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.');
}
public function testConfigAdvanced() {
$node = $this->node;
$uri = File::load($node->{$this->instFieldName}[0]->target_id)
->getFileUri();
$test_image_url = file_create_url($uri);
$test_image_url_formatted = entity_load('image_style', 'juicebox_medium')
->buildUrl($uri);
$this
->drupalGet('juicebox/xml/field/node/' . $node
->id() . '/' . $this->instFieldName . '/full');
$this
->assertRaw('linkTarget="_blank"', 'Default linkTarget setting found.');
$this
->assertRaw('linkURL="' . $test_image_url, 'Test unstyled image found in XML');
$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][image_style]' => 'juicebox_medium',
'fields[' . $this->instFieldName . '][settings_edit_form][settings][linkurl_source]' => 'image_styled',
'fields[' . $this->instFieldName . '][settings_edit_form][settings][linkurl_target]' => '_self',
'fields[' . $this->instFieldName . '][settings_edit_form][settings][custom_parent_classes]' => 'my-custom-wrapper',
];
$this
->submitForm($edit, 'Save');
$this
->assertText(t('Your settings have been saved.'), 'Gallery configuration changes saved.');
$this
->drupalLogout();
$this
->drupalGet('juicebox/xml/field/node/' . $node
->id() . '/' . $this->instFieldName . '/full');
$this
->assertRaw('linkTarget="_self"', 'Updated linkTarget setting found in XML.');
$this
->assertRaw('linkURL="' . Html::escape($test_image_url_formatted), 'Test styled image found in XML for linkURL.');
$this
->drupalGet('node/' . $node
->id());
$this
->assertRaw('class="juicebox-parent my-custom-wrapper"', 'Custom class found in embed code.');
}
}