View source
<?php
namespace Drupal\Tests\juicebox\Functional;
use Drupal\file\Entity\File;
use Drupal\Component\Utility\Html;
class JuiceboxConfGlobalCase 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 testGlobalConf() {
$node = $this->node;
$this
->drupalGet('juicebox/xml/field/node/' . $node
->id() . '/' . $this->instFieldName . '/full');
$this
->assertResponse(200, 'Control request of XML was successful.');
$this
->drupalLogin($this->webUser);
$edit = [
'enable_cors' => TRUE,
];
$this
->drupalGet('admin/config/media/juicebox');
$this
->submitForm($edit, 'Save configuration');
$this
->assertText(t('The Juicebox configuration options have been saved'), 'Custom global options saved.');
$this
->drupalLogout();
$this
->drupalGet('juicebox/xml/field/node/' . $node
->id() . '/' . $this->instFieldName . '/full');
$this
->assertEqual($this
->drupalGetHeader('Access-Control-Allow-Origin'), '*', 'Expected CORS header found.');
}
public function voidtestGlobalTrans() {
$node = $this->node;
$this
->drupalGet('juicebox/xml/field/node/' . $node
->id() . '/' . $this->instFieldName . '/full');
$this
->assertResponse(200, 'Control request of XML was successful.');
$this
->drupalLogin($this->webUser);
$edit = [
'locale_translate_english' => TRUE,
];
$this
->drupalGet('admin/config/regional/language/edit/en');
$this
->submitForm($edit, 'Save language');
$edit = [
'translate_interface' => TRUE,
'base_languagelist' => 'Show Thumbnails|Hide Thumbnails|Expand Gallery|Close Gallery|Open Image in New Window',
];
$this
->drupalGet('admin/config/media/juicebox');
$this
->submitForm($edit, 'Save configuration');
$this
->assertText(t('The Juicebox configuration options have been saved'), 'Custom global options saved.');
$this
->drupalGet('node/' . $node
->id());
$edit = [
'string' => 'Show Thumbnails|Hide Thumbnails|Expand Gallery|Close Gallery|Open Image in New Window',
];
$this
->drupalGet('admin/config/media/juicebox');
$this
->submitForm($edit, 'Filter');
$matches = [];
$this
->assertTrue(preg_match('/name="strings\\[([0-9]+)\\]\\[translations\\]\\[0\\]"/', $this
->getRawContent(), $matches), 'Languagelist base string is available for translation.');
$edit = [
'strings[' . $matches[1] . '][translations][0]' => 'Translated|Lang|List',
];
$this
->submitForm($edit, 'Save translations');
$this
->assertText(t('The strings have been saved'), 'Languagelist translation saved.');
$this
->drupalLogout();
$this
->drupalGet('juicebox/xml/field/node/' . $node
->id() . '/' . $this->instFieldName . '/full');
$this
->assertRaw('languagelist="Translated|Lang|List"', 'Translated languagelist value found in XML.');
}
public function testGlobalMultisize() {
$node = $this->node;
$this
->drupalGet('juicebox/xml/field/node/' . $node
->id() . '/' . $this->instFieldName . '/full');
$this
->assertResponse(200, 'Control request of XML was successful.');
$this
->drupalLogin($this->webUser);
$edit = [
'juicebox_multisize_large' => 'large',
];
$this
->drupalGet('admin/config/media/juicebox');
$this
->submitForm($edit, 'Save configuration');
$this
->assertText(t('The Juicebox configuration options have been saved'), 'Custom global options saved.');
$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_multisize',
];
$this
->submitForm($edit, 'Save');
$this
->assertText(t('Your settings have been saved.'), 'Gallery configuration changes saved.');
$uri = File::load($node->{$this->instFieldName}[0]->target_id)
->getFileUri();
$formatted_image_small = entity_load('image_style', 'juicebox_small')
->buildUrl($uri);
$formatted_image_medium = entity_load('image_style', 'juicebox_medium')
->buildUrl($uri);
$formatted_image_large = entity_load('image_style', 'large')
->buildUrl($uri);
$this
->drupalLogout();
$this
->drupalGet('juicebox/xml/field/node/' . $node
->id() . '/' . $this->instFieldName . '/full');
$this
->assertRaw('smallImageURL="' . Html::escape($formatted_image_small), 'Test small image found in XML.');
$this
->assertRaw('imageURL="' . Html::escape($formatted_image_medium), 'Test medium image found in XML.');
$this
->assertRaw('largeImageURL="' . Html::escape($formatted_image_large), 'Test large image found in XML.');
}
}