You are here

public function ThunderParagraphsTestTrait::getParagraphDelta in Thunder 8.3

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

Get dalta of paragraph item for a given filed on a specific position.

Parameters

string $fieldName: Field name.

int $position: The Position of the paragraph item.

Return value

int The delta of the paragraph

Throws

\Exception

2 calls to ThunderParagraphsTestTrait::getParagraphDelta()
ParagraphSplitTest::testAddParagraphAfterSplitDataLoss in tests/src/FunctionalJavascript/Integration/ParagraphSplitTest.php
Test if a adding paragraph after split leads to data loss.
ThunderParagraphsTestTrait::addParagraph in tests/src/FunctionalJavascript/ThunderParagraphsTestTrait.php
Add paragraph for field with defined paragraph type.

File

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

Class

ThunderParagraphsTestTrait
Trait for handling of Paragraph related test actions.

Namespace

Drupal\Tests\thunder\FunctionalJavascript

Code

public function getParagraphDelta($fieldName, $position) {
  $fieldSelector = HTML::cleanCssIdentifier($fieldName);

  // Retrieve new paragraphs delta from id attribute of the item.
  $paragraphItem = $this
    ->getParagraphItems($fieldName)[$position];
  $itemId = $paragraphItem
    ->getAttribute('id');
  preg_match("/^edit-{$fieldSelector}-(\\d+)--/", $itemId, $matches);
  if (!isset($matches[1])) {
    throw new \Exception('No new paragraph is found');
  }
  return $matches[1];
}