You are here

public function ParagraphsTypesTest::testRemoveTypesWithContent in Paragraphs 8

Same name in this branch
  1. 8 tests/src/Functional/WidgetLegacy/ParagraphsTypesTest.php \Drupal\Tests\paragraphs\Functional\WidgetLegacy\ParagraphsTypesTest::testRemoveTypesWithContent()
  2. 8 tests/src/Functional/WidgetStable/ParagraphsTypesTest.php \Drupal\Tests\paragraphs\Functional\WidgetStable\ParagraphsTypesTest::testRemoveTypesWithContent()

Tests the deletion of Paragraphs types.

File

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

Class

ParagraphsTypesTest
Tests Paragraphs types.

Namespace

Drupal\Tests\paragraphs\Functional\WidgetLegacy

Code

public function testRemoveTypesWithContent() {
  $this
    ->loginAsAdmin();

  // Add a Paragraphed test content.
  $this
    ->addParagraphedContentType('paragraphed_test', 'paragraphs', 'entity_reference_paragraphs');
  $this
    ->addParagraphsType('paragraph_type_test');
  $this
    ->addParagraphsType('text');

  // Attempt to delete the content type not used yet.
  $this
    ->drupalGet('admin/structure/paragraphs_type');
  $this
    ->clickLink('Delete');
  $this
    ->assertSession()
    ->pageTextContains('This action cannot be undone.');
  $this
    ->clickLink('Cancel');

  // Add a test node with a Paragraph.
  $this
    ->drupalGet('node/add/paragraphed_test');
  $this
    ->submitForm([], 'paragraphs_paragraph_type_test_add_more');
  $edit = [
    'title[0][value]' => 'test_node',
  ];
  $this
    ->submitForm($edit, 'Save');
  $this
    ->assertSession()
    ->pageTextContains('paragraphed_test test_node has been created.');

  // Attempt to delete the paragraph type already used.
  $this
    ->drupalGet('admin/structure/paragraphs_type');
  $this
    ->clickLink('Delete');
  $this
    ->assertSession()
    ->pageTextContains('paragraph_type_test Paragraphs type is used by 1 piece of content on your site. You can not remove this paragraph_type_test Paragraphs type until you have removed all from the content.');
}