You are here

public function ParagraphsTypesTest::testParagraphTypeDescription in Paragraphs 8

Test the paragraph type description settings.

File

tests/src/Functional/WidgetLegacy/ParagraphsTypesTest.php, line 144

Class

ParagraphsTypesTest
Tests Paragraphs types.

Namespace

Drupal\Tests\paragraphs\Functional\WidgetLegacy

Code

public function testParagraphTypeDescription() {
  $admin_user = $this
    ->drupalCreateUser([
    'administer paragraphs types',
  ]);
  $this
    ->drupalLogin($admin_user);

  // Add the paragraph type with description.
  $this
    ->drupalGet('admin/structure/paragraphs_type/add');
  $this
    ->assertSession()
    ->pageTextContains('Description');
  $label = 'Test paragraph type';
  $description_markup = 'Use <em>Test paragraph type</em> to test the functionality of descriptions.';
  $description_text = 'Use Test paragraph type to test the functionality of descriptions.';
  $edit = [
    'label' => $label,
    'id' => 'test_paragraph_type_description',
    'description' => $description_markup,
  ];
  $this
    ->submitForm($edit, 'Save and manage fields');
  $this
    ->assertSession()
    ->pageTextContains("Saved the {$label} Paragraphs type.");

  // Check if the description has been saved.
  $this
    ->drupalGet('admin/structure/paragraphs_type');
  $this
    ->assertSession()
    ->pageTextContains('Description');
  $this
    ->assertSession()
    ->pageTextContains($description_text);
  $this
    ->assertSession()
    ->responseContains($description_markup);

  // Check if description is at Description column.
  $header_position = count($this
    ->xpath('//table/thead/tr/th[.="Description"]/preceding-sibling::th'));
  $row_position = count($this
    ->xpath('//table/tbody/tr/td[.="' . $description_text . '"]/preceding-sibling::td'));
  $this
    ->assertEquals($header_position, $row_position);
  $this
    ->clickLink('Edit');
  $this
    ->assertSession()
    ->responseContains('Use &lt;em&gt;Test paragraph type&lt;/em&gt; to test the functionality of descriptions.');
}