You are here

abstract class OgAccessEntityTestBase in Organic groups 8

OG access entity base class.

Hierarchy

Expanded class hierarchy of OgAccessEntityTestBase

File

tests/src/Unit/OgAccessEntityTestBase.php, line 20

Namespace

Drupal\Tests\og\Unit
View 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

Namesort descending Modifiers Type Description Overrides
OgAccessEntityTestBase::$groupContentEntity protected property A test group content entity.
OgAccessEntityTestBase::setUp protected function Overrides OgAccessTestBase::setUp 1
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.