You are here

protected function GroupSubscribeFormatterTest::setUp in Organic groups 8

Same name in this branch
  1. 8 tests/src/Functional/GroupSubscribeFormatterTest.php \Drupal\Tests\og\Functional\GroupSubscribeFormatterTest::setUp()
  2. 8 tests/src/Unit/GroupSubscribeFormatterTest.php \Drupal\Tests\og\Unit\GroupSubscribeFormatterTest::setUp()

Overrides UnitTestCase::setUp

File

tests/src/Unit/GroupSubscribeFormatterTest.php, line 155

Class

GroupSubscribeFormatterTest
Tests the OG group formatter.

Namespace

Drupal\Tests\og\Unit

Code

protected function setUp() : void {
  parent::setUp();
  $this->accessResult = $this
    ->prophesize(AccessResultInterface::class);
  $this->accountProxy = $this
    ->prophesize(AccountProxyInterface::class);
  $this->bundle = $this
    ->randomMachineName();
  $this->entityId = rand(10, 50);
  $this->entityStorage = $this
    ->prophesize(EntityStorageInterface::class);
  $this->entityTypeId = $this
    ->randomMachineName();
  $this->entityTypeManager = $this
    ->prophesize(EntityTypeManagerInterface::class);
  $this->entityTypeRepository = $this
    ->prophesize(EntityTypeRepositoryInterface::class);
  $this->fieldDefinitionInterface = $this
    ->prophesize(FieldDefinitionInterface::class);
  $this->fieldItemList = $this
    ->prophesize(FieldItemListInterface::class);
  $this->group = $this
    ->prophesize(EntityInterface::class);
  $this->groupTypeManager = $this
    ->prophesize(GroupTypeManagerInterface::class);
  $this->membershipManager = $this
    ->prophesize(MembershipManagerInterface::class);
  $this->ogAccess = $this
    ->prophesize(OgAccessInterface::class);
  $this->user = $this
    ->prophesize(AccountInterface::class);
  $this->userId = rand(10, 50);
  $this->fieldItemList
    ->getEntity()
    ->willReturn($this->group);
  $this->group
    ->willImplement(EntityOwnerInterface::class);
  $this->group
    ->getEntityTypeId()
    ->willReturn($this->entityTypeId);
  $this->group
    ->bundle()
    ->willReturn($this->bundle);
  $this->group
    ->id()
    ->willReturn($this->entityId);
  $this->groupTypeManager
    ->isGroup($this->entityTypeId, $this->bundle)
    ->willReturn(TRUE);
  $this->entityTypeManager
    ->getStorage('user')
    ->willReturn($this->entityStorage
    ->reveal());
  $this->accountProxy
    ->id()
    ->willReturn($this->userId);
  $this->entityTypeRepository
    ->getEntityTypeFromClass('Drupal\\user\\Entity\\User')
    ->willReturn('user');
  $this->entityStorage
    ->load($this->userId)
    ->willReturn($this->user
    ->reveal());
  $this->user
    ->isAuthenticated()
    ->willReturn(TRUE);
  $this->user
    ->id()
    ->willReturn($this->userId);
  $container = new ContainerBuilder();
  $container
    ->set('entity_type.manager', $this->entityTypeManager
    ->reveal());
  $container
    ->set('entity_type.repository', $this->entityTypeRepository
    ->reveal());
  $container
    ->set('og.membership_manager', $this->membershipManager
    ->reveal());
  $container
    ->set('string_translation', $this
    ->getStringTranslationStub());
  \Drupal::setContainer($container);
}