protected function ThunderEntityBrowserTestTrait::dragDropElement in Thunder 8.2
Same name and namespace in other branches
- 8.5 tests/src/FunctionalJavascript/ThunderEntityBrowserTestTrait.php \Drupal\Tests\thunder\FunctionalJavascript\ThunderEntityBrowserTestTrait::dragDropElement()
- 8.3 tests/src/FunctionalJavascript/ThunderEntityBrowserTestTrait.php \Drupal\Tests\thunder\FunctionalJavascript\ThunderEntityBrowserTestTrait::dragDropElement()
- 8.4 tests/src/FunctionalJavascript/ThunderEntityBrowserTestTrait.php \Drupal\Tests\thunder\FunctionalJavascript\ThunderEntityBrowserTestTrait::dragDropElement()
- 6.2.x tests/src/FunctionalJavascript/ThunderEntityBrowserTestTrait.php \Drupal\Tests\thunder\FunctionalJavascript\ThunderEntityBrowserTestTrait::dragDropElement()
- 6.0.x tests/src/FunctionalJavascript/ThunderEntityBrowserTestTrait.php \Drupal\Tests\thunder\FunctionalJavascript\ThunderEntityBrowserTestTrait::dragDropElement()
- 6.1.x tests/src/FunctionalJavascript/ThunderEntityBrowserTestTrait.php \Drupal\Tests\thunder\FunctionalJavascript\ThunderEntityBrowserTestTrait::dragDropElement()
Drag element in document with defined offset position.
Parameters
\Behat\Mink\Element\NodeElement $element: Element that will be dragged.
int $offsetX: Vertical offset for element drag in pixels.
int $offsetY: Horizontal offset for element drag in pixels.
2 calls to ThunderEntityBrowserTestTrait::dragDropElement()
- MediaGalleryModifyTest::testAddRemove in tests/
src/ FunctionalJavascript/ MediaGalleryModifyTest.php - Test add/remove Images in Gallery.
- MediaGalleryModifyTest::testOrderChange in tests/
src/ FunctionalJavascript/ MediaGalleryModifyTest.php - Test order change for Gallery.
File
- tests/
src/ FunctionalJavascript/ ThunderEntityBrowserTestTrait.php, line 132
Class
- ThunderEntityBrowserTestTrait
- Trait with support for handling Entity Browser actions.
Namespace
Drupal\Tests\thunder\FunctionalJavascriptCode
protected function dragDropElement(NodeElement $element, $offsetX, $offsetY) {
$this
->assertSession()
->assertWaitOnAjaxRequest();
$elemXpath = $element
->getXpath();
$jsCode = "var fireMouseEvent = function (type, element, x, y) {" . " var event = document.createEvent('MouseEvents');" . " event.initMouseEvent(type, true, (type !== 'mousemove'), window, 0, 0, 0, x, y, false, false, false, false, 0, element);" . " element.dispatchEvent(event); };";
// XPath provided by getXpath uses single quote (') to encapsulate strings,
// that's why xpath has to be quited with double quites in javascript code.
$jsCode .= "(function() {" . " var dragElement = document.evaluate(\"{$elemXpath}\", document, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null).singleNodeValue;" . " var pos = dragElement.getBoundingClientRect();" . " var centerX = Math.floor((pos.left + pos.right) / 2);" . " var centerY = Math.floor((pos.top + pos.bottom) / 2);" . " fireMouseEvent('mousedown', dragElement, centerX, centerY);" . " fireMouseEvent('mousemove', document, centerX + {$offsetX}, centerY + {$offsetY});" . " fireMouseEvent('mouseup', dragElement, centerX + {$offsetX}, centerY + {$offsetY});" . "})();";
$this
->getSession()
->executeScript($jsCode);
}