You are here

public function OgMenuAccessTest::testOgMenuEntityAccess in Organic Groups Menu (OG Menu) 8

Test access to the administration section.

File

tests/src/Kernel/OgMenuAccessTest.php, line 182

Class

OgMenuAccessTest
Tests access to operations on OG Menu instances.

Namespace

Drupal\Tests\og_menu\Kernel

Code

public function testOgMenuEntityAccess() {
  $expected_operations = [
    'uid1' => [
      'create' => TRUE,
      'update' => TRUE,
      'view' => TRUE,
      'delete' => TRUE,
    ],
    'ogadmin' => [
      'create' => FALSE,
      'update' => FALSE,
      'view' => FALSE,
      'delete' => FALSE,
    ],
    'ogmenuadmin' => [
      'create' => TRUE,
      'update' => TRUE,
      'view' => TRUE,
      'delete' => TRUE,
    ],
    'groupadmin' => [
      'create' => FALSE,
      'update' => FALSE,
      'view' => FALSE,
      'delete' => FALSE,
    ],
    'groupmember' => [
      'create' => FALSE,
      'update' => FALSE,
      'view' => FALSE,
      'delete' => FALSE,
    ],
    'authenticated' => [
      'create' => FALSE,
      'update' => FALSE,
      'view' => FALSE,
      'delete' => FALSE,
    ],
  ];
  foreach ($expected_operations as $user_key => $operations) {
    \Drupal::currentUser()
      ->setAccount($this->users[$user_key]);
    foreach ($operations as $operation => $expected) {
      $message = "User {$user_key} " . ($expected ? 'has' : 'does not have') . " access to the {$operation} operation.";
      $this
        ->assertEquals($expected, $this->ogMenu
        ->access($operation), $message);
    }
  }
  $this
    ->assertFalse($this->ogMenu
    ->access('update'));
}