You are here

class OgAccessHookTest in Organic groups 8

Same name in this branch
  1. 8 tests/src/Unit/OgAccessHookTest.php \Drupal\Tests\og\Unit\OgAccessHookTest
  2. 8 tests/src/Kernel/Access/OgAccessHookTest.php \Drupal\Tests\og\Kernel\Access\OgAccessHookTest

Tests hook implementation of OG related access.

@group og

Hierarchy

Expanded class hierarchy of OgAccessHookTest

File

tests/src/Unit/OgAccessHookTest.php, line 14

Namespace

Drupal\Tests\og\Unit
View source
class OgAccessHookTest extends OgAccessEntityTestBase {

  /**
   * {@inheritdoc}
   */
  protected function setUp() : void {
    parent::setUp();

    // Since this is a unit test, we don't enable the module. However, we test
    // a hook implementation inside the module so include the module manually.
    include_once __DIR__ . '/../../../og.module';
  }

  /**
   * Tests that an entity which is not a group or group content is ignored.
   *
   * @dataProvider permissionsProvider
   */
  public function testNotContentEntity($operation) {
    $entity = $this
      ->prophesize(EntityInterface::class);
    $access = og_entity_access($entity
      ->reveal(), $operation, $this->user
      ->reveal());

    // An entity which is not a group or group content should always return
    // neutral, since we have no opinion over it.
    $this
      ->assertTrue($access
      ->isNeutral());
  }

  /**
   * Tests that an administrator with 'administer group' permission has access.
   *
   * @dataProvider permissionsProvider
   */
  public function testGetEntityGroups($operation) {
    $this->user
      ->hasPermission('administer organic groups')
      ->willReturn(TRUE);
    $user_entity_access = og_entity_access($this->groupContentEntity
      ->reveal(), $operation, $this->user
      ->reveal());
    $this
      ->assertTrue($user_entity_access
      ->isAllowed());
  }

}

Members

Namesort descending Modifiers Type Description Overrides
OgAccessEntityTestBase::$groupContentEntity protected property A test group content entity.
OgAccessHookTest::setUp protected function Overrides OgAccessEntityTestBase::setUp
OgAccessHookTest::testGetEntityGroups public function Tests that an administrator with 'administer group' permission has access.
OgAccessHookTest::testNotContentEntity public function Tests that an entity which is not a group or group content is ignored.
OgAccessTestBase::$bundle protected property The bundle ID of the test group.
OgAccessTestBase::$config protected property The mocked config handler.
OgAccessTestBase::$entityTypeId protected property The entity type ID of the test group.
OgAccessTestBase::$entityTypeManager protected property The entity type manager service.
OgAccessTestBase::$group protected property The mocked test group.
OgAccessTestBase::$groupId protected property The ID of the test group.
OgAccessTestBase::$groupTypeManager protected property The mocked group manager.
OgAccessTestBase::$membership protected property The membership entity.
OgAccessTestBase::$membershipManager protected property The group membership manager service.
OgAccessTestBase::$ogAccess protected property The OgAccess class, this is the system under test.
OgAccessTestBase::$ogRole protected property The OG role.
OgAccessTestBase::$permissionManager protected property The mocked permission manager.
OgAccessTestBase::$user protected property A mocked test user.
OgAccessTestBase::addCache protected function Mocks the cache methods.
OgAccessTestBase::groupEntity protected function Returns a mocked test group.
OgAccessTestBase::permissionsProvider public function Provides group level permissions to use in access tests.
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.