function EntityTest::testRenderWithIdAndToken

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

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

@dataProvider providerTestTokens

File

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

Class

EntityTest
@coversDefaultClass <a href="/api/drupal/core%21modules%21views%21src%21Plugin%21views%21area%21Entity.php/class/Entity/11.x" title="Provides an area handler which renders an entity in a certain view mode." class="local">\Drupal\views\Plugin\views\area\Entity</a> @group Entity

Namespace

Drupal\Tests\views\Unit\Plugin\area

Code

public function testRenderWithIdAndToken($token, $id) : void {
    $this->setupEntityTypeManager();
    $options = [
        'target' => $token,
        'tokenize' => TRUE,
    ];
    $entity = $this->createMock('Drupal\\Core\\Entity\\EntityInterface');
    $entity->expects($this->once())
        ->method('access')
        ->willReturn(TRUE);
    $this->stylePlugin
        ->expects($this->once())
        ->method('tokenizeValue')
        ->with($token, 0)
        ->willReturn($id);
    $this->entityStorage
        ->expects($this->never())
        ->method('loadByProperties');
    $this->entityStorage
        ->expects($this->once())
        ->method('load')
        ->with($id)
        ->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.