protected function MemberCountBlockTest::setUp in Organic groups 8
Overrides KernelTestBase::setUp
File
- tests/
src/ Kernel/ Plugin/ Block/ MemberCountBlockTest.php, line 115
Class
- MemberCountBlockTest
- Tests the member count block.
Namespace
Drupal\Tests\og\Kernel\Plugin\BlockCode
protected function setUp() : void {
parent::setUp();
$this
->installEntitySchema('entity_test');
$this
->installEntitySchema('user');
$this
->installEntitySchema('og_membership');
$this
->installConfig([
'system',
'block',
'og',
]);
$this
->installSchema('system', [
'sequences',
]);
$this->groupTypeManager = $this->container
->get('og.group_type_manager');
$this->entityTypeManager = $this->container
->get('entity_type.manager');
$this->blockStorage = $this->entityTypeManager
->getStorage('block');
$this->blockViewBuilder = $this->entityTypeManager
->getViewBuilder('block');
$this->cacheTagsInvalidator = $this->container
->get('cache_tags.invalidator');
$this->renderer = $this->container
->get('renderer');
$this->renderCache = $this->container
->get('render_cache');
// The block being tested shows the member count of the currently active
// group, which it gets from OgContext. Mock OgContext using a callback to
// set the active group that will be used during the test.
$og_context = $this
->prophesize(OgContextInterface::class);
$og_context
->getGroup()
->will(new CallbackPromise([
$this,
'getActiveGroup',
]));
$this->container
->set('og.context', $og_context
->reveal());
// Create a group type.
$this->groupTypeManager
->addGroup('entity_test', 'group');
// Create two test groups.
for ($i = 0; $i < 2; $i++) {
$this->groups[$i] = EntityTest::create([
'type' => 'group',
'name' => $this
->randomString(),
]);
$this->groups[$i]
->save();
}
// Create a test block.
$this->block = $this->blockStorage
->create([
'plugin' => 'og_member_count',
'region' => 'sidebar_first',
'id' => 'group_member_count',
'theme' => $this
->config('system.theme')
->get('default'),
'label' => 'Group member count',
'visibility' => [],
'weight' => 0,
]);
$this->block
->save();
}