You are here

public function NodeEntityBundleInfoTest::testGetPermissionsByTids in Permissions by Term 8

Same name and namespace in other branches
  1. 8.2 tests/src/Kernel/NodeEntityBundleInfoTest.php \Drupal\Tests\permissions_by_term\Kernel\NodeEntityBundleInfoTest::testGetPermissionsByTids()

Return value

void

File

tests/src/Kernel/NodeEntityBundleInfoTest.php, line 34

Class

NodeEntityBundleInfoTest
Class AccessStorageTest

Namespace

Drupal\Tests\permissions_by_term\Kernel

Code

public function testGetPermissionsByTids() {
  $testUser1 = User::create([
    'uid' => 5,
    'name' => 'testUser1',
    'mail' => 'foobar@example.com',
  ]);
  $testUser1
    ->save();
  $role = Role::create([
    'id' => 'first-role',
    'label' => 'First Role',
  ]);
  $role
    ->save();
  $testUser2 = User::create([
    'uid' => 6,
    'name' => 'testUser2',
    'mail' => 'foobar@example.com',
  ]);
  $testUser2
    ->save();
  $role = Role::create([
    'id' => 'second-role',
    'label' => 'Second Role',
  ]);
  $role
    ->save();
  $testUser3 = User::create([
    'uid' => 7,
    'name' => 'testUser3',
    'mail' => 'foobar@example.com',
  ]);
  $testUser3
    ->save();
  $role = Role::create([
    'id' => 'third-role',
    'label' => 'Third Role',
  ]);
  $role
    ->save();
  $firstTerm = Term::create([
    'name' => 'term2',
    'vid' => 'test',
  ]);
  $firstTerm
    ->save();
  $secondTerm = Term::create([
    'name' => 'term3',
    'vid' => 'test',
  ]);
  $secondTerm
    ->save();
  $this->accessStorage
    ->addTermPermissionsByUserIds([
    5,
    6,
    7,
  ], $firstTerm
    ->id());
  $this->accessStorage
    ->addTermPermissionsByRoleIds([
    'first-role',
    'second-role',
    'third-role',
  ], $firstTerm
    ->id());
  $this->accessStorage
    ->addTermPermissionsByRoleIds([
    'second-role',
    'third-role',
  ], $secondTerm
    ->id());
  $permissions = $this->nodeEntityBundleInfo
    ->getPermissions();
  $expectedPermissions = [
    'roleLabels' => [
      1 => [
        'First Role',
        'Second Role',
        'Third Role',
      ],
      2 => [
        'Second Role',
        'Third Role',
      ],
    ],
    'userDisplayNames' => [
      1 => [
        'testUser1',
        'testUser2',
        'testUser3',
      ],
    ],
  ];
  $this
    ->assertArraySubset($expectedPermissions, $permissions);
}