You are here

public function ParagraphsDuplicateFeatureTest::testDuplicateButtonWithLimitedCardinality in Paragraphs 8

Tests duplicate paragraph feature for fields with a limited cardinality.

File

tests/src/Functional/WidgetStable/ParagraphsDuplicateFeatureTest.php, line 192

Class

ParagraphsDuplicateFeatureTest
Tests paragraphs duplicate feature.

Namespace

Drupal\Tests\paragraphs\Functional\WidgetStable

Code

public function testDuplicateButtonWithLimitedCardinality() {
  $this
    ->addParagraphedContentType('paragraphed_test');

  /** @var \Drupal\field\FieldStorageConfigInterface $field_storage */
  $field_storage = FieldStorageConfig::load('node.field_paragraphs');
  $field_storage
    ->setCardinality(2)
    ->save();
  $this
    ->loginAsAdmin([
    'create paragraphed_test content',
    'edit any paragraphed_test content',
  ]);

  // Add a Paragraph type.
  $paragraph_type = 'text_paragraph';
  $this
    ->addParagraphsType($paragraph_type);

  // Add a text field to the text_paragraph type.
  static::fieldUIAddNewField('admin/structure/paragraphs_type/' . $paragraph_type, 'text', 'Text', 'text_long', [], []);
  $this
    ->drupalGet('node/add/paragraphed_test');
  $this
    ->submitForm([], 'field_paragraphs_text_paragraph_add_more');
  $edit = [
    'title[0][value]' => 'paragraphs_mode_test',
    'field_paragraphs[0][subform][field_text][0][value]' => 'A',
    'field_paragraphs[1][subform][field_text][0][value]' => 'B',
  ];
  $this
    ->submitForm($edit, 'Save');
  $node = $this
    ->drupalGetNodeByTitle('paragraphs_mode_test');
  $this
    ->drupalGet('node/' . $node
    ->id() . '/edit');
  $this
    ->assertNoField('field_paragraphs_0_duplicate');
  $this
    ->assertNoField('field_paragraphs_1_duplicate');
}