public function ParagraphsCollapsedSummaryTest::testNestedParagraphSummary

Tests nested paragraph summary.

File

paragraphs/tests/src/Kernel/ParagraphsCollapsedSummaryTest.php, line 125

Class

ParagraphsCollapsedSummaryTest
Tests the collapsed summary options.

Namespace

Drupal\Tests\paragraphs\Kernel

Code

public function testNestedParagraphSummary() {

  // Create a text paragraph.
  $paragraph_text_1 = Paragraph::create([
    'type' => 'text_paragraph',
    'text' => 'Text paragraph on nested level',
  ]);
  $paragraph_text_1
    ->save();

  // Add a nested paragraph with the text inside.
  $paragraph_nested_1 = Paragraph::create([
    'type' => 'nested_paragraph',
    'nested_paragraph_field' => [
      $paragraph_text_1,
    ],
  ]);
  $paragraph_nested_1
    ->save();

  // Create a new text paragraph.
  $paragraph_text_2 = Paragraph::create([
    'type' => 'text_paragraph',
    'text' => 'Text paragraph on top level',
  ]);
  $paragraph_text_2
    ->save();

  // Add a nested paragraph with the new text and nested paragraph inside.
  $paragraph_nested_2 = Paragraph::create([
    'type' => 'nested_paragraph',
    'nested_paragraph_field' => [
      $paragraph_text_2,
      $paragraph_nested_1,
    ],
  ]);
  $paragraph_nested_2
    ->save();
  $this
    ->assertEquals((string) $paragraph_nested_2
    ->getSummary([
    'show_behavior_summary' => FALSE,
  ]), '<div class="paragraphs-description paragraphs-collapsed-description"><div class="paragraphs-content-wrapper"><span class="summary-content">Text paragraph on top level</span></div></div>');
  $this
    ->assertEquals((string) $paragraph_nested_2
    ->getSummary([
    'show_behavior_summary' => FALSE,
    'depth_limit' => 2,
  ]), '<div class="paragraphs-description paragraphs-collapsed-description"><div class="paragraphs-content-wrapper"><span class="summary-content">Text paragraph on top level</span>, <span class="summary-content">Text paragraph on nested level</span></div></div>');
  $info = $paragraph_nested_2
    ->getIcons();
  $this
    ->assertEquals($info['count']['#prefix'], '<span class="paragraphs-badge" title="2 children">');
  $this
    ->assertEquals($info['count']['#suffix'], '</span>');
}