You are here

protected function SortableTestTrait::sortableAfter in Drupal 8

Same name and namespace in other branches
  1. 9 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.

1 call to SortableTestTrait::sortableAfter()
ContentPreviewToggleTest::testContentPreviewToggle in core/modules/layout_builder/tests/src/FunctionalJavascript/ContentPreviewToggleTest.php
Tests the content preview toggle.

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);
}