You are here

public function LatestRevisionCheckTest::testLatestAccessPermissions in Workbench Moderation 8.2

Same name and namespace in other branches
  1. 8 tests/src/Unit/LatestRevisionCheckTest.php \Drupal\Tests\workbench_moderation\Unit\LatestRevisionCheckTest::testLatestAccessPermissions()

Test the access check of the LatestRevisionCheck service.

@dataProvider accessSituationProvider

Parameters

string $entity_class: The class of the entity to mock.

string $entity_type: The machine name of the entity to mock.

bool $has_forward: Whether this entity should have a forward revision in the system.

string $result_class: The AccessResult class that should result. One of AccessResultAllowed, AccessResultForbidden, AccessResultNeutral.

File

tests/src/Unit/LatestRevisionCheckTest.php, line 38

Class

LatestRevisionCheckTest
@coversDefaultClass \Drupal\workbench_moderation\Access\LatestRevisionCheck @group workbench_moderation

Namespace

Drupal\Tests\workbench_moderation\Unit

Code

public function testLatestAccessPermissions($entity_class, $entity_type, $has_forward, $result_class) {

  /** @var EntityInterface $entity */
  $entity = $this
    ->prophesize($entity_class);
  $entity
    ->getCacheContexts()
    ->willReturn([]);
  $entity
    ->getCacheTags()
    ->willReturn([]);
  $entity
    ->getCacheMaxAge()
    ->willReturn(0);

  /** @var ModerationInformationInterface $mod_info */
  $mod_info = $this
    ->prophesize(ModerationInformation::class);
  $mod_info
    ->hasForwardRevision($entity
    ->reveal())
    ->willReturn($has_forward);
  $route = $this
    ->prophesize(Route::class);
  $route
    ->getOption('_workbench_moderation_entity_type')
    ->willReturn($entity_type);
  $route_match = $this
    ->prophesize(RouteMatch::class);
  $route_match
    ->getParameter($entity_type)
    ->willReturn($entity
    ->reveal());
  $lrc = new LatestRevisionCheck($mod_info
    ->reveal());

  /** @var AccessResult $result */
  $result = $lrc
    ->access($route
    ->reveal(), $route_match
    ->reveal());
  $this
    ->assertInstanceOf($result_class, $result);
}