public function ScheduledTransitionsEntityHooksUnitTest::testEntityAccessViewOperationHasPermissionWithMirroring in Scheduled Transitions 8
Same name and namespace in other branches
- 2.x tests/src/Unit/ScheduledTransitionsEntityHooksUnitTest.php \Drupal\Tests\scheduled_transitions\Unit\ScheduledTransitionsEntityHooksUnitTest::testEntityAccessViewOperationHasPermissionWithMirroring()
Tests view operation, and when user has permission, but no mirroring.
@covers ::entityAccess
File
- tests/
src/ Unit/ ScheduledTransitionsEntityHooksUnitTest.php, line 253
Class
- ScheduledTransitionsEntityHooksUnitTest
- Tests entity hooks.
Namespace
Drupal\Tests\scheduled_transitions\UnitCode
public function testEntityAccessViewOperationHasPermissionWithMirroring() : void {
\Drupal::setContainer($this->testContainer);
$testConfig = $this
->createMock(ImmutableConfig::class);
$testConfig
->expects($this
->once())
->method('get')
->with('mirror_operations.' . ScheduledTransitionsPermissions::ENTITY_OPERATION_VIEW_TRANSITIONS)
->willReturn('testop');
$this->testConfigFactory
->expects($this
->once())
->method('get')
->with('scheduled_transitions.settings')
->willReturn($testConfig);
$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(TRUE);
$entity
->expects($this
->once())
->method('access')
->with('testop', $account, TRUE)
->willReturn(AccessResult::forbidden('no can do'));
/** @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('no can do', $access
->getReason());
$this
->assertEquals([
ScheduledTransitionsSettingsForm::SETTINGS_TAG,
], $access
->getCacheTags());
}