function SortableTestTrait::sortableAfter

Same name and namespace in other branches
  1. 8.9.x core/tests/Drupal/FunctionalJavascriptTests/SortableTestTrait.php \Drupal\FunctionalJavascriptTests\SortableTestTrait::sortableAfter()
  2. 10 core/tests/Drupal/FunctionalJavascriptTests/SortableTestTrait.php \Drupal\FunctionalJavascriptTests\SortableTestTrait::sortableAfter()
  3. 11.x core/tests/Drupal/FunctionalJavascriptTests/SortableTestTrait.php \Drupal\FunctionalJavascriptTests\SortableTestTrait::sortableAfter()

Simulates a drag moving an element after its sibling in the same container.

Parameters

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

string $target: The HTML selector for the sibling element.

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

3 calls to SortableTestTrait::sortableAfter()
ContentPreviewToggleTest::testContentPreviewToggle in core/modules/layout_builder/tests/src/FunctionalJavascript/ContentPreviewToggleTest.php
Tests the content preview toggle.
EntityReferenceWidgetTest::testAddAfterReordering in core/modules/media_library/tests/src/FunctionalJavascript/EntityReferenceWidgetTest.php
Tests that order is correct after re-order and adding another item.
EntityReferenceWidgetTest::testRemoveAfterReordering in core/modules/media_library/tests/src/FunctionalJavascript/EntityReferenceWidgetTest.php
Tests that changed order is maintained after removing a selection.

File

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

Class

SortableTestTrait
Provides functions for simulating sort changes.

Namespace

Drupal\FunctionalJavascriptTests

Code

protected function sortableAfter($item, $target, $from) {
    $item = addslashes($item);
    $target = addslashes($target);
    $from = addslashes($from);
    $script = <<<JS
(function (src, to) {
  var sourceElement = document.querySelector(src);
  var toElement = document.querySelector(to);

  toElement.insertAdjacentElement('afterend', sourceElement);
})('{<span class="php-variable">$item</span>}', '{<span class="php-variable">$target</span>}')

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

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