You are here

public function MultilingualTest::testCanNotAccess in Permissions by Term 8.2

Same name and namespace in other branches
  1. 8 tests/src/Kernel/MultilingualTest.php \Drupal\Tests\permissions_by_term\Kernel\MultilingualTest::testCanNotAccess()

File

tests/src/Kernel/MultilingualTest.php, line 63

Class

MultilingualTest
@group permissions_by_term

Namespace

Drupal\Tests\permissions_by_term\Kernel

Code

public function testCanNotAccess() {
  [
    $termDe,
    $nodeDe,
    $term,
    $node,
    $user,
  ] = $this
    ->setupEntities();
  $this->accessStorage
    ->addTermPermissionsByUserIds([
    \Drupal::service('current_user')
      ->id(),
  ], $term
    ->id(), 'en');
  $this->accessStorage
    ->addTermPermissionsByUserIds([
    $user
      ->id(),
  ], $termDe
    ->id(), 'de');

  /**
   * @var User $user
   */
  $user = user_load_by_name('some_username123');
  $this
    ->assertTrue($this->accessCheck
    ->canUserAccessByNode($node, \Drupal::service('current_user')
    ->id()));
  $this
    ->assertFalse($this->accessCheck
    ->canUserAccessByNode($nodeDe, \Drupal::service('current_user')
    ->id(), 'de'));
  $this
    ->assertTrue($this->accessCheck
    ->canUserAccessByNode($nodeDe, $user
    ->id(), 'de'));
}