public function ParagraphsBehaviorsTest::testBehaviorSubform

Tests the behavior plugins subform state submit.

File

paragraphs/tests/src/Functional/WidgetStable/ParagraphsBehaviorsTest.php, line 288

Class

ParagraphsBehaviorsTest
Tests paragraphs behavior plugins.

Namespace

Drupal\Tests\paragraphs\Functional\WidgetStable

Code

public function testBehaviorSubform() {
  $this
    ->addParagraphedContentType('paragraphed_test');
  $this
    ->loginAsAdmin([
    'create paragraphed_test content',
    'edit any paragraphed_test content',
    'edit behavior plugin settings',
  ]);

  // Add a text paragraph type.
  $paragraph_type = 'text_paragraph';
  $this
    ->addParagraphsType($paragraph_type);
  static::fieldUIAddNewField('admin/structure/paragraphs_type/' . $paragraph_type, 'text', 'Text', 'text_long', [], []);

  // Enable plugins for the text paragraph type.
  $edit = [
    'behavior_plugins[test_bold_text][enabled]' => TRUE,
    'behavior_plugins[test_text_color][enabled]' => TRUE,
  ];
  $this
    ->drupalGet('admin/structure/paragraphs_type/' . $paragraph_type);
  $this
    ->submitForm($edit, 'Save');

  // Add a nested Paragraph type.
  $paragraph_type = 'nested_paragraph';
  $this
    ->addParagraphsType($paragraph_type);
  static::fieldUIAddNewField('admin/structure/paragraphs_type/nested_paragraph', 'nested', 'Nested', 'field_ui:entity_reference_revisions:paragraph', [
    'settings[target_type]' => 'paragraph',
    'cardinality' => '-1',
  ], []);

  // Enable plugins for the nested paragraph type.
  $edit = [
    'behavior_plugins[test_bold_text][enabled]' => TRUE,
  ];
  $this
    ->drupalGet('admin/structure/paragraphs_type/' . $paragraph_type);
  $this
    ->submitForm($edit, 'Save');

  // Add a node and enabled plugins.
  $this
    ->drupalGet('node/add/paragraphed_test');
  $this
    ->submitForm([], 'field_paragraphs_nested_paragraph_add_more');
  $this
    ->submitForm([], 'field_paragraphs_text_paragraph_add_more');
  $this
    ->submitForm([], 'field_paragraphs_0_subform_field_nested_text_paragraph_add_more');
  $edit = [
    'title[0][value]' => 'collapsed_test',
    'field_paragraphs[0][subform][field_nested][0][subform][field_text][0][value]' => 'nested text paragraph',
    'field_paragraphs[0][behavior_plugins][test_bold_text][bold_text]' => TRUE,
    'field_paragraphs[1][subform][field_text][0][value]' => 'first_paragraph',
    'field_paragraphs[1][behavior_plugins][test_bold_text][bold_text]' => TRUE,
  ];
  $this
    ->submitForm($edit, 'Save');
  $this
    ->clickLink('Edit');
  $edit = [
    'field_paragraphs[0][_weight]' => 1,
    'field_paragraphs[1][behavior_plugins][test_bold_text][bold_text]' => FALSE,
    'field_paragraphs[1][behavior_plugins][test_text_color][text_color]' => 'red',
    'field_paragraphs[1][_weight]' => 0,
  ];
  $this
    ->submitForm($edit, 'Save');
  $this
    ->clickLink('Edit');
  $this
    ->assertSession()
    ->fieldValueEquals('field_paragraphs[0][behavior_plugins][test_text_color][text_color]', 'red');
}