X-Git-Url: http://www.aleph1.co.uk/gitweb/?p=yaffs-website;a=blobdiff_plain;f=web%2Fcore%2Fmodules%2Fimage%2Ftests%2Fsrc%2FFunctionalJavascript%2FQuickEditImageEditorTestTrait.php;fp=web%2Fcore%2Fmodules%2Fimage%2Ftests%2Fsrc%2FFunctionalJavascript%2FQuickEditImageEditorTestTrait.php;h=704e4e702014070079e8bf5b409e01db8a8582a0;hp=0000000000000000000000000000000000000000;hb=0bf8d09d2542548982e81a441b1f16e75873a04f;hpb=74df008bdbb3a11eeea356744f39b802369bda3c diff --git a/web/core/modules/image/tests/src/FunctionalJavascript/QuickEditImageEditorTestTrait.php b/web/core/modules/image/tests/src/FunctionalJavascript/QuickEditImageEditorTestTrait.php new file mode 100644 index 000000000..704e4e702 --- /dev/null +++ b/web/core/modules/image/tests/src/FunctionalJavascript/QuickEditImageEditorTestTrait.php @@ -0,0 +1,76 @@ +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"]')); + } + + /** + * Simulates typing in the 'image' in-place editor 'alt' attribute text input. + * + * @param string $text + * The text to type. + */ + 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); + } + + /** + * Simulates dragging and dropping an image on the 'image' in-place editor. + * + * @param string $file_uri + * The URI of the image file to drag and drop. + */ + protected function dropImageOnImageEditor($file_uri) { + // Our headless browser can't drag+drop files, but we can mock the event. + // Append a hidden upload element to the DOM. + $script = 'jQuery("").appendTo("body")'; + $this->getSession()->executeScript($script); + + // Find the element, and set its value to our new image. + $input = $this->assertSession()->elementExists('css', '#quickedit-image-test-input'); + $filepath = $this->container->get('file_system')->realpath($file_uri); + $input->attachFile($filepath); + + // Trigger the upload logic with a mock "drop" event. + $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); + + // Wait for the dropzone element to be removed (i.e. loading is done). + $js_condition = <<assertJsCondition($js_condition, 20000); + + } + +}