public function ParagraphsCollapsedSummaryTest::testMultipleEntityReferences

Tests multiple entity references are visible in the paragraph summary.

File

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

Class

ParagraphsCollapsedSummaryTest
Tests the collapsed summary options.

Namespace

Drupal\Tests\paragraphs\Kernel

Code

public function testMultipleEntityReferences() {
  $user1 = $this
    ->createUser([], 'bob');
  $user2 = $this
    ->createUser([], 'pete');
  $paragraphs_type = ParagraphsType::create([
    'label' => 'Multiple entity references',
    'id' => 'multiple_entity_references',
  ]);
  $paragraphs_type
    ->save();
  $this
    ->createEntityReferenceField('paragraph', 'multiple_entity_references', 'field_user_references', 'Users', 'user', 'default', [], FieldStorageDefinitionInterface::CARDINALITY_UNLIMITED);
  EntityFormDisplay::create([
    'targetEntityType' => 'paragraph',
    'bundle' => 'multiple_entity_references',
    'mode' => 'default',
    'status' => TRUE,
  ])
    ->setComponent('field_user_references', [
    'type' => 'options_select',
  ])
    ->save();
  $paragraph_with_multiple_entity_references = Paragraph::create([
    'type' => 'multiple_entity_references',
  ]);
  $paragraph_with_multiple_entity_references
    ->get('field_user_references')
    ->appendItem($user1
    ->id());
  $paragraph_with_multiple_entity_references
    ->get('field_user_references')
    ->appendItem($user2
    ->id());
  $paragraph_with_multiple_entity_references
    ->save();
  $this
    ->assertEquals('<div class="paragraphs-description paragraphs-collapsed-description"><div class="paragraphs-content-wrapper"><span class="summary-content">bob</span>, <span class="summary-content">pete</span></div></div>', (string) $paragraph_with_multiple_entity_references
    ->getSummary());
}