You are here

public function ParagraphsBehaviorsTest::testCollapsedSummary in Paragraphs 8

Tests the behavior plugins summary for paragraphs closed mode.

File

tests/src/Functional/WidgetStable/ParagraphsBehaviorsTest.php, line 211

Class

ParagraphsBehaviorsTest
Tests paragraphs behavior plugins.

Namespace

Drupal\Tests\paragraphs\Functional\WidgetStable

Code

public function testCollapsedSummary() {
  $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', [], []);
  $this
    ->setParagraphsWidgetMode('paragraphed_test', 'field_paragraphs', 'closed');

  // 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);
  $this
    ->addParagraphsField('nested_paragraph', 'paragraphs', 'paragraph');

  // 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_1_subform_paragraphs_text_paragraph_add_more');
  $this
    ->assertSession()
    ->fieldExists('field_paragraphs[0][behavior_plugins][test_bold_text][bold_text]');
  $this
    ->assertSession()
    ->fieldExists('field_paragraphs[1][behavior_plugins][test_bold_text][bold_text]');
  $edit = [
    'title[0][value]' => 'collapsed_test',
    'field_paragraphs[0][subform][field_text][0][value]' => 'first_paragraph',
    'field_paragraphs[0][behavior_plugins][test_bold_text][bold_text]' => TRUE,
    'field_paragraphs[1][subform][paragraphs][0][subform][field_text][0][value]' => 'nested_paragraph',
    'field_paragraphs[1][behavior_plugins][test_bold_text][bold_text]' => TRUE,
  ];
  $this
    ->submitForm($edit, 'Save');
  $this
    ->clickLink('Edit');

  // Assert that info section includes the information from behavior plugins.
  $this
    ->assertSession()
    ->elementExists('xpath', '//*[@id="edit-field-paragraphs-0-top-icons"]/span[@class="paragraphs-icon paragraphs-icon-bold"]');
  $this
    ->assertSession()
    ->elementExists('xpath', '//*[@id="edit-field-paragraphs-1-top-icons"]/span[@class="paragraphs-badge" and @title="1 child"]');
  $this
    ->assertSession()
    ->elementExists('xpath', '//*[@id="edit-field-paragraphs-1-top-icons"]/span[@class="paragraphs-icon paragraphs-icon-bold"]');

  // Assert that the summary includes the text of the behavior plugins.
  $this
    ->assertSession()
    ->responseContains('first_paragraph</span></div><div class="paragraphs-plugin-wrapper"><span class="summary-plugin"><span class="summary-plugin-label">Bold</span>Yes</span><span class="summary-plugin"><span class="summary-plugin-label">Text color</span>blue</span>');
  $this
    ->assertSession()
    ->responseContains('nested_paragraph</span></div><div class="paragraphs-plugin-wrapper"><span class="summary-plugin"><span class="summary-plugin-label">Bold</span>Yes</span></div></div>');

  // Add an empty nested paragraph.
  $this
    ->drupalGet('node/add/paragraphed_test');
  $this
    ->submitForm([], 'field_paragraphs_nested_paragraph_add_more');
  $edit = [
    'title[0][value]' => 'collapsed_test',
  ];
  $this
    ->submitForm($edit, 'Save');

  // Check an empty nested paragraph summary.
  $this
    ->clickLink('Edit');
  $this
    ->assertSession()
    ->responseContains('class="paragraphs-description paragraphs-collapsed-description">');
}