You are here

class CalculatedGroupPermissionsTest in Group 8

Same name and namespace in other branches
  1. 2.0.x tests/src/Unit/CalculatedGroupPermissionsTest.php \Drupal\Tests\group\Unit\CalculatedGroupPermissionsTest

Tests the CalculatedGroupPermissions value object.

@coversDefaultClass \Drupal\group\Access\CalculatedGroupPermissions @group group

Hierarchy

Expanded class hierarchy of CalculatedGroupPermissionsTest

File

tests/src/Unit/CalculatedGroupPermissionsTest.php, line 17

Namespace

Drupal\Tests\group\Unit
View source
class CalculatedGroupPermissionsTest extends UnitTestCase {

  /**
   * Tests that the object values were set in the constructor.
   *
   * @covers ::__construct
   * @covers ::getItem
   * @covers ::getItems
   * @covers ::getItemsByScope
   */
  public function testConstructor() {
    $calculated_permissions = $this
      ->prophesize(CalculatedGroupPermissionsInterface::class);
    $item_a = new CalculatedGroupPermissionsItem(CGPII::SCOPE_GROUP_TYPE, 'foo', [
      'baz',
    ]);
    $item_b = new CalculatedGroupPermissionsItem(CGPII::SCOPE_GROUP, 1, [
      'bob',
      'charlie',
    ]);
    $calculated_permissions
      ->getItems()
      ->willReturn([
      $item_a,
      $item_b,
    ]);
    $calculated_permissions
      ->getCacheContexts()
      ->willReturn([
      '24',
    ]);
    $calculated_permissions
      ->getCacheTags()
      ->willReturn([
      'Oct',
    ]);
    $calculated_permissions
      ->getCacheMaxAge()
      ->willReturn(1986);
    $calculated_permissions = new CalculatedGroupPermissions($calculated_permissions
      ->reveal());
    $this
      ->assertSame($item_a, $calculated_permissions
      ->getItem(CGPII::SCOPE_GROUP_TYPE, 'foo'), 'Managed to retrieve the calculated permissions item by scope and identifier.');
    $this
      ->assertFalse($calculated_permissions
      ->getItem(CGPII::SCOPE_GROUP_TYPE, '404-id-not-found'), 'Requesting a non-existent identifier fails correctly.');
    $this
      ->assertSame([
      $item_a,
      $item_b,
    ], $calculated_permissions
      ->getItems(), 'Successfully retrieved all items regardless of scope.');
    $this
      ->assertSame([
      $item_a,
    ], $calculated_permissions
      ->getItemsByScope(CGPII::SCOPE_GROUP_TYPE), 'Successfully retrieved all items by scope.');
    $this
      ->assertSame([
      '24',
    ], $calculated_permissions
      ->getCacheContexts(), 'Successfully inherited all cache tags.');
    $this
      ->assertSame([
      'Oct',
    ], $calculated_permissions
      ->getCacheTags(), 'Successfully inherited all cache contexts.');
    $this
      ->assertSame(1986, $calculated_permissions
      ->getCacheMaxAge(), 'Successfully inherited cache max-age.');
  }

}

Members

Namesort descending Modifiers Type Description Overrides
CalculatedGroupPermissionsTest::testConstructor public function Tests that the object values were set in the constructor.
PhpunitCompatibilityTrait::getMock Deprecated public function Returns a mock object for the specified class using the available method.
PhpunitCompatibilityTrait::setExpectedException Deprecated public function Compatibility layer for PHPUnit 6 to support PHPUnit 4 code.
UnitTestCase::$randomGenerator protected property The random generator.
UnitTestCase::$root protected property The app root. 1
UnitTestCase::assertArrayEquals protected function Asserts if two arrays are equal by sorting them first.
UnitTestCase::getBlockMockWithMachineName Deprecated protected function Mocks a block with a block plugin. 1
UnitTestCase::getClassResolverStub protected function Returns a stub class resolver.
UnitTestCase::getConfigFactoryStub public function Returns a stub config factory that behaves according to the passed array.
UnitTestCase::getConfigStorageStub public function Returns a stub config storage that returns the supplied configuration.
UnitTestCase::getContainerWithCacheTagsInvalidator protected function Sets up a container with a cache tags invalidator.
UnitTestCase::getRandomGenerator protected function Gets the random generator for the utility methods.
UnitTestCase::getStringTranslationStub public function Returns a stub translation manager that just returns the passed string.
UnitTestCase::randomMachineName public function Generates a unique random string containing letters and numbers.
UnitTestCase::setUp protected function 340