You are here

public function ScheduledTransitionsEntityHooksUnitTest::testEntityAccessAddOperationHasPermissionNoMirroring in Scheduled Transitions 8

Same name and namespace in other branches
  1. 2.x tests/src/Unit/ScheduledTransitionsEntityHooksUnitTest.php \Drupal\Tests\scheduled_transitions\Unit\ScheduledTransitionsEntityHooksUnitTest::testEntityAccessAddOperationHasPermissionNoMirroring()

Tests add operation, and when user has permission, but no mirroring.

@covers ::entityAccess

File

tests/src/Unit/ScheduledTransitionsEntityHooksUnitTest.php, line 206

Class

ScheduledTransitionsEntityHooksUnitTest
Tests entity hooks.

Namespace

Drupal\Tests\scheduled_transitions\Unit

Code

public function testEntityAccessAddOperationHasPermissionNoMirroring() : void {
  \Drupal::setContainer($this->testContainer);
  $testConfig = $this
    ->createMock(ImmutableConfig::class);
  $testConfig
    ->expects($this
    ->once())
    ->method('get')
    ->with('mirror_operations.' . ScheduledTransitionsPermissions::ENTITY_OPERATION_ADD_TRANSITION)
    ->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_ADD_TRANSITION;
  $account = $this
    ->createMock(AccountInterface::class);
  $account
    ->expects($this
    ->once())
    ->method('hasPermission')
    ->with('add 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());
}