og-8.x-1.x-dev/tests/src/Unit/OgAccessHookTest.php
tests/src/Unit/OgAccessHookTest.php
<?php
declare(strict_types=1);
namespace Drupal\Tests\og\Unit;
use Drupal\Core\Entity\EntityInterface;
use Prophecy\PhpUnit\ProphecyTrait;
/**
* Tests hook implementation of OG related access.
*
* @group og
*/
class OgAccessHookTest extends OgAccessEntityTestBase {
use ProphecyTrait;
/**
* {@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.
*
* @param string $operation
* The operation.
*
* @dataProvider permissionsProvider
*/
public function testNotContentEntity(string $operation): void {
$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.
*
* @param string $operation
* The operation.
*
* @dataProvider permissionsProvider
*/
public function testGetEntityGroups(string $operation): void {
$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());
}
}
