function LinkBaseTest::testRenderNullEntity

Same name in other branches
  1. 11.x core/modules/views/tests/src/Unit/Plugin/views/field/LinkBaseTest.php \Drupal\Tests\views\Unit\Plugin\views\field\LinkBaseTest::testRenderNullEntity()

Tests the render method when getEntity returns NULL.

@covers ::render

File

core/modules/views/tests/src/Unit/Plugin/views/field/LinkBaseTest.php, line 46

Class

LinkBaseTest
@coversDefaultClass \Drupal\views\Plugin\views\field\EntityLink @group Views

Namespace

Drupal\Tests\views\Unit\Plugin\views\field

Code

public function testRenderNullEntity() : void {
    $row = new ResultRow();
    $access = new AccessResultAllowed();
    $languageManager = $this->createMock(LanguageManagerInterface::class);
    $languageManager->expects($this->any())
        ->method('isMultilingual')
        ->willReturn(TRUE);
    $field = $this->getMockBuilder(LinkBase::class)
        ->setConstructorArgs([
        [
            'entity_type' => 'foo',
            'entity field' => 'bar',
        ],
        'foo',
        [],
        $this->createMock(AccessManagerInterface::class),
        $this->createMock(EntityTypeManagerInterface::class),
        $this->createMock(EntityRepositoryInterface::class),
        $languageManager,
    ])
        ->onlyMethods([
        'checkUrlAccess',
        'getUrlInfo',
    ])
        ->getMock();
    $field->expects($this->any())
        ->method('checkUrlAccess')
        ->willReturn($access);
    $view = $this->createMock(ViewExecutable::class);
    $display = $this->createMock(DisplayPluginBase::class);
    $field->init($view, $display);
    $field_built = $field->render($row);
    $this->assertEquals('', \Drupal::service('renderer')->render($field_built));
}

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