You are here

public function ParagraphsAddModesTest::testSettingDefaultParagraphType in Paragraphs 8

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

Tests if setting for default paragraph type is working properly.

File

tests/src/Functional/WidgetStable/ParagraphsAddModesTest.php, line 151

Class

ParagraphsAddModesTest
Tests paragraphs add modes.

Namespace

Drupal\Tests\paragraphs\Functional\WidgetStable

Code

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

  // Add a Paragraphed test content.
  $paragraphs_type_text_image = ParagraphsType::create([
    'id' => 'text_image',
    'label' => 'Text + Image',
  ]);
  $paragraphs_type_text = ParagraphsType::create([
    'id' => 'text',
    'label' => 'Text',
  ]);
  $paragraphs_type_text_image
    ->save();
  $paragraphs_type_text
    ->save();
  $this
    ->setDefaultParagraphType('paragraphed_test', 'paragraphs', 'paragraphs_settings_edit', 'text_image');

  // Check if default paragraph type is showing.
  $this
    ->drupalGet('node/add/paragraphed_test');
  $this
    ->assertSession()
    ->pageTextContains('Text + Image');
  $this
    ->removeDefaultParagraphType('paragraphed_test');

  // Disable text_image as default paragraph type.
  $this
    ->setDefaultParagraphType('paragraphed_test', 'paragraphs', 'paragraphs_settings_edit', '_none');

  // Check if is Text + Image is added as default paragraph type.
  $this
    ->drupalGet('node/add/paragraphed_test');
  $elements = $this
    ->xpath('//table[@id="paragraphs-values"]/tbody');
  $header = $this
    ->xpath('//table[@id="paragraphs-values"]/thead');
  $this
    ->assertEquals($elements, []);
  $this
    ->assertNotEquals($header, []);

  // Check if default type is created only for new host
  $this
    ->setDefaultParagraphType('paragraphed_test', 'paragraphs', 'paragraphs_settings_edit', 'text_image');
  $this
    ->removeDefaultParagraphType('paragraphed_test');
  $edit = [
    'title[0][value]' => 'New Host',
  ];
  $this
    ->submitForm($edit, 'Save');
  $this
    ->drupalGet('node/1/edit');
  $elements = $this
    ->xpath('//table[@id="paragraphs-values"]/tbody');
  $header = $this
    ->xpath('//table[@id="paragraphs-values"]/thead');
  $this
    ->assertEquals($elements, []);
  $this
    ->assertNotEquals($header, []);
}