You are here

public function AccessCheckTest::testSingleTermRestrictionWithNoRestrictedTerms in Permissions by Term 8

Return value

void

File

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

Class

AccessCheckTest
Class AccessCheckTest

Namespace

Drupal\Tests\permissions_by_term\Kernel

Code

public function testSingleTermRestrictionWithNoRestrictedTerms() {
  $database = $this->container
    ->get('database');
  $database
    ->truncate('node_access')
    ->execute();
  $this
    ->createRelationWithoutRestriction();
  \Drupal::configFactory()
    ->getEditable('permissions_by_term.settings.single_term_restriction')
    ->set('value', TRUE)
    ->save();
  $this
    ->assertTrue($this->accessCheck
    ->canUserAccessByNodeId($this
    ->getNidOneGrantedTerm()));
  node_access_rebuild();
  $gids = $this->accessStorage
    ->getGids(\Drupal::service('current_user'));
  $nodeAccess = $database
    ->select('node_access', 'na')
    ->fields('na', [
    'nid',
  ])
    ->condition('na.gid', $gids['permissions_by_term'], 'IN')
    ->condition('na.realm', AccessStorage::NODE_ACCESS_REALM);
  $permittedNids = $nodeAccess
    ->execute()
    ->fetchCol();
  $this
    ->assertCount(0, $permittedNids);
}