public function ScheduledTransitionsEntityHooksUnitTest::testEntityAccessViewOperationHasPermissionNoMirroring in Scheduled Transitions 8
Same name and namespace in other branches
- 2.x tests/src/Unit/ScheduledTransitionsEntityHooksUnitTest.php \Drupal\Tests\scheduled_transitions\Unit\ScheduledTransitionsEntityHooksUnitTest::testEntityAccessViewOperationHasPermissionNoMirroring()
Tests view operation, and when user has permission, but no mirroring.
@covers ::entityAccess
File
- tests/
src/ Unit/ ScheduledTransitionsEntityHooksUnitTest.php, line 159
Class
- ScheduledTransitionsEntityHooksUnitTest
- Tests entity hooks.
Namespace
Drupal\Tests\scheduled_transitions\UnitCode
public function testEntityAccessViewOperationHasPermissionNoMirroring() : 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(NULL);
$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
->never())
->method('access');
/** @var \Drupal\Core\Access\AccessResultForbidden $access */
$access = $entityHooks
->entityAccess($entity, $operation, $account);
$this
->assertInstanceOf(AccessResultNeutral::class, $access);
$this
->assertEquals([
'user.permissions',
], $access
->getCacheContexts());
$this
->assertNull($access
->getReason());
$this
->assertEquals([
ScheduledTransitionsSettingsForm::SETTINGS_TAG,
], $access
->getCacheTags());
}