You are here

public function GroupCheckTest::testPermissions in Organic groups 8

Tests an in-accessible and accessible routes.

@covers ::access @dataProvider permissionsProvider

File

tests/src/Unit/GroupCheckTest.php, line 223

Class

GroupCheckTest
Tests the group check access.

Namespace

Drupal\Tests\og\Unit

Code

public function testPermissions($permissions, $expected) {
  $this->entityTypeManager
    ->getDefinition($this->entityTypeId, FALSE)
    ->willReturn($this->entityType);
  $this->entityTypeManager
    ->getStorage($this->entityTypeId)
    ->willReturn($this->entityStorage);
  $this->entityStorage
    ->load($this->entityId)
    ->willReturn($this->group);
  $this->group
    ->bundle()
    ->willReturn($this->bundle);
  $this->groupTypeManager
    ->isGroup($this->entityTypeId, $this->bundle)
    ->willReturn(TRUE);
  $this->route
    ->getRequirement('_og_user_access_group')
    ->willReturn($permissions);
  foreach (explode('|', $permissions) as $permission) {

    // Check explicitly that only the permissions we passed were used.
    $this->ogAccess
      ->userAccess($this->group
      ->reveal(), $permission, $this->user
      ->reveal())
      ->willReturn($this->accessResult);
  }
  $this->accessResult
    ->isAllowed()
    ->willReturn($expected);
  $result = $this
    ->getAccessResult();
  $actual = $expected ? $result
    ->isAllowed() : $result
    ->isForbidden();
  $this
    ->assertTrue($actual);
}