public function ThunderParagraphsTestTrait::addParagraph in Thunder 6.2.x
Same name and namespace in other branches
- 8.5 tests/src/FunctionalJavascript/ThunderParagraphsTestTrait.php \Drupal\Tests\thunder\FunctionalJavascript\ThunderParagraphsTestTrait::addParagraph()
- 8.2 tests/src/FunctionalJavascript/ThunderParagraphsTestTrait.php \Drupal\Tests\thunder\FunctionalJavascript\ThunderParagraphsTestTrait::addParagraph()
- 8.3 tests/src/FunctionalJavascript/ThunderParagraphsTestTrait.php \Drupal\Tests\thunder\FunctionalJavascript\ThunderParagraphsTestTrait::addParagraph()
- 8.4 tests/src/FunctionalJavascript/ThunderParagraphsTestTrait.php \Drupal\Tests\thunder\FunctionalJavascript\ThunderParagraphsTestTrait::addParagraph()
- 6.0.x tests/src/FunctionalJavascript/ThunderParagraphsTestTrait.php \Drupal\Tests\thunder\FunctionalJavascript\ThunderParagraphsTestTrait::addParagraph()
- 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
6 calls to ThunderParagraphsTestTrait::addParagraph()
- 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.
- ThunderParagraphsTestTrait::addTextParagraph in tests/
src/ FunctionalJavascript/ ThunderParagraphsTestTrait.php - Adding text type paragraphs.
File
- tests/
src/ FunctionalJavascript/ ThunderParagraphsTestTrait.php, line 64
Class
- ThunderParagraphsTestTrait
- Trait for handling of Paragraph related test actions.
Namespace
Drupal\Tests\thunder\FunctionalJavascriptCode
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
->assertWaitOnAjaxRequest();
$page
->find('xpath', "//div[contains(@class, \"ui-dialog-content\")]/*[contains(@class, \"paragraphs-add-dialog-list\")]//*[@name=\"{$fieldName}_{$type}_add_more\"]")
->click();
$this
->assertWaitOnAjaxRequest();
// Test if we have one more paragraph now.
static::assertEquals($this
->getNumberOfParagraphs($fieldName), $numberOfParagraphs + 1);
return $this
->getParagraphDelta($fieldName, $position);
}