You are here

public function AccessCheckTest::testCheckAccessAsGuestWithTermRestriction in Permissions by Term 8.2

File

tests/src/Kernel/AccessCheckTest.php, line 128

Class

AccessCheckTest
Class AccessCheckTest

Namespace

Drupal\Tests\permissions_by_term\Kernel

Code

public function testCheckAccessAsGuestWithTermRestriction() : void {
  $termRestricted = Term::create([
    'name' => 'term1',
    'vid' => 'test',
  ]);
  $termRestricted
    ->save();
  $termNotRestricted = Term::create([
    'name' => 'term1',
    'vid' => 'test',
  ]);
  $termNotRestricted
    ->save();
  $this->accessStorage
    ->addTermPermissionsByUserIds([
    1,
  ], $termRestricted
    ->id());
  self::assertFalse($this->accessCheck
    ->isAccessAllowedByDatabase($termRestricted
    ->id(), 0));
  $node = Node::create([
    'type' => 'page',
    'title' => 'test_title',
    'field_tags' => [
      [
        'target_id' => $termRestricted
          ->id(),
      ],
      [
        'target_id' => $termNotRestricted
          ->id(),
      ],
    ],
  ]);
  $node
    ->save();
  self::assertFalse($this->accessCheck
    ->canUserAccessByNode($node, 0));
}