protected function GroupContentOperationAccessAlterTest::setUp in Organic groups 8
Overrides KernelTestBase::setUp
File
- tests/
src/ Kernel/ Access/ GroupContentOperationAccessAlterTest.php, line 70
Class
- GroupContentOperationAccessAlterTest
- Test that access to group content operations can be altered.
Namespace
Drupal\Tests\og\Kernel\AccessCode
protected function setUp() : void {
parent::setUp();
$this
->installEntitySchema('comment');
$this
->installEntitySchema('entity_test');
$this
->installEntitySchema('og_membership');
$this
->installEntitySchema('user');
$this
->installSchema('system', 'sequences');
$this->ogAccess = $this->container
->get('og.access');
// Create a dummy user which will get UID 1. We cannot use this for testing
// since this user becomes the super administrator and is not suitable for
// testing access control.
User::create([
'name' => $this
->randomString(),
])
->save();
// Create a test user with the 'moderator' role which has global permission
// to moderate comments in all groups, even ones they are not a member of.
$this->user = $this
->createUser([
'edit and delete comments in all groups',
]);
// Create the test group along with a user that serves as the group owner.
$group_bundle = mb_strtolower($this
->randomMachineName());
$this->group = EntityTest::create([
'type' => $group_bundle,
'name' => $this
->randomString(),
'user_id' => $this
->createUser()
->id(),
]);
$this->group
->save();
// Declare that the test entity type is a group type.
Og::groupTypeManager()
->addGroup('entity_test', $group_bundle);
// Create a group content type.
CommentType::create([
'id' => 'comment',
'label' => 'Comment subscription',
'target_entity_type_id' => 'entity_test',
])
->save();
$settings = [
'field_storage_config' => [
'settings' => [
'target_type' => 'entity_test',
],
],
];
Og::createField(OgGroupAudienceHelperInterface::DEFAULT_FIELD, 'comment', 'comment', $settings);
// Create a group content entity.
$values = [
'subject' => 'subscribe',
'comment_type' => 'comment',
'entity_id' => $this->group
->id(),
'entity_type' => 'entity_test',
'field_name' => 'an_imaginary_field',
OgGroupAudienceHelperInterface::DEFAULT_FIELD => [
[
'target_id' => $this->group
->id(),
],
],
];
$this->groupContent = Comment::create($values);
$this->groupContent
->save();
}