QuickEditImageEditorTestTrait.php in Drupal 9
File
core/modules/quickedit/tests/src/FunctionalJavascript/QuickEditImageEditorTestTrait.php
View source
<?php
namespace Drupal\Tests\quickedit\FunctionalJavascript;
trait QuickEditImageEditorTestTrait {
protected function awaitImageEditor() {
$this
->assertJsCondition('document.querySelector(".quickedit-image-field-info") !== null', 10000);
$quickedit_entity_toolbar = $this
->getSession()
->getPage()
->findById('quickedit-entity-toolbar');
$this
->assertNotNull($quickedit_entity_toolbar
->find('css', 'form.quickedit-image-field-info input[name="alt"]'));
}
protected function typeInImageEditorAltTextInput($text) {
$quickedit_entity_toolbar = $this
->getSession()
->getPage()
->findById('quickedit-entity-toolbar');
$input = $quickedit_entity_toolbar
->find('css', 'form.quickedit-image-field-info input[name="alt"]');
$input
->setValue($text);
}
protected function dropImageOnImageEditor($file_uri) {
$script = 'jQuery("<input id=\\"quickedit-image-test-input\\" type=\\"file\\" />").appendTo("body")';
$this
->getSession()
->executeScript($script);
$input = $this
->assertSession()
->elementExists('css', '#quickedit-image-test-input');
$filepath = $this->container
->get('file_system')
->realpath($file_uri);
$input
->attachFile($filepath);
$script = 'var e = jQuery.Event("drop");' . 'e.originalEvent = {dataTransfer: {files: jQuery("#quickedit-image-test-input").get(0).files}};' . 'e.preventDefault = e.stopPropagation = function () {};' . 'jQuery(".quickedit-image-dropzone").trigger(e);';
$this
->getSession()
->executeScript($script);
$js_condition = <<<JS
function () {
var activeFieldID = Drupal.quickedit.collections.entities
.findWhere({state:'opened'})
.get('fields')
.filter(function (fieldModel) {
var state = fieldModel.get('state');
return state === 'active' || state === 'changed';
})[0]
.get('fieldID')
return document.querySelector('[data-quickedit-field-id="' + activeFieldID + '"] .quickedit-image-dropzone') === null;
}()
JS;
$this
->assertJsCondition($js_condition, 20000);
}
}