You are here

protected function OgGroupResolverTestBase::setUp in Organic groups 8

Overrides UnitTestCase::setUp

2 calls to OgGroupResolverTestBase::setUp()
OgRouteGroupResolverTestBase::setUp in tests/src/Unit/Plugin/OgGroupResolver/OgRouteGroupResolverTestBase.php
RequestQueryArgumentResolverTest::setUp in tests/src/Unit/Plugin/OgGroupResolver/RequestQueryArgumentResolverTest.php
2 methods override OgGroupResolverTestBase::setUp()
OgRouteGroupResolverTestBase::setUp in tests/src/Unit/Plugin/OgGroupResolver/OgRouteGroupResolverTestBase.php
RequestQueryArgumentResolverTest::setUp in tests/src/Unit/Plugin/OgGroupResolver/RequestQueryArgumentResolverTest.php

File

tests/src/Unit/Plugin/OgGroupResolver/OgGroupResolverTestBase.php, line 73

Class

OgGroupResolverTestBase
Base class for testing OgGroupResolver plugins.

Namespace

Drupal\Tests\og\Unit\Plugin\OgGroupResolver

Code

protected function setUp() : void {
  parent::setUp();

  // Instantiate mocks of the classes that the plugins rely on.
  $this->entityTypeManager = $this
    ->prophesize(EntityTypeManagerInterface::class);
  $this->groupAudienceHelper = $this
    ->prophesize(OgGroupAudienceHelperInterface::class);
  $this->groupTypeManager = $this
    ->prophesize(GroupTypeManagerInterface::class);
  $this->membershipManager = $this
    ->prophesize(MembershipManagerInterface::class);

  // Create mocked test entities.

  /** @var \Drupal\Core\Entity\ContentEntityInterface[] $test_entities */
  $test_entities = [];
  foreach ($this
    ->getTestEntityProperties() as $id => $properties) {
    $entity_type_id = $properties['type'];
    $bundle_id = $properties['bundle'];
    $is_group = !empty($properties['group']);
    $is_group_content = !empty($properties['group_content']);
    $entity = $this
      ->createMockedEntity($id, $properties);
    $test_entities[$id] = $entity
      ->reveal();

    // It is not being tight lipped about whether it is a group or group
    // content.
    $this->groupTypeManager
      ->isGroup($entity_type_id, $bundle_id)
      ->willReturn($is_group);
    $this->groupAudienceHelper
      ->hasGroupAudienceField($entity_type_id, $bundle_id)
      ->willReturn($is_group_content);

    // If the entity is group content it will spill the beans on which groups
    // it belongs to.
    if ($is_group_content) {
      $groups = [];
      foreach ($properties['group_content'] as $group_id) {
        $group = $test_entities[$group_id];
        $groups[$group
          ->getEntityTypeId()][$group
          ->id()] = $group;
      }
      $this->membershipManager
        ->getGroups($entity)
        ->willReturn($groups);
    }
  }
  $this->testEntities = $test_entities;
}