You are here

protected function SortableTestTrait::sortableTo in Entity Embed 8

Simulates a drag on an element from one container to another.

Parameters

string $item: The HTML selector for the element to be moved.

string $from: The HTML selector for the previous container element.

null|string $to: The HTML selector for the target container.

4 calls to SortableTestTrait::sortableTo()
CKEditorIntegrationTest::testIntegration in tests/src/FunctionalJavascript/CKEditorIntegrationTest.php
Test integration with Filter, Editor and Ckeditor.
ConfigurationUiTest::testValidationWhenAdding in tests/src/FunctionalJavascript/ConfigurationUiTest.php
Test integration with Filter and Text Editor form validation.
ConfigurationUiTest::testValidationWhenEditing in tests/src/FunctionalJavascript/ConfigurationUiTest.php
Test integration with Filter and Text Editor form validation.
ImageFieldFormatterTest::testInvalidImageError in tests/src/FunctionalJavascript/ImageFieldFormatterTest.php
Test invalid image error.

File

tests/src/FunctionalJavascript/SortableTestTrait.php, line 56

Class

SortableTestTrait
Extends \Drupal\FunctionalJavascriptTests\SortableTestTrait.

Namespace

Drupal\Tests\entity_embed\FunctionalJavascript

Code

protected function sortableTo($item, $from, $to) {

  // Versions of Drupal older than 8.8 allow normal Selenium-style dragging
  // and dropping.
  if (version_compare(\Drupal::VERSION, '8.8.0', '<')) {
    $this
      ->doLegacyDrag($item, $to);
    return;
  }
  $item = addslashes($item);
  $from = addslashes($from);
  $to = addslashes($to);
  $script = <<<JS
(function (src, to) {
  var sourceElement = document.querySelector(src);
  var toElement = document.querySelector(to);

  toElement.insertBefore(sourceElement, toElement.firstChild);
})('{<span class="php-variable">$item</span>}', '{<span class="php-variable">$to</span>}')

JS;
  $options = [
    'script' => $script,
    'args' => [],
  ];
  $this
    ->getSession()
    ->getDriver()
    ->getWebDriverSession()
    ->execute($options);
  $this
    ->sortableUpdate($item, $from, $to);
}