Commit 43882bc2 authored by Sam152's avatar Sam152 Committed by frjo
Browse files

Issue #2642514 by Sam152: Create a basic integration test to ensure the colorbox library is loaded

parent 3b134876
custom: custom:
style: 'default' style: 'default'
activate: '0' activate: false
transition_type: 'elastic' transition_type: 'elastic'
transition_speed: '350' transition_speed: 350
opacity: '0.85' opacity: 0.85
text_current: '{current} of {total}' text_current: '{current} of {total}'
text_previous: '« Prev' text_previous: '« Prev'
text_next: 'Next »' text_next: 'Next »'
...@@ -16,18 +16,15 @@ custom: ...@@ -16,18 +16,15 @@ custom:
fixed: TRUE fixed: TRUE
scrolling: TRUE scrolling: TRUE
slideshow: slideshow:
slideshow: '0' slideshow: false
auto: TRUE auto: TRUE
speed: '2500' speed: 2500
text_start: 'start slideshow' text_start: 'start slideshow'
text_stop: 'stop slideshow' text_stop: 'stop slideshow'
advanced: advanced:
unique_token: '1' unique_token: 1
mobile_detect: '1' mobile_detect: 1
mobile_device_width: '480px' mobile_device_width: '480px'
caption_trim: '0' caption_trim: 0
caption_trim_length: '75' caption_trim_length: 75
compression_type: 'minified' compression_type: 'minified'
insert:
image_style: ''
insert_gallery: '0'
colorbox.settings: field.formatter.settings.colorbox:
type: mapping type: mapping
label: 'Entity reference field formatter settings.'
mapping:
colorbox_node_style:
type: string
label: 'Node Style'
colorbox_node_style_first:
type: boolean
label: 'Node style first'
colorbox_image_style:
type: string
label: 'Image style'
colorbox_gallery:
type: string
label: 'Gallery'
colorbox_gallery_custom:
type: string
label: 'Gallery custom'
colorbox_caption:
type: string
label: 'Caption'
colorbox_caption_custom:
type: string
label: 'Caption custom'
colorbox.settings:
type: config_object
label: 'Colorbox settings' label: 'Colorbox settings'
mapping: mapping:
custom: custom:
style: type: mapping
type: string label: Custom Settings
label: 'Style' mapping:
activate: style:
type: integer type: string
label: 'Options' label: 'Style'
transition_type: activate:
type: string type: boolean
label: 'Transition type' label: 'Options'
transition_speed: transition_type:
type: integer type: string
label: 'Transition speed' label: 'Transition type'
opacity: transition_speed:
type: float type: integer
label: 'Opacity' label: 'Transition speed'
text_current: opacity:
type: text type: float
label: 'Current' label: 'Opacity'
text_previous: text_current:
type: text type: text
label: 'Previous' label: 'Current'
text_next: text_previous:
type: text type: text
label: 'Next' label: 'Previous'
text_close: text_next:
type: text type: text
label: 'Close' label: 'Next'
maxwidth: text_close:
type: text type: text
label: 'Max width' label: 'Close'
maxheight: maxwidth:
type: text type: text
label: 'Max height' label: 'Max width'
initialwidth: maxheight:
type: text type: text
label: 'Initial width' label: 'Max height'
initialheight: initialwidth:
type: text type: text
label: 'Initial height' label: 'Initial width'
overlayclose: initialheight:
type: boolean type: text
label: 'Overlay close' label: 'Initial height'
fixed: overlayclose:
type: boolean type: boolean
label: 'Fixed' label: 'Overlay close'
scrolling: fixed:
type: boolean type: boolean
label: 'Scrollbars' label: 'Fixed'
slideshow: scrolling:
type: mapping type: boolean
label: 'Slideshow' label: 'Scrollbars'
mapping: slideshow:
slideshow: type: mapping
type: boolean label: 'Slideshow'
label: 'Slideshow' mapping:
auto: slideshow:
type: boolean type: boolean
label: 'Slideshow autostart' label: 'Slideshow'
speed: auto:
type: integer type: boolean
label: 'Slideshow speed' label: 'Slideshow autostart'
text_start: speed:
type: text type: integer
label: 'Start slideshow' label: 'Slideshow speed'
text_stop: text_start:
type: text type: text
label: 'Stop slideshow' label: 'Start slideshow'
text_stop:
type: text
label: 'Stop slideshow'
advanced: advanced:
type: mapping type: mapping
label: 'Advanced settings' label: 'Advanced settings'
......
<?php
/**
* @file
* Contains \Drupal\colorbox\Tests\Colorbox.
*/
namespace Drupal\colorbox\Tests;
use Drupal\image\Tests\ImageFieldTestBase;
/**
* Test the colorbox module.
*
* @group colorbox
*/
class Colorbox extends ImageFieldTestBase {
/**
* Modules to enable.
*
* @var array
*/
public static $modules = [
'colorbox',
'field_test',
'node',
'field_ui',
'image'
];
/**
* The field name used in the test.
*
* @var string
*/
protected $fieldName = 'field_colorbox_test';
/**
* The content type used in the test.
*
* @var string
*/
protected $contentType = 'article';
/**
* The node ID with an uploaded image, ready for testing.
*
* @var int
*/
protected $testNid;
/**
* {@inheritdoc}
*/
protected function setUp() {
parent::setUp();
$this->createImageField($this->fieldName, $this->contentType, ['uri_scheme' => 'public'], ['alt_field_required' => 0]);
entity_get_display('node', $this->contentType, 'default')
->setComponent($this->fieldName, [
'type' => 'colorbox',
'settings' => [],
])
->save();
$this->drupalGet('node/add/article');
$test_image = current($this->drupalGetTestFiles('image'));
$this->testNid = $this->uploadNodeImage($test_image, $this->fieldName, 'article', '');
}
/**
* Test the colorbox formatter.
*/
public function testColorboxFormatter() {
$this->drupalGet('node/' . $this->testNid);
// Ensure all the relevant colorbox JavaScript is loaded on the page.
$this->assertScript('libraries/colorbox/jquery.colorbox-min.js');
$this->assertScript('modules/colorbox/styles/default/colorbox_style.js');
$this->assertScript('modules/colorbox/js/colorbox.js');
// Ensure the image appears with the relevant colorbox markup.
$this->assertRaw('rel="gallery-article-1" class="colorbox"');
// The script should not appear by default on the homepage.
$this->drupalGet('<front>');
$this->assertScript('libraries/colorbox/jquery.colorbox-min.js', FALSE);
}
/**
* Assert a script is appearing in the document.
*
* @param string $script_url
* The script URL to assert
* @pararm bool $exists
* A flag to indicate if the script should exist or not exist for a pass.
*/
public function assertScript($script_url, $exists = TRUE) {
$version = \Drupal::VERSION;
$this->{$exists ? 'assertRaw' : 'assertNoRaw'}("<script src=\"{$GLOBALS['base_url']}/$script_url?v=$version\"></script>");
}
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment