function EntityListBuilderTest::testGetOperations

Same name and namespace in other branches
  1. 9 core/tests/Drupal/Tests/Core/Entity/EntityListBuilderTest.php \Drupal\Tests\Core\Entity\EntityListBuilderTest::testGetOperations()
  2. 8.9.x core/tests/Drupal/Tests/Core/Entity/EntityListBuilderTest.php \Drupal\Tests\Core\Entity\EntityListBuilderTest::testGetOperations()
  3. 10 core/tests/Drupal/Tests/Core/Entity/EntityListBuilderTest.php \Drupal\Tests\Core\Entity\EntityListBuilderTest::testGetOperations()

@covers ::getOperations

File

core/tests/Drupal/Tests/Core/Entity/EntityListBuilderTest.php, line 98

Class

EntityListBuilderTest
@coversDefaultClass <a href="/api/drupal/core%21lib%21Drupal%21Core%21Entity%21EntityListBuilder.php/class/EntityListBuilder/11.x" title="Defines a generic implementation to build a listing of entities." class="local">\Drupal\Core\Entity\EntityListBuilder</a> @group Entity

Namespace

Drupal\Tests\Core\Entity

Code

public function testGetOperations() : void {
    $operation_name = $this->randomMachineName();
    $operations = [
        $operation_name => [
            'title' => $this->randomMachineName(),
        ],
    ];
    $this->moduleHandler
        ->expects($this->once())
        ->method('invokeAll')
        ->with('entity_operation', [
        $this->role,
    ])
        ->willReturn($operations);
    $this->moduleHandler
        ->expects($this->once())
        ->method('alter')
        ->with('entity_operation');
    $this->container
        ->set('module_handler', $this->moduleHandler);
    $this->role
        ->expects($this->any())
        ->method('access')
        ->willReturn(AccessResult::allowed());
    $this->role
        ->expects($this->any())
        ->method('hasLinkTemplate')
        ->willReturn(TRUE);
    $url = Url::fromRoute('entity.user_role.collection');
    $this->role
        ->expects($this->any())
        ->method('toUrl')
        ->willReturn($url);
    $this->redirectDestination
        ->expects($this->atLeastOnce())
        ->method('getAsArray')
        ->willReturn([
        'destination' => '/foo/bar',
    ]);
    $list = new EntityListBuilder($this->entityType, $this->roleStorage);
    $list->setStringTranslation($this->translationManager);
    $list->setRedirectDestination($this->redirectDestination);
    $operations = $list->getOperations($this->role);
    $this->assertIsArray($operations);
    $this->assertArrayHasKey('edit', $operations);
    $this->assertIsArray($operations['edit']);
    $this->assertArrayHasKey('title', $operations['edit']);
    $this->assertArrayHasKey('delete', $operations);
    $this->assertIsArray($operations['delete']);
    $this->assertArrayHasKey('title', $operations['delete']);
    $this->assertArrayHasKey($operation_name, $operations);
    $this->assertIsArray($operations[$operation_name]);
    $this->assertArrayHasKey('title', $operations[$operation_name]);
}

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