protected function OgRoleManagerTest::setUp in Organic groups 8
Same name in this branch
- 8 tests/src/Unit/OgRoleManagerTest.php \Drupal\Tests\og\Unit\OgRoleManagerTest::setUp()
- 8 tests/src/Kernel/OgRoleManagerTest.php \Drupal\Tests\og\Kernel\OgRoleManagerTest::setUp()
Overrides KernelTestBase::setUp
File
- tests/src/ Kernel/ OgRoleManagerTest.php, line 57 
Class
- OgRoleManagerTest
- Kernel tests for the OG role manager service.
Namespace
Drupal\Tests\og\KernelCode
protected function setUp() : void {
  parent::setUp();
  // Add membership and config schema.
  $this
    ->installConfig([
    'og',
  ]);
  $this
    ->installEntitySchema('entity_test');
  $this
    ->installEntitySchema('node');
  $this->roleName = mb_strtolower($this
    ->randomMachineName());
  $this->ogRoleManager = $this->container
    ->get('og.role_manager');
  // Create two group entity types.
  NodeType::create([
    'type' => 'node_group_type',
    'name' => $this
      ->randomString(),
  ])
    ->save();
  Og::groupTypeManager()
    ->addGroup('node', 'node_group_type');
  // Bundles are implied for entity_test and don't need to be created.
  Og::groupTypeManager()
    ->addGroup('entity_test', 'entity_test_group_type');
  // Create a custom role to verify that the tests cover custom roles as well.
  $og_role = OgRole::create();
  $og_role
    ->setName($this->roleName)
    ->setLabel($this
    ->randomString())
    ->setGroupType('node')
    ->setGroupBundle('node_group_type')
    ->grantPermission('access content')
    ->grantPermission(OgAccess::ADMINISTER_GROUP_PERMISSION)
    ->grantPermission('view own unpublished content')
    ->save();
}