public function ScheduledTransitionsEntityHooksUnitTest::testEntityAccessViewOperationNoPermission in Scheduled Transitions 8
Same name and namespace in other branches
- 2.x tests/src/Unit/ScheduledTransitionsEntityHooksUnitTest.php \Drupal\Tests\scheduled_transitions\Unit\ScheduledTransitionsEntityHooksUnitTest::testEntityAccessViewOperationNoPermission()
Tests view operation, and when user doesn't have permission.
No permission returns neutral with correct cacheabiltiy.
@covers ::entityAccess
File
- tests/
src/ Unit/ ScheduledTransitionsEntityHooksUnitTest.php, line 93
Class
- ScheduledTransitionsEntityHooksUnitTest
- Tests entity hooks.
Namespace
Drupal\Tests\scheduled_transitions\UnitCode
public function testEntityAccessViewOperationNoPermission() : void {
\Drupal::setContainer($this->testContainer);
$entityHooks = new ScheduledTransitionsEntityHooks($this->testConfigFactory, $this->testEntityTypeManager, $this->testModerationInformation);
$entity = $this
->createMock(EntityInterface::class);
$entity
->expects($this
->once())
->method('getEntityTypeId')
->willReturn('foo');
$entity
->expects($this
->once())
->method('bundle')
->willReturn('bar');
$operation = ScheduledTransitionsPermissions::ENTITY_OPERATION_VIEW_TRANSITIONS;
$account = $this
->createMock(AccountInterface::class);
$account
->expects($this
->once())
->method('hasPermission')
->with('view scheduled transitions foo bar')
->willReturn(FALSE);
/** @var \Drupal\Core\Access\AccessResultForbidden $access */
$access = $entityHooks
->entityAccess($entity, $operation, $account);
$this
->assertInstanceOf(AccessResultForbidden::class, $access);
$this
->assertEquals([
'user.permissions',
], $access
->getCacheContexts());
$this
->assertEquals("The 'view scheduled transitions foo bar' permission is required.", $access
->getReason());
}