You are here

public function TaxonomyAccessTest::testCreateAccess in Workbench Access 8

Test create access integration.

File

tests/src/Kernel/TaxonomyAccessTest.php, line 121

Class

TaxonomyAccessTest
Tests workbench_access integration with taxonomy.

Namespace

Drupal\Tests\workbench_access\Kernel

Code

public function testCreateAccess() {

  // The first user in a kernel test gets UID 1, so we need to make sure we're
  // not testing with that user.
  $this
    ->createUser();

  // Create a section.
  $term = Term::create([
    'vid' => $this->vocabulary
      ->id(),
    'name' => 'Some section',
  ]);
  $term
    ->save();

  // Create two users with equal permissions but assign one of them to the
  // section.
  $version = Drupal::VERSION;
  $permissions = $this
    ->getPermissions();
  $allowed_editor = $this
    ->createUser($permissions);
  $allowed_editor
    ->save();
  $this->userStorage
    ->addUser($this->scheme, $allowed_editor, [
    $term
      ->id(),
  ]);
  $editor_with_no_access = $this
    ->createUser($permissions);
  $permissions[] = 'bypass workbench access';
  $editor_with_bypass_access = $this
    ->createUser($permissions);
  $this
    ->assertTrue($this->accessHandler
    ->createAccess('tags', $allowed_editor));
  $this
    ->assertFalse($this->accessHandler
    ->createAccess('tags', $editor_with_no_access));
  $this
    ->assertTrue($this->accessHandler
    ->createAccess('tags', $editor_with_bypass_access));
}