function EntityOperationsUnitTest::testRenderWithDestination

Same name in other branches
  1. 9 core/modules/views/tests/src/Unit/Plugin/views/field/EntityOperationsUnitTest.php \Drupal\Tests\views\Unit\Plugin\views\field\EntityOperationsUnitTest::testRenderWithDestination()
  2. 8.9.x core/modules/views/tests/src/Unit/Plugin/views/field/EntityOperationsUnitTest.php \Drupal\Tests\views\Unit\Plugin\views\field\EntityOperationsUnitTest::testRenderWithDestination()
  3. 11.x core/modules/views/tests/src/Unit/Plugin/views/field/EntityOperationsUnitTest.php \Drupal\Tests\views\Unit\Plugin\views\field\EntityOperationsUnitTest::testRenderWithDestination()

@covers ::render

File

core/modules/views/tests/src/Unit/Plugin/views/field/EntityOperationsUnitTest.php, line 104

Class

EntityOperationsUnitTest
@coversDefaultClass \Drupal\views\Plugin\views\field\EntityOperations @group Views

Namespace

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

Code

public function testRenderWithDestination() : void {
    $entity_type_id = $this->randomMachineName();
    $entity = $this->getMockBuilder('\\Drupal\\user\\Entity\\Role')
        ->disableOriginalConstructor()
        ->getMock();
    $entity->expects($this->any())
        ->method('getEntityTypeId')
        ->willReturn($entity_type_id);
    $operations = [
        'foo' => [
            'title' => $this->randomMachineName(),
        ],
    ];
    $list_builder = $this->createMock('\\Drupal\\Core\\Entity\\EntityListBuilderInterface');
    $list_builder->expects($this->once())
        ->method('getOperations')
        ->with($entity)
        ->willReturn($operations);
    $this->entityTypeManager
        ->expects($this->once())
        ->method('getListBuilder')
        ->with($entity_type_id)
        ->willReturn($list_builder);
    $this->plugin->options['destination'] = TRUE;
    $result = new ResultRow();
    $result->_entity = $entity;
    $expected_build = [
        '#type' => 'operations',
        '#links' => $operations,
    ];
    $expected_build['#links']['foo']['query'] = [
        'destination' => 'foobar',
    ];
    $build = $this->plugin
        ->render($result);
    $this->assertSame($expected_build, $build);
}

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