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:
style: 'default'
activate: '0'
activate: false
transition_type: 'elastic'
transition_speed: '350'
opacity: '0.85'
transition_speed: 350
opacity: 0.85
text_current: '{current} of {total}'
text_previous: '« Prev'
text_next: 'Next »'
......@@ -16,18 +16,15 @@ custom:
fixed: TRUE
scrolling: TRUE
slideshow:
slideshow: '0'
slideshow: false
auto: TRUE
speed: '2500'
speed: 2500
text_start: 'start slideshow'
text_stop: 'stop slideshow'
advanced:
unique_token: '1'
mobile_detect: '1'
unique_token: 1
mobile_detect: 1
mobile_device_width: '480px'
caption_trim: '0'
caption_trim_length: '75'
caption_trim: 0
caption_trim_length: 75
compression_type: 'minified'
insert:
image_style: ''
insert_gallery: '0'
colorbox.settings:
field.formatter.settings.colorbox:
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'
mapping:
custom:
type: mapping
label: Custom Settings
mapping:
style:
type: string
label: 'Style'
activate:
type: integer
type: boolean
label: 'Options'
transition_type:
type: string
......
<?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