abstract class OgAccessEntityTestBase in Organic groups 8
OG access entity base class.
Hierarchy
- class \Drupal\Tests\UnitTestCase extends \PHPUnit\Framework\TestCase uses PhpunitCompatibilityTrait
- class \Drupal\Tests\og\Unit\OgAccessTestBase
- class \Drupal\Tests\og\Unit\OgAccessEntityTestBase
- class \Drupal\Tests\og\Unit\OgAccessTestBase
Expanded class hierarchy of OgAccessEntityTestBase
File
- tests/
src/ Unit/ OgAccessEntityTestBase.php, line 20
Namespace
Drupal\Tests\og\UnitView source
abstract class OgAccessEntityTestBase extends OgAccessTestBase {
/**
* A test group content entity.
*
* @var \Drupal\Core\Entity\ContentEntityInterface|\Prophecy\Prophecy\ObjectProphecy
*/
protected $groupContentEntity;
/**
* {@inheritdoc}
*/
protected function setUp() : void {
parent::setUp();
// Mock a group content entity.
$entity_type_id = $this
->randomMachineName();
$bundle = $this
->randomMachineName();
// Just a random entity ID.
$entity_id = 20;
$entity_type = $this
->prophesize(EntityTypeInterface::class);
$entity_type
->getListCacheTags()
->willReturn([]);
$entity_type
->entityClassImplements(FieldableEntityInterface::class)
->willReturn(TRUE);
$entity_type
->id()
->willReturn($entity_type_id);
$this->groupContentEntity = $this
->prophesize(ContentEntityInterface::class);
$this->groupContentEntity
->id()
->willReturn($entity_id);
$this->groupContentEntity
->bundle()
->willReturn($bundle);
$this->groupContentEntity
->isNew()
->willReturn(FALSE);
$this->groupContentEntity
->getEntityType()
->willReturn($entity_type
->reveal());
$this->groupContentEntity
->getEntityTypeId()
->willReturn($entity_type_id);
$this
->addCache($this->groupContentEntity);
// If the group type manager is asked if the group content entity is group
// content, it is expected that this will return TRUE.
$this->groupTypeManager
->isGroupContent($entity_type_id, $bundle)
->willReturn(TRUE);
// It is expected that a list of entity operation permissions is retrieved
// from the permission manager so that the passed in permission can be
// checked against this list. Our permissions are not in the list, so it is
// of no importance what we return here, an empty array is sufficient.
$this->permissionManager
->getDefaultEntityOperationPermissions($this->entityTypeId, $this->bundle, [
$entity_type_id => [
$bundle,
],
])
->willReturn([]);
// The group manager is expected to declare that this is not a group.
$this->groupTypeManager
->isGroup($entity_type_id, $bundle)
->willReturn(FALSE);
// Mock retrieval of field definitions.
$field_definition = $this
->prophesize(FieldDefinitionInterface::class);
$field_definition
->getType()
->willReturn(OgGroupAudienceHelperInterface::GROUP_REFERENCE);
$field_definition
->getFieldStorageDefinition()
->willReturn($this
->prophesize(FieldStorageDefinitionInterface::class)
->reveal());
$field_definition
->getSetting('handler_settings')
->willReturn([]);
$field_definition
->getName()
->willReturn($this
->randomMachineName());
$entity_field_manager = $this
->prophesize(EntityFieldManagerInterface::class);
$entity_field_manager
->getFieldDefinitions($entity_type_id, $bundle)
->willReturn([
$field_definition
->reveal(),
]);
$group_type_id = $this->group
->getEntityTypeId();
$storage = $this
->prophesize(EntityStorageInterface::class);
$entity_type_manager = $this
->prophesize(EntityTypeManagerInterface::class);
$entity_type_manager
->getDefinition($entity_type_id)
->willReturn($entity_type
->reveal());
$entity_type_manager
->getStorage($group_type_id)
->willReturn($storage
->reveal());
$container = \Drupal::getContainer();
$container
->set('entity_type.manager', $entity_type_manager
->reveal());
$container
->set('entity_field.manager', $entity_field_manager
->reveal());
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
OgAccessEntityTestBase:: |
protected | property | A test group content entity. | |
OgAccessEntityTestBase:: |
protected | function |
Overrides OgAccessTestBase:: |
1 |
OgAccessTestBase:: |
protected | property | The bundle ID of the test group. | |
OgAccessTestBase:: |
protected | property | The mocked config handler. | |
OgAccessTestBase:: |
protected | property | The entity type ID of the test group. | |
OgAccessTestBase:: |
protected | property | The entity type manager service. | |
OgAccessTestBase:: |
protected | property | The mocked test group. | |
OgAccessTestBase:: |
protected | property | The ID of the test group. | |
OgAccessTestBase:: |
protected | property | The mocked group manager. | |
OgAccessTestBase:: |
protected | property | The membership entity. | |
OgAccessTestBase:: |
protected | property | The group membership manager service. | |
OgAccessTestBase:: |
protected | property | The OgAccess class, this is the system under test. | |
OgAccessTestBase:: |
protected | property | The OG role. | |
OgAccessTestBase:: |
protected | property | The mocked permission manager. | |
OgAccessTestBase:: |
protected | property | A mocked test user. | |
OgAccessTestBase:: |
protected | function | Mocks the cache methods. | |
OgAccessTestBase:: |
protected | function | Returns a mocked test group. | |
OgAccessTestBase:: |
public | function | Provides group level permissions to use in access tests. | |
PhpunitCompatibilityTrait:: |
public | function | Returns a mock object for the specified class using the available method. | |
PhpunitCompatibilityTrait:: |
public | function | Compatibility layer for PHPUnit 6 to support PHPUnit 4 code. | |
UnitTestCase:: |
protected | property | The random generator. | |
UnitTestCase:: |
protected | property | The app root. | 1 |
UnitTestCase:: |
protected | function | Asserts if two arrays are equal by sorting them first. | |
UnitTestCase:: |
protected | function | Mocks a block with a block plugin. | 1 |
UnitTestCase:: |
protected | function | Returns a stub class resolver. | |
UnitTestCase:: |
public | function | Returns a stub config factory that behaves according to the passed array. | |
UnitTestCase:: |
public | function | Returns a stub config storage that returns the supplied configuration. | |
UnitTestCase:: |
protected | function | Sets up a container with a cache tags invalidator. | |
UnitTestCase:: |
protected | function | Gets the random generator for the utility methods. | |
UnitTestCase:: |
public | function | Returns a stub translation manager that just returns the passed string. | |
UnitTestCase:: |
public | function | Generates a unique random string containing letters and numbers. |