function SortableTestTrait::sortableTo

Same name in other branches
  1. 9 core/tests/Drupal/FunctionalJavascriptTests/SortableTestTrait.php \Drupal\FunctionalJavascriptTests\SortableTestTrait::sortableTo()
  2. 10 core/tests/Drupal/FunctionalJavascriptTests/SortableTestTrait.php \Drupal\FunctionalJavascriptTests\SortableTestTrait::sortableTo()
  3. 11.x core/tests/Drupal/FunctionalJavascriptTests/SortableTestTrait.php \Drupal\FunctionalJavascriptTests\SortableTestTrait::sortableTo()

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.

2 calls to SortableTestTrait::sortableTo()
CKEditorIntegrationTest::testConfigurationValidation in core/modules/media_library/tests/src/FunctionalJavascript/CKEditorIntegrationTest.php
Tests validation that DrupalMediaLibrary requires media_embed filter.
LayoutBuilderTest::testLayoutBuilderUi in core/modules/layout_builder/tests/src/FunctionalJavascript/LayoutBuilderTest.php
Tests the Layout Builder UI.

File

core/tests/Drupal/FunctionalJavascriptTests/SortableTestTrait.php, line 38

Class

SortableTestTrait
Provides functions for simulating sort changes.

Namespace

Drupal\FunctionalJavascriptTests

Code

protected function sortableTo($item, $from, $to) {
    $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);
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.