function NodeOperationAccessTest::testRevisionOperations
Same name in other branches
- 9 core/modules/node/tests/src/Unit/NodeOperationAccessTest.php \Drupal\Tests\node\Unit\NodeOperationAccessTest::testRevisionOperations()
- 11.x core/modules/node/tests/src/Unit/NodeOperationAccessTest.php \Drupal\Tests\node\Unit\NodeOperationAccessTest::testRevisionOperations()
Tests revision operations.
@dataProvider providerTestRevisionOperations
Parameters
string $operation: A revision operation.
array $hasPermissionMap: A map of permissions, to whether they should be granted.
bool|null $assertAccess: Whether the access is allowed or denied.
bool|null $isDefaultRevision: Whether the node should be default revision, or NULL if not to expect it to be called.
File
-
core/
modules/ node/ tests/ src/ Unit/ NodeOperationAccessTest.php, line 60
Class
- NodeOperationAccessTest
- Tests node operations.
Namespace
Drupal\Tests\node\UnitCode
public function testRevisionOperations($operation, array $hasPermissionMap, $assertAccess, $isDefaultRevision = NULL) : void {
$account = $this->createMock(AccountInterface::class);
$account->method('hasPermission')
->willReturnMap($hasPermissionMap);
$entityType = $this->createMock(EntityTypeInterface::class);
$grants = $this->createMock(NodeGrantDatabaseStorageInterface::class);
$grants->expects($this->any())
->method('access')
->willReturn(AccessResult::neutral());
$language = $this->createMock(LanguageInterface::class);
$language->expects($this->any())
->method('getId')
->willReturn('de');
$nid = 333;
/** @var \Drupal\node\NodeInterface|\PHPUnit\Framework\MockObject\MockObject $node */
$node = $this->createMock(NodeInterface::class);
$node->expects($this->any())
->method('language')
->willReturn($language);
$node->expects($this->any())
->method('id')
->willReturn($nid);
$node->expects($this->any())
->method('getCacheContexts')
->willReturn([]);
$node->expects($this->any())
->method('getCacheTags')
->willReturn([]);
$node->expects($this->any())
->method('getCacheMaxAge')
->willReturn(-1);
$node->expects($this->any())
->method('getEntityTypeId')
->willReturn('node');
if (isset($isDefaultRevision)) {
$node->expects($this->atLeastOnce())
->method('isDefaultRevision')
->willReturn($isDefaultRevision);
}
$nodeStorage = $this->createMock(NodeStorageInterface::class);
$nodeStorage->expects($this->any())
->method('load')
->with($nid)
->willReturn($node);
$entityTypeManager = $this->createMock(EntityTypeManagerInterface::class);
$entityTypeManager->expects($this->any())
->method('getStorage')
->with('node')
->willReturn($nodeStorage);
$moduleHandler = $this->createMock(ModuleHandlerInterface::class);
$moduleHandler->expects($this->any())
->method('invokeAll')
->willReturn([]);
$accessControl = new NodeAccessControlHandler($entityType, $grants, $entityTypeManager);
$accessControl->setModuleHandler($moduleHandler);
$access = $accessControl->access($node, $operation, $account, FALSE);
$this->assertEquals($assertAccess, $access);
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.