public function ScheduledTransitionsEntityHooksUnitTest::testEntityAccessAddOperationNoPermission in Scheduled Transitions 8
Same name and namespace in other branches
- 2.x tests/src/Unit/ScheduledTransitionsEntityHooksUnitTest.php \Drupal\Tests\scheduled_transitions\Unit\ScheduledTransitionsEntityHooksUnitTest::testEntityAccessAddOperationNoPermission()
Tests add operation, and when user doesn't have permission.
No permission returns neutral with correct cacheabiltiy.
@covers ::entityAccess
File
- tests/
src/ Unit/ ScheduledTransitionsEntityHooksUnitTest.php, line 127
Class
- ScheduledTransitionsEntityHooksUnitTest
- Tests entity hooks.
Namespace
Drupal\Tests\scheduled_transitions\UnitCode
public function testEntityAccessAddOperationNoPermission() : 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_ADD_TRANSITION;
$account = $this
->createMock(AccountInterface::class);
$account
->expects($this
->once())
->method('hasPermission')
->with('add 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 'add scheduled transitions foo bar' permission is required.", $access
->getReason());
}