You are here

public function NodeMenuTest::testCreateAccess in Workbench Access 8

Test create access integration.

File

tests/src/Kernel/NodeMenuTest.php, line 97

Class

NodeMenuTest
Tests workbench_access integration with node access via menu plugin.

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 menu link.
  $link = MenuLinkContent::create([
    'title' => 'Home',
    'link' => [
      [
        'uri' => 'route:<front>',
      ],
    ],
    'menu_name' => 'main',
  ]);
  $link
    ->save();

  // Create two users with equal permissions but assign one of them to the
  // section.
  $permissions = [
    'create page content',
    'create article content',
    'edit any page content',
    'access content',
    'delete any page content',
    'administer nodes',
  ];
  $allowed_editor = $this
    ->createUser($permissions);
  $allowed_editor
    ->save();
  $this->userStorage
    ->addUser($this->scheme, $allowed_editor, [
    $link
      ->getPluginId(),
  ]);
  $editor_with_no_access = $this
    ->createUser($permissions);
  $permissions[] = 'bypass workbench access';
  $editor_with_bypass_access = $this
    ->createUser($permissions);
  $this
    ->assertTrue($this->accessHandler
    ->createAccess('page', $allowed_editor));
  $this
    ->assertFalse($this->accessHandler
    ->createAccess('page', $editor_with_no_access));
  $this
    ->assertTrue($this->accessHandler
    ->createAccess('page', $editor_with_bypass_access));

  // Non access controlled bundles should be allowed.
  $this
    ->assertTrue($this->accessHandler
    ->createAccess('article', $allowed_editor));
  $this
    ->assertTrue($this->accessHandler
    ->createAccess('article', $editor_with_no_access));
  $this
    ->assertTrue($this->accessHandler
    ->createAccess('article', $editor_with_bypass_access));
}