Commit f8651c75 authored by Volker Killesreiter's avatar Volker Killesreiter
Browse files

Issue #3274032: Refactor base class into a trait

parent 75f0033b
Loading
Loading
Loading
Loading
+1 −29
Original line number Diff line number Diff line
@@ -16,6 +16,7 @@ use Drupal\Tests\paragraphs\FunctionalJavascript\LoginAdminTrait;
abstract class ParagraphsPasteJavascriptTestBase extends WebDriverTestBase {

  use LoginAdminTrait;
  use ParagraphsPasteJavascriptTestTrait;

  /**
   * Modules to enable.
@@ -33,35 +34,6 @@ abstract class ParagraphsPasteJavascriptTestBase extends WebDriverTestBase {
   */
  protected $defaultTheme = 'stark';

  /**
   * Simulate paste event.
   *
   * @param string $field_name
   *   The original field name.
   * @param string $text
   *   Text to copy.
   */
  public function simulatePasteEvent($field_name, $text) {
    $this->click("[data-paragraphs-paste-target=\"{$field_name}\"]");
    $area_selector = ".ui-dialog .paragraphs-paste-form [name=\"" . $field_name . "_paste_area\"]";
    $this->getSession()->executeScript("document.querySelector('{$area_selector}').value = '{$text}';");
    $this->click(".ui-dialog .paragraphs-paste-form [name=\"" . $field_name . "_paste_submit\"]");
  }

  /**
   * Wait for element to be present.
   *
   * @param string $selector
   *   The CSS selector.
   * @param int $timeout
   *   (Optional) Timeout in milliseconds, defaults to 1000.
   * @param string $message
   *   (Optional) Message to pass to assertJsCondition().
   */
  public function waitForElementPresent($selector, $timeout = 1000, $message = '') {
    $this->assertJsCondition("document.querySelector('{$selector}')", $timeout, $message);
  }

  /**
   * {@inheritdoc}
   */
+39 −0
Original line number Diff line number Diff line
<?php

namespace Drupal\Tests\paragraphs_paste\FunctionalJavascript;

/**
 * Test trait with helper functions.
 */
trait ParagraphsPasteJavascriptTestTrait {

  /**
   * Simulate paste event.
   *
   * @param string $field_name
   *   The original field name.
   * @param string $text
   *   Text to copy.
   */
  public function simulatePasteEvent($field_name, $text) {
    $this->click("[data-paragraphs-paste-target=\"{$field_name}\"]");
    $area_selector = ".ui-dialog .paragraphs-paste-form [name=\"" . $field_name . "_paste_area\"]";
    $this->getSession()->executeScript("document.querySelector('{$area_selector}').value = '{$text}';");
    $this->click(".ui-dialog .paragraphs-paste-form [name=\"" . $field_name . "_paste_submit\"]");
  }

  /**
   * Wait for element to be present.
   *
   * @param string $selector
   *   The CSS selector.
   * @param int $timeout
   *   (Optional) Timeout in milliseconds, defaults to 1000.
   * @param string $message
   *   (Optional) Message to pass to assertJsCondition().
   */
  public function waitForElementPresent($selector, $timeout = 1000, $message = '') {
    $this->assertJsCondition("document.querySelector('{$selector}')", $timeout, $message);
  }

}