function EntityTest::testRenderWithId

Same name in other branches
  1. 8.9.x core/modules/views/tests/src/Unit/Plugin/area/EntityTest.php \Drupal\Tests\views\Unit\Plugin\area\EntityTest::testRenderWithId()
  2. 10 core/modules/views/tests/src/Unit/Plugin/area/EntityTest.php \Drupal\Tests\views\Unit\Plugin\area\EntityTest::testRenderWithId()
  3. 11.x core/modules/views/tests/src/Unit/Plugin/area/EntityTest.php \Drupal\Tests\views\Unit\Plugin\area\EntityTest::testRenderWithId()

@covers ::render @covers ::defineOptions @covers ::init

File

core/modules/views/tests/src/Unit/Plugin/area/EntityTest.php, line 158

Class

EntityTest
@coversDefaultClass \Drupal\views\Plugin\views\area\Entity @group Entity

Namespace

Drupal\Tests\views\Unit\Plugin\area

Code

public function testRenderWithId() {
    $this->setupEntityTypeManager();
    $options = [
        'target' => 1,
        'tokenize' => FALSE,
    ];
    
    /** @var \Drupal\Core\Entity\EntityInterface $entity */
    $entity = $this->createMock('Drupal\\Core\\Entity\\EntityInterface');
    $entity->expects($this->once())
        ->method('access')
        ->willReturn(TRUE);
    $this->entityStorage
        ->expects($this->never())
        ->method('loadByProperties');
    $this->entityRepository
        ->expects($this->any())
        ->method('loadEntityByConfigTarget')
        ->willReturn($entity);
    $this->entityViewBuilder
        ->expects($this->once())
        ->method('view')
        ->with($entity, 'default')
        ->willReturn([
        '#markup' => 'hallo',
    ]);
    $this->entityHandler
        ->init($this->executable, $this->display, $options);
    $result = $this->entityHandler
        ->render();
    $this->assertEquals([
        '#markup' => 'hallo',
    ], $result);
}

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