public function EntityListBuilderTest::testGetOperations in Drupal 8
Same name and namespace in other branches
- 9 core/tests/Drupal/Tests/Core/Entity/EntityListBuilderTest.php \Drupal\Tests\Core\Entity\EntityListBuilderTest::testGetOperations()
- 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 100 - Contains \Drupal\Tests\Core\Entity\EntityListBuilderTest.
Class
- EntityListBuilderTest
- @coversDefaultClass \Drupal\entity_test\EntityTestListBuilder @group Entity
Namespace
Drupal\Tests\Core\EntityCode
public function testGetOperations() {
$operation_name = $this
->randomMachineName();
$operations = [
$operation_name => [
'title' => $this
->randomMachineName(),
],
];
$this->moduleHandler
->expects($this
->once())
->method('invokeAll')
->with('entity_operation', [
$this->role,
])
->will($this
->returnValue($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')
->will($this
->returnValue(AccessResult::allowed()));
$this->role
->expects($this
->any())
->method('hasLinkTemplate')
->will($this
->returnValue(TRUE));
$url = $this
->getMockBuilder('\\Drupal\\Core\\Url')
->disableOriginalConstructor()
->getMock();
$url
->expects($this
->atLeastOnce())
->method('mergeOptions')
->with([
'query' => [
'destination' => '/foo/bar',
],
]);
$this->role
->expects($this
->any())
->method('toUrl')
->will($this
->returnValue($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]);
}