Commit 1902e884 authored by Primsi's avatar Primsi Committed by Primsi

Issue #3086881 by Primsi, Berdir: Add test coverage to eb_widget

parent 0a9c56f0
# This is the DrupalCI testbot build file for Drupal core.
# Learn to make one for your own drupal.org project:
# https://www.drupal.org/drupalorg/docs/drupal-ci/customizing-drupalci-testing
build:
assessment:
validate_codebase:
phplint:
csslint:
halt-on-fail: false
eslint:
# A test must pass eslinting standards check in order to continue processing.
halt-on-fail: false
phpcs:
# phpcs will use core's specified version of Coder.
sniff-all-files: false
halt-on-fail: false
testing:
container_command:
commands: "cd ${SOURCE_DIR} &&
sudo -u www-data mkdir libraries &&
sudo -u www-data curl https://codeload.github.com/enyo/dropzone/tar.gz/v5.5.0 --output dropzone.tar.gz --silent &&
sudo -u www-data tar xzf dropzone.tar.gz &&
sudo -u www-data mv dropzone-5.5.0 libraries/dropzone"
halt-on-fail: true
# run_tests task is executed several times in order of performance speeds.
# halt-on-fail can be set on the run_tests tasks in order to fail fast.
# suppress-deprecations is false in order to be alerted to usages of
# deprecated code.
run_tests.phpunit:
types: 'PHPUnit-Unit'
testgroups: '--all'
suppress-deprecations: true
halt-on-fail: false
run_tests.kernel:
types: 'PHPUnit-Kernel'
testgroups: '--all'
suppress-deprecations: true
halt-on-fail: false
run_tests.simpletest:
types: 'Simpletest'
testgroups: '--all'
suppress-deprecations: true
halt-on-fail: false
run_tests.build:
types: 'PHPUnit-Build'
testgroups: '--all'
suppress-deprecations: true
halt-on-fail: false
run_tests.functional:
types: 'PHPUnit-Functional'
testgroups: '--all'
suppress-deprecations: true
halt-on-fail: false
run_tests.javascript:
concurrency: 15
types: 'PHPUnit-FunctionalJavascript'
testgroups: '--all'
suppress-deprecations: true
halt-on-fail: false
# Run nightwatch testing.
# @see https://www.drupal.org/project/drupal/issues/2869825
nightwatchjs:
# container_command.drupal_project_templates:
# commands:
# - "sudo -u www-data ${SOURCE_DIR}/core/tests/scripts/test_composer_project_templates.sh"
# halt-on-fail: true
langcode: en
status: true
dependencies:
config:
- field.field.media.dropzonejs_media.field_media_image
- image.style.thumbnail
- media.type.dropzonejs_media
module:
- image
- path
id: media.dropzonejs_media.default
targetEntityType: media
bundle: dropzonejs_media
mode: default
content:
created:
type: datetime_timestamp
weight: 10
region: content
settings: { }
third_party_settings: { }
field_media_image:
weight: 0
settings:
progress_indicator: throbber
preview_image_style: thumbnail
third_party_settings: { }
type: image_image
region: content
name:
type: string_textfield
weight: -5
region: content
settings:
size: 60
placeholder: ''
third_party_settings: { }
path:
type: path
weight: 30
region: content
settings: { }
third_party_settings: { }
status:
type: boolean_checkbox
settings:
display_label: true
weight: 100
region: content
third_party_settings: { }
uid:
type: entity_reference_autocomplete
weight: 5
settings:
match_operator: CONTAINS
size: 60
placeholder: ''
match_limit: 10
region: content
third_party_settings: { }
hidden: { }
uuid: cc12d4b9-9cb9-43d3-b92a-b6106b6df5f1
langcode: en
status: true
dependencies:
config:
- entity_browser.browser.dropzonejs_eb_test
- field.field.node.dropzonejs_test.field_dropzonejs_image
- node.type.dropzonejs_test
module:
- entity_browser
- path
id: node.dropzonejs_test.default
targetEntityType: node
bundle: dropzonejs_test
mode: default
content:
created:
type: datetime_timestamp
weight: 3
region: content
settings: { }
third_party_settings: { }
field_dropzonejs_image:
weight: 1
settings:
entity_browser: dropzonejs_eb_test
field_widget_display: label
open: true
selection_mode: selection_append
field_widget_edit: false
field_widget_remove: false
field_widget_replace: false
field_widget_display_settings: { }
third_party_settings: { }
type: entity_browser_entity_reference
region: content
path:
type: path
weight: 6
region: content
settings: { }
third_party_settings: { }
promote:
type: boolean_checkbox
settings:
display_label: true
weight: 4
region: content
third_party_settings: { }
status:
type: boolean_checkbox
settings:
display_label: true
weight: 7
region: content
third_party_settings: { }
sticky:
type: boolean_checkbox
settings:
display_label: true
weight: 5
region: content
third_party_settings: { }
title:
type: string_textfield
weight: 0
region: content
settings:
size: 60
placeholder: ''
third_party_settings: { }
uid:
type: entity_reference_autocomplete
weight: 2
settings:
match_operator: CONTAINS
size: 60
placeholder: ''
match_limit: 10
region: content
third_party_settings: { }
hidden: { }
langcode: en
status: true
dependencies:
config:
- field.field.media.dropzonejs_media.field_media_image
- image.style.large
- media.type.dropzonejs_media
module:
- image
id: media.dropzonejs_media.default
targetEntityType: media
bundle: dropzonejs_media
mode: default
content:
field_media_image:
label: visually_hidden
weight: 0
settings:
image_style: large
image_link: ''
third_party_settings: { }
type: image
region: content
hidden:
created: true
name: true
thumbnail: true
uid: true
langcode: en
status: true
dependencies:
config:
- field.field.node.dropzonejs_test.field_dropzonejs_image
- node.type.dropzonejs_test
module:
- user
id: node.dropzonejs_test.default
targetEntityType: node
bundle: dropzonejs_test
mode: default
content:
field_dropzonejs_image:
type: entity_reference_entity_view
weight: 101
label: above
settings:
view_mode: default
link: false
third_party_settings: { }
region: content
links:
weight: 100
settings: { }
third_party_settings: { }
region: content
hidden: { }
langcode: en
status: true
dependencies:
config:
- media.type.dropzonejs_media
module:
- dropzonejs_eb_widget
- media
name: dropzonejs_eb_test
label: 'Dropzonejs eb test'
display: iframe
display_configuration:
width: '650'
height: '500'
link_text: 'Select entities'
auto_open: false
selection_display: no_display
selection_display_configuration: { }
widget_selector: single
widget_selector_configuration: { }
widgets:
44b1e6ea-637d-4dd6-b79e-edeefc546c1c:
settings:
media_type: dropzonejs_media
upload_location: 'public://'
dropzone_description: 'Drop files here to upload them'
max_filesize: 2M
extensions: 'jpg jpeg gif png txt doc xls pdf ppt pps odt ods odp'
clientside_resize: false
resize_width: null
resize_height: null
resize_quality: !!float 1
resize_method: contain
thumbnail_method: contain
submit_text: 'Select entities'
auto_select: false
uuid: 44b1e6ea-637d-4dd6-b79e-edeefc546c1c
weight: 2
label: 'Dropzonejs media'
id: dropzonejs_media_entity
langcode: en
status: true
dependencies:
config:
- field.storage.media.field_media_image
- media.type.dropzonejs_media
module:
- image
id: media.dropzonejs_media.field_media_image
field_name: field_media_image
entity_type: media
bundle: dropzonejs_media
label: Image
description: ''
required: true
translatable: true
default_value: { }
default_value_callback: ''
settings:
file_extensions: 'png gif jpg jpeg'
alt_field: true
alt_field_required: true
title_field: false
title_field_required: false
max_resolution: ''
min_resolution: ''
default_image:
uuid: null
alt: ''
title: ''
width: null
height: null
file_directory: '[date:custom:Y]-[date:custom:m]'
max_filesize: ''
handler: 'default:file'
handler_settings: { }
field_type: image
langcode: en
status: true
dependencies:
config:
- field.storage.node.field_dropzonejs_image
- media.type.dropzonejs_media
- node.type.dropzonejs_test
id: node.dropzonejs_test.field_dropzonejs_image
field_name: field_dropzonejs_image
entity_type: node
bundle: dropzonejs_test
label: Image
description: ''
required: false
translatable: false
default_value: { }
default_value_callback: ''
settings:
handler: 'default:media'
handler_settings:
target_bundles:
dropzonejs_media: dropzonejs_media
sort:
field: _none
auto_create: false
auto_create_bundle: ''
field_type: entity_reference
langcode: en
status: true
dependencies:
enforced:
module:
- media
module:
- file
- image
- media
_core:
default_config_hash: 7ZBrcl87ZXaw42v952wwcw_9cQgTBq5_5tgyUkE-VV0
id: media.field_media_image
field_name: field_media_image
entity_type: media
type: image
settings:
default_image:
uuid: null
alt: ''
title: ''
width: null
height: null
target_type: file
display_field: false
display_default: false
uri_scheme: public
module: image
locked: false
cardinality: 1
translatable: true
indexes: { }
persist_with_no_fields: false
custom_storage: false
langcode: en
status: true
dependencies:
module:
- media
- node
id: node.field_dropzonejs_image
field_name: field_dropzonejs_image
entity_type: node
type: entity_reference
settings:
target_type: media
module: core
locked: false
cardinality: 1
translatable: true
indexes: { }
persist_with_no_fields: false
custom_storage: false
langcode: en
status: true
dependencies: { }
id: dropzonejs_media
label: 'Dropzonejs media'
description: ''
source: image
queue_thumbnail_downloads: false
new_revision: false
source_configuration:
source_field: field_media_image
field_map: { }
langcode: en
status: true
dependencies:
module:
- menu_ui
third_party_settings:
menu_ui:
available_menus: { }
parent: ''
name: 'Dropzonejs test'
type: dropzonejs_test
description: ''
help: ''
new_revision: false
preview_mode: 0
display_submitted: false
......@@ -5,4 +5,6 @@ package: Testing
version: VERSION
core: 8.x
dependencies:
- drupal:media
- dropzonejs:dropzonejs
- dropzonejs:dropzonejs_eb_widget
<?php
namespace Drupal\Tests\dropzonejs\FunctionalJavascript;
use Drupal\Tests\field_ui\Traits\FieldUiTestTrait;
/**
* Test dropzonejs EB Widget.
*
* @group dropzonejs
*/
class DropzoneJsEbWidgetTest extends DropzoneJsWebDriverTestBase {
use FieldUiTestTrait;
/**
* Modules to enable.
*
* @var array
*/
public static $modules = [
'node',
'media',
'menu_ui',
'path',
'dropzonejs_test',
];
/**
* Permissions for user that will be logged-in for test.
*
* @var array
*/
protected static $userPermissions = [
'access dropzonejs_eb_test entity browser pages',
'create dropzonejs_test content',
'dropzone upload files',
'access content',
];
/**
* {@inheritdoc}
*/
protected function setUp() {
parent::setUp();
$account = $this->drupalCreateUser(static::$userPermissions);
$this->drupalLogin($account);
}
/**
* Tests the add widget with iframe form.
*/
public function testUploadFile() {
$this->drupalGet('node/add/dropzonejs_test');
$this->getSession()->getPage()->clickLink('Select entities');
$this->waitForAjaxToFinish();
$this->getSession()->switchToIFrame('entity_browser_iframe_dropzonejs_eb_test');
$this->dropFile();
$this->waitForAjaxToFinish();
$this->getSession()->getPage()->pressButton('Select entities');
// Switch back to the main page.
$this->getSession()->switchToIFrame();
$this->waitForAjaxToFinish();
// For some reason we have to wait here for the markup to show up regardless
// of the waitForAjaxToFinish above.
sleep(2);
$this->assertSession()->elementContains('xpath', '//div[contains(@class, "entities-list")]/div[contains(@class, "label")]', 'notalama.jpg');
}
}
<?php
namespace Drupal\Tests\dropzonejs\FunctionalJavascript;
use Drupal\file\Entity\File;
use Drupal\FunctionalJavascriptTests\WebDriverTestBase;
/**
* Base class for DropzoneJS Web driver functional test base.
*
* @package Drupal\Tests\entity_browser\FunctionalJavascript
*/
abstract class DropzoneJsWebDriverTestBase extends WebDriverTestBase {
protected $defaultTheme = 'classy';
/**
* Simple grey rectangle image data.
*
* @var string
*/
var $fileData = "iVBORw0KGgoAAAANSUhEUgAAAGQAAABkCAAAAABVicqIAAAACXBIWXMAAAsTAAALEwEAmpwYAAAA
B3RJTUUH3gIYBAEMHCkuWQAAAB1pVFh0Q29tbWVudAAAAAAAQ3JlYXRlZCB3aXRoIEdJTVBkLmUH
AAAAQElEQVRo3u3NQQ0AAAgEoNN29i9kCh9uUICa3OtIJBKJRCKRSCQSiUQikUgkEolEIpFIJBKJ
RCKRSCQSiUTyPlnSFQER9VCp/AAAAABJRU5ErkJggg==";
/**
* Modules to enable.
*
* @var array
*/
public static $modules = [
'dropzonejs_test',
'views',
'block',
'node',
'file',
'image',
'field_ui',
'views_ui',
'system',
];
/**
* Creates an file.
*
* @param string $name
* The name of the image.
* @param string $extension
* File extension.
*
* @return \Drupal\file\FileInterface
* Returns an image.
* @throws \Drupal\Core\Entity\EntityStorageException
*/
protected function getFile($name, $extension = 'jpg') {
file_put_contents('public://' . $name . '.' . $extension, $this->fileData);
$file = File::create([
'filename' => $name . '.' . $extension,