public function ParagraphsAddModesTest::testDefaultParagraphTypeWithSingleType

Same name in this branch
  1. 8.x-1.x paragraphs/tests/src/Functional/WidgetStable/ParagraphsAddModesTest.php \Drupal\Tests\paragraphs\Functional\WidgetStable\ParagraphsAddModesTest::testDefaultParagraphTypeWithSingleType()
  2. 8.x-1.x paragraphs/tests/src/Functional/WidgetLegacy/ParagraphsAddModesTest.php \Drupal\Tests\paragraphs\Functional\WidgetLegacy\ParagraphsAddModesTest::testDefaultParagraphTypeWithSingleType()

Tests the default paragraph type behavior for a field with a single type.

File

paragraphs/tests/src/Functional/WidgetLegacy/ParagraphsAddModesTest.php, line 198

Class

ParagraphsAddModesTest
Tests paragraphs add modes.

Namespace

Drupal\Tests\paragraphs\Functional\WidgetLegacy

Code

public function testDefaultParagraphTypeWithSingleType() {
  $this
    ->addParagraphedContentType('paragraphed_test', 'paragraphs', 'entity_reference_paragraphs');
  $this
    ->loginAsAdmin([
    'administer content types',
    'administer node form display',
    'edit any paragraphed_test content',
  ]);

  // Add a Paragraphed test content.
  $paragraphs_type_text = ParagraphsType::create([
    'id' => 'text',
    'label' => 'Text',
  ]);
  $paragraphs_type_text
    ->save();

  // Check that when only one paragraph type is allowed in a content type,
  // one instance is automatically added in the 'Add content' dialogue.
  $this
    ->drupalGet('node/add/paragraphed_test');
  $this
    ->assertSession()
    ->pageTextNotContains('No Paragraph added yet.');

  // Check that no paragraph type is automatically added, if the defaut
  // setting was set to '- None -'.
  $this
    ->setDefaultParagraphType('paragraphed_test', 'paragraphs', 'paragraphs_settings_edit', '_none');
  $this
    ->drupalGet('node/add/paragraphed_test');
  $this
    ->assertSession()
    ->pageTextContains('No Paragraph added yet.');
}