You are here

public function RefinableCalculatedGroupPermissionsTest::testAddItem in Group 8

Same name and namespace in other branches
  1. 2.0.x tests/src/Unit/RefinableCalculatedGroupPermissionsTest.php \Drupal\Tests\group\Unit\RefinableCalculatedGroupPermissionsTest::testAddItem()

Tests the addition of a calculated permissions item.

@covers ::addItem @covers ::getItem

File

tests/src/Unit/RefinableCalculatedGroupPermissionsTest.php, line 27

Class

RefinableCalculatedGroupPermissionsTest
Tests the RefinableCalculatedGroupPermissions class.

Namespace

Drupal\Tests\group\Unit

Code

public function testAddItem() {
  $calculated_permissions = new RefinableCalculatedGroupPermissions();
  $item = new CalculatedGroupPermissionsItem(CGPII::SCOPE_GROUP_TYPE, 'foo', [
    'bar',
  ]);
  $calculated_permissions
    ->addItem($item);
  $this
    ->assertSame($item, $calculated_permissions
    ->getItem(CGPII::SCOPE_GROUP_TYPE, 'foo'), 'Managed to retrieve the calculated permissions item.');
  $item = new CalculatedGroupPermissionsItem(CGPII::SCOPE_GROUP_TYPE, 'foo', [
    'baz',
  ]);
  $calculated_permissions
    ->addItem($item);
  $this
    ->assertEquals([
    'bar',
    'baz',
  ], $calculated_permissions
    ->getItem(CGPII::SCOPE_GROUP_TYPE, 'foo')
    ->getPermissions(), 'Adding a calculated permissions item that was already in the list merges them.');
  $calculated_permissions
    ->addItem($item, TRUE);
  $this
    ->assertEquals([
    'baz',
  ], $calculated_permissions
    ->getItem(CGPII::SCOPE_GROUP_TYPE, 'foo')
    ->getPermissions(), 'Successfully overwrote an item that was already in the list.');
}