You are here

public function ParagraphsLibraryItemTest::testLibraryItemDeleteWarningMessage in Paragraphs 8

Test if the usage warning message shows up, when deleting a library item.

File

modules/paragraphs_library/tests/src/Functional/ParagraphsLibraryItemTest.php, line 332

Class

ParagraphsLibraryItemTest
Tests the functionality of the Paragraphs Library.

Namespace

Drupal\Tests\paragraphs_library\Functional

Code

public function testLibraryItemDeleteWarningMessage() {
  $page = $this
    ->getSession()
    ->getPage();
  $assert_session = $this
    ->assertSession();

  // Create a paragraph in the library.
  $this
    ->drupalGet('admin/content/paragraphs/add/default');
  $page
    ->pressButton('Add text');
  $edit = [
    'label[0][value]' => 'Test usage warning message',
    'paragraphs[0][subform][field_text][0][value]' => 'Example text.',
  ];
  $this
    ->submitForm($edit, 'Save');
  $assert_session
    ->pageTextContains('Paragraph Test usage warning message has been created.');

  // Create content with referenced paragraph.
  $this
    ->drupalGet('node/add/paragraphed_test');
  $page
    ->pressButton('Add From library');
  $edit = [
    'title[0][value]' => 'Test content',
    'field_paragraphs[0][subform][field_reusable_paragraph][0][target_id]' => 'Test usage warning message',
  ];
  $this
    ->submitForm($edit, 'Save');
  $node = $this
    ->drupalGetNodeByTitle('Test content');
  $library_item = $node
    ->get('field_paragraphs')->entity
    ->get('field_reusable_paragraph')->entity;

  // Check if there is a warning message on the delete form.
  $this
    ->drupalGet('/admin/content/paragraphs/' . $library_item
    ->id() . '/delete');
  $assert_session
    ->pageTextContains('There are recorded usages of this entity.');
}