You are here

public function ThunderParagraphsTestTrait::addParagraph in Thunder 8.3

Same name and namespace in other branches
  1. 8.5 tests/src/FunctionalJavascript/ThunderParagraphsTestTrait.php \Drupal\Tests\thunder\FunctionalJavascript\ThunderParagraphsTestTrait::addParagraph()
  2. 8.2 tests/src/FunctionalJavascript/ThunderParagraphsTestTrait.php \Drupal\Tests\thunder\FunctionalJavascript\ThunderParagraphsTestTrait::addParagraph()
  3. 8.4 tests/src/FunctionalJavascript/ThunderParagraphsTestTrait.php \Drupal\Tests\thunder\FunctionalJavascript\ThunderParagraphsTestTrait::addParagraph()
  4. 6.2.x tests/src/FunctionalJavascript/ThunderParagraphsTestTrait.php \Drupal\Tests\thunder\FunctionalJavascript\ThunderParagraphsTestTrait::addParagraph()
  5. 6.0.x tests/src/FunctionalJavascript/ThunderParagraphsTestTrait.php \Drupal\Tests\thunder\FunctionalJavascript\ThunderParagraphsTestTrait::addParagraph()
  6. 6.1.x tests/src/FunctionalJavascript/ThunderParagraphsTestTrait.php \Drupal\Tests\thunder\FunctionalJavascript\ThunderParagraphsTestTrait::addParagraph()

Add paragraph for field with defined paragraph type.

This uses paragraphs modal widget.

Parameters

string $fieldName: Field name.

string $type: Type of the paragraph.

int $position: Position of the paragraph.

Return value

int Returns index for added paragraph.

Throws

\Exception

7 calls to ThunderParagraphsTestTrait::addParagraph()
RiddleTest::testRiddle in tests/src/FunctionalJavascript/Integration/RiddleTest.php
Testing integration of "thunder_riddle" module.
ThunderParagraphsTestTrait::addGalleryParagraph in tests/src/FunctionalJavascript/ThunderParagraphsTestTrait.php
Add Gallery paragraph.
ThunderParagraphsTestTrait::addImageParagraph in tests/src/FunctionalJavascript/ThunderParagraphsTestTrait.php
Add Image paragraph.
ThunderParagraphsTestTrait::addLinkParagraph in tests/src/FunctionalJavascript/ThunderParagraphsTestTrait.php
Add link paragraph.
ThunderParagraphsTestTrait::addSocialParagraph in tests/src/FunctionalJavascript/ThunderParagraphsTestTrait.php
Create Twitter, Instagram or PinterestParagraph.

... See full list

File

tests/src/FunctionalJavascript/ThunderParagraphsTestTrait.php, line 62

Class

ThunderParagraphsTestTrait
Trait for handling of Paragraph related test actions.

Namespace

Drupal\Tests\thunder\FunctionalJavascript

Code

public function addParagraph($fieldName, $type, $position = NULL) {

  /** @var \Behat\Mink\Element\DocumentElement $page */
  $page = $this
    ->getSession()
    ->getPage();
  $numberOfParagraphs = $this
    ->getNumberOfParagraphs($fieldName);
  $fieldSelector = HTML::cleanCssIdentifier($fieldName);
  if ($position === NULL || $position > $numberOfParagraphs) {
    $position = $numberOfParagraphs;
    $addButtonCssSelector = "#edit-{$fieldSelector}-wrapper table > tbody > tr:last-child input.paragraphs-features__add-in-between__button";
  }
  else {
    $addButtonPosition = $position * 2 + 1;
    $addButtonCssSelector = "#edit-{$fieldSelector}-wrapper table > tbody > tr:nth-child({$addButtonPosition}) input.paragraphs-features__add-in-between__button";
  }
  $addButton = $page
    ->find('css', $addButtonCssSelector);
  $this
    ->scrollElementInView($addButtonCssSelector);
  $addButton
    ->click();
  $this
    ->assertSession()
    ->assertWaitOnAjaxRequest();
  $page
    ->find('xpath', "//div[contains(@class, \"ui-dialog-content\")]/*[contains(@class, \"paragraphs-add-dialog-list\")]//*[@name=\"{$fieldName}_{$type}_add_more\"]")
    ->click();
  $this
    ->assertSession()
    ->assertWaitOnAjaxRequest();

  // Test if we have one more paragraph now.
  static::assertEquals($this
    ->getNumberOfParagraphs($fieldName), $numberOfParagraphs + 1);
  return $this
    ->getParagraphDelta($fieldName, $position);
}