function EntityConcurrentRenderTest::testSameEntityInMultipleBlocks

Same name and namespace in other branches
  1. 11.x core/tests/Drupal/FunctionalTests/Entity/EntityConcurrentRenderTest.php \Drupal\FunctionalTests\Entity\EntityConcurrentRenderTest::testSameEntityInMultipleBlocks()

Tests that two blocks rendering the same entity both produce output.

File

core/tests/Drupal/FunctionalTests/Entity/EntityConcurrentRenderTest.php, line 68

Class

EntityConcurrentRenderTest
Tests that the same entity can be rendered multiple times on a page.

Namespace

Drupal\FunctionalTests\Entity

Code

public function testSameEntityInMultipleBlocks() : void {
  $entity = EntityTest::create([
    'name' => 'Unique entity content',
    'body' => [
      'value' => 'Body text',
      'format' => 'plain_text',
    ],
  ]);
  $entity->save();
  $this->drupalPlaceBlock('entity_test_block', [
    'id' => 'first',
    'label' => 'First',
    'entity_id' => $entity->id(),
  ]);
  $this->drupalPlaceBlock('entity_test_block', [
    'id' => 'second',
    'label' => 'Second',
    'entity_id' => $entity->id(),
  ]);
  $this->drupalGet('<front>');
  // Both blocks should render the entity content.
  $first = $this->assertSession()
    ->elementExists('css', '#block-first');
  $second = $this->assertSession()
    ->elementExists('css', '#block-second');
  $this->assertStringContainsString('Unique entity content', $first->getText());
  $this->assertStringContainsString('Unique entity content', $second->getText());
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.