You are here

public function ParagraphsAddModesTest::testDefaultParagraphTypeWithSingleType in Paragraphs 8

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

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

File

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.');
}