You are here

public function ActionTestBase::testAccess in Organic groups 8

Checks that the user can perform the action on the membership.

@covers ::access

File

tests/src/Kernel/Action/ActionTestBase.php, line 209

Class

ActionTestBase
Base class for testing action plugins.

Namespace

Drupal\Tests\og\Kernel\Action

Code

public function testAccess() {

  // Dramatically improve testing speed by looping over all test cases in a
  // single test, so that the expensive setup is not executed over and over.
  $test_cases = $this
    ->accessProvider();
  foreach ($test_cases as $test_case) {
    list($user, $membership) = $test_case;

    // When testing the group owner, configure whether or not they have full
    // access.
    if ($user === 'group_owner') {
      $this
        ->config('og.settings')
        ->set('group_manager_full_access', $test_case[2])
        ->save();
    }
    $plugin = $this
      ->getPlugin();
    $access_as_object = $plugin
      ->access($this->memberships[$membership], $this->users[$user], TRUE);
    $this
      ->assertTrue($access_as_object instanceof AccessResultAllowed, "{$user} {$membership}");
    $access_as_boolean = $plugin
      ->access($this->memberships[$membership], $this->users[$user], FALSE);
    $this
      ->assertTrue($access_as_boolean);
  }
}