class CreateMembershipTest in Organic groups 8
Tests create membership helper function.
@group og @coversDefaultClass \Drupal\og\Og
Hierarchy
- class \Drupal\Tests\UnitTestCase extends \PHPUnit\Framework\TestCase uses PhpunitCompatibilityTrait
- class \Drupal\Tests\og\Unit\CreateMembershipTest
Expanded class hierarchy of CreateMembershipTest
File
- tests/
src/ Unit/ CreateMembershipTest.php, line 26
Namespace
Drupal\Tests\og\UnitView source
class CreateMembershipTest extends UnitTestCase {
/**
* The entity type manager.
*
* @var \Drupal\Core\Entity\EntityTypeManagerInterface|\Prophecy\Prophecy\ObjectProphecy
*/
protected $entityTypeManager;
/**
* The mocked entity type repository.
*
* @var \Drupal\Core\Entity\EntityTypeRepositoryInterface|\Prophecy\Prophecy\ObjectProphecy
*/
protected $entityTypeRepository;
/**
* The OG group audience helper.
*
* @var \Drupal\og\OgGroupAudienceHelperInterface|\Prophecy\Prophecy\ObjectProphecy
*/
protected $groupAudienceHelper;
/**
* The mocked memory cache backend.
*
* @var \Drupal\Core\Cache\MemoryCache\MemoryCacheInterface|\Prophecy\Prophecy\ObjectProphecy
*/
protected $staticCache;
/**
* The entity storage prophecy used in the test.
*
* @var \Drupal\Core\Entity\EntityStorageInterface|\Prophecy\Prophecy\ObjectProphecy
*/
protected $entityStorage;
/**
* A mocked test user.
*
* @var \Drupal\Core\Session\AccountInterface|\Prophecy\Prophecy\ObjectProphecy
*/
protected $user;
/**
* The entity type ID of the test group.
*
* @var string
*/
protected $entityTypeId;
/**
* The bundle ID of the test group.
*
* @var string
*/
protected $bundle;
/**
* The mocked test group.
*
* @var \Drupal\Core\Entity\EntityInterface|\Prophecy\Prophecy\ObjectProphecy
*/
protected $group;
/**
* The mocked test OG membership.
*
* @var \Drupal\og\OgMembershipInterface
*/
protected $membership;
/**
* {@inheritdoc}
*/
protected function setUp() : void {
parent::setUp();
$this->entityTypeId = $this
->randomMachineName();
$this->bundle = $this
->randomMachineName();
$this->entityStorage = $this
->prophesize(EntityStorageInterface::class);
$this->entityTypeManager = $this
->prophesize(EntityTypeManagerInterface::class);
$this->entityTypeRepository = $this
->prophesize(EntityTypeRepositoryInterface::class);
$this->groupAudienceHelper = $this
->prophesize(OgGroupAudienceHelperInterface::class);
$this->staticCache = $this
->prophesize(MemoryCacheInterface::class);
$this->entityTypeManager
->getStorage('og_membership')
->willReturn($this->entityStorage
->reveal());
$this->entityTypeRepository
->getEntityTypeFromClass('Drupal\\og\\Entity\\OgMembership')
->willReturn('og_membership');
// Create a mocked Og Membership entity.
/** @var \Drupal\og\OgMembershipInterface|\Prophecy\Prophecy\ObjectProphecy $membership_entity */
$membership_entity = $this
->prophesize(OgMembershipInterface::class);
$this->entityStorage
->create(Argument::type('array'))
->willReturn($membership_entity
->reveal());
// Create a mocked test group.
$this->group = $this
->prophesize(ContentEntityInterface::class);
// Create a mocked test user.
$this->user = $this
->prophesize(UserInterface::class);
$membership_entity
->setOwner($this->user)
->willReturn($membership_entity
->reveal());
$membership_entity
->setGroup($this->group)
->willReturn($membership_entity
->reveal());
$container = new ContainerBuilder();
$container
->set('entity_type.manager', $this->entityTypeManager
->reveal());
$container
->set('entity_type.repository', $this->entityTypeRepository
->reveal());
\Drupal::setContainer($container);
}
/**
* Tests creating membership for an un-saved group.
*
* @covers ::createMembership
*/
public function testNewGroup() {
$membership_manager = new MembershipManager($this->entityTypeManager
->reveal(), $this->groupAudienceHelper
->reveal(), $this->staticCache
->reveal());
$membership = $membership_manager
->createMembership($this->group
->reveal(), $this->user
->reveal());
$this
->assertInstanceOf(OgMembershipInterface::class, $membership);
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
CreateMembershipTest:: |
protected | property | The bundle ID of the test group. | |
CreateMembershipTest:: |
protected | property | The entity storage prophecy used in the test. | |
CreateMembershipTest:: |
protected | property | The entity type ID of the test group. | |
CreateMembershipTest:: |
protected | property | The entity type manager. | |
CreateMembershipTest:: |
protected | property | The mocked entity type repository. | |
CreateMembershipTest:: |
protected | property | The mocked test group. | |
CreateMembershipTest:: |
protected | property | The OG group audience helper. | |
CreateMembershipTest:: |
protected | property | The mocked test OG membership. | |
CreateMembershipTest:: |
protected | property | The mocked memory cache backend. | |
CreateMembershipTest:: |
protected | property | A mocked test user. | |
CreateMembershipTest:: |
protected | function |
Overrides UnitTestCase:: |
|
CreateMembershipTest:: |
public | function | Tests creating membership for an un-saved group. | |
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. |