public function ParagraphsConfigTest::testRequiredParagraphsField

Tests required Paragraphs field.

File

paragraphs/tests/src/Functional/WidgetLegacy/ParagraphsConfigTest.php, line 145

Class

ParagraphsConfigTest
Tests paragraphs configuration.

Namespace

Drupal\Tests\paragraphs\Functional\WidgetLegacy

Code

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

  // Add a Paragraph content type and 2 Paragraphs types.
  $this
    ->addParagraphedContentType('paragraphed_test', 'paragraphs', 'entity_reference_paragraphs');
  $this
    ->addParagraphsType('paragraph_type_test');
  $this
    ->addParagraphsType('text');

  // Make the paragraphs field required and save configuration.
  $this
    ->drupalGet('admin/structure/types/manage/paragraphed_test/fields/node.paragraphed_test.paragraphs');
  $edit = [
    'required' => TRUE,
  ];
  $this
    ->submitForm($edit, 'Save settings');
  $this
    ->assertSession()
    ->pageTextContains('Saved paragraphs configuration.');

  // Assert that the field is displayed in the form as required.
  $this
    ->drupalGet('node/add/paragraphed_test');
  $this
    ->assertSession()
    ->responseContains('<strong class="form-required" data-drupal-selector="edit-paragraphs-title">');
  $edit = [
    'title[0][value]' => 'test_title',
  ];
  $this
    ->submitForm($edit, 'Save');
  $this
    ->assertSession()
    ->pageTextContains('paragraphs field is required.');
  $this
    ->submitForm([], 'paragraphs_paragraph_type_test_add_more');
  $this
    ->submitForm($edit, 'Save');
  $this
    ->assertSession()
    ->pageTextContains('paragraphed_test test_title has been created.');
}