You are here

public function AccessCheckTest::testDisabledRequireAllTermsGranted in Permissions by Term 8.2

File

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

Class

AccessCheckTest
Class AccessCheckTest

Namespace

Drupal\Tests\permissions_by_term\Kernel

Code

public function testDisabledRequireAllTermsGranted() : void {
  $database = $this->container
    ->get('database');
  $database
    ->truncate('node_access')
    ->execute();
  $this
    ->createRelationOneGrantedTerm();
  $this
    ->createRelationAllGrantedTerms();
  \Drupal::configFactory()
    ->getEditable('permissions_by_term.settings')
    ->set('require_all_terms_granted', FALSE)
    ->save();
  $this
    ->assertTrue($this->accessCheck
    ->canUserAccessByNode(Node::load($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(2, $permittedNids);
}