public function ParagraphsCollapsedSummaryTest::testCollapsedSummaryOptions

Tests the collapsed summary additional options.

File

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

Class

ParagraphsCollapsedSummaryTest
Tests the collapsed summary options.

Namespace

Drupal\Tests\paragraphs\Kernel

Code

public function testCollapsedSummaryOptions() {

  // Create a paragraph and set its feature settings.
  $paragraph = Paragraph::create([
    'type' => 'text_paragraph',
    'text' => 'Example text for a text paragraph',
  ]);
  $feature_settings = [
    'test_text_color' => [
      'text_color' => 'red',
    ],
  ];
  $paragraph
    ->setAllBehaviorSettings($feature_settings);
  $paragraph
    ->save();

  // Load the paragraph and assert its stored feature settings.
  $paragraph = Paragraph::load($paragraph
    ->id());
  $this
    ->assertEquals($paragraph
    ->getAllBehaviorSettings(), $feature_settings);
  $this
    ->assertEquals((string) $paragraph
    ->getSummary(), '<div class="paragraphs-description paragraphs-collapsed-description"><div class="paragraphs-content-wrapper"><span class="summary-content">Example text for a text paragraph</span></div><div class="paragraphs-plugin-wrapper"><span class="summary-plugin"><span class="summary-plugin-label">Text color</span>red</span></div></div>');

  // Check the summary and the additional options.
  $paragraph_1 = Paragraph::create([
    'type' => 'nested_paragraph',
    'nested_paragraph_field' => [
      $paragraph,
    ],
  ]);
  $paragraph_1
    ->save();

  // We do not include behavior summaries of nested children in the parent
  // summary.
  $this
    ->assertEquals((string) $paragraph_1
    ->getSummary(), '<div class="paragraphs-description paragraphs-collapsed-description"><div class="paragraphs-content-wrapper"><span class="summary-content">Example text for a text paragraph</span></div></div>');
  $info = $paragraph_1
    ->getIcons();
  $this
    ->assertEquals($info['count']['#prefix'], '<span class="paragraphs-badge" title="1 child">');
  $this
    ->assertEquals($info['count']['#suffix'], '</span>');
  $this
    ->assertEquals((string) $paragraph_1
    ->getSummary([
    'depth_limit' => 0,
  ]), '');
}