protected function GroupSubscribeTest::setUp in Organic groups 8
Overrides BrowserTestBase::setUp
File
- tests/
src/ Functional/ GroupSubscribeTest.php, line 117
Class
- GroupSubscribeTest
- Tests subscribe and un-subscribe to groups.
Namespace
Drupal\Tests\og\FunctionalCode
protected function setUp() : void {
parent::setUp();
// Create bundles.
$this->groupBundle1 = mb_strtolower($this
->randomMachineName());
NodeType::create([
'type' => $this->groupBundle1,
])
->save();
$this->groupBundle2 = mb_strtolower($this
->randomMachineName());
NodeType::create([
'type' => $this->groupBundle2,
])
->save();
$this->groupBundle3 = mb_strtolower($this
->randomMachineName());
NodeType::create([
'type' => $this->groupBundle3,
])
->save();
$this->nonGroupBundle = mb_strtolower($this
->randomMachineName());
NodeType::create([
'type' => $this->nonGroupBundle,
])
->save();
$this->membershipTypeBundle = mb_strtolower($this
->randomMachineName());
NodeType::create([
'type' => $this->membershipTypeBundle,
])
->save();
// Define the entities as groups.
Og::groupTypeManager()
->addGroup('node', $this->groupBundle1);
Og::groupTypeManager()
->addGroup('node', $this->groupBundle2);
Og::groupTypeManager()
->addGroup('node', $this->groupBundle3);
// Create node author user.
$user = $this
->createUser();
// Create test groups. The first group has the 'subscribe without approval'
// permission.
$this->group1 = Node::create([
'type' => $this->groupBundle1,
'title' => $this
->randomString(),
'uid' => $user
->id(),
]);
$this->group1
->save();
// A group which is using default permissions; it grants the 'subscribe'
// permission to non-members.
$this->group2 = Node::create([
'type' => $this->groupBundle2,
'title' => $this
->randomString(),
'uid' => $user
->id(),
]);
$this->group2
->save();
// An unpublished group.
$this->group3 = Node::create([
'type' => $this->groupBundle1,
'title' => $this
->randomString(),
'uid' => $user
->id(),
'status' => NodeInterface::NOT_PUBLISHED,
]);
$this->group3
->save();
// Create non-group.
$this->group4 = Node::create([
'type' => $this->nonGroupBundle,
'title' => $this
->randomString(),
'uid' => $user
->id(),
]);
$this->group4
->save();
// A group which is closed for subscription. It grants neither 'subscribe'
// nor 'subscribe without approval'.
$this->group5 = Node::create([
'type' => $this->groupBundle3,
'title' => $this
->randomString(),
'uid' => $user
->id(),
]);
$this->group5
->save();
// Grant the permission to 'subscribe without approval' to the first group
// type.
OgRole::getRole('node', $this->groupBundle1, OgRoleInterface::ANONYMOUS)
->grantPermission('subscribe without approval')
->save();
// Revoke the permission to subscribe from the third group type.
OgRole::getRole('node', $this->groupBundle3, OgRoleInterface::ANONYMOUS)
->revokePermission('subscribe')
->save();
// Create a new membership type.
$membership_type = OgMembershipType::create([
'type' => $this->membershipTypeBundle,
'name' => $this
->randomString(),
]);
$membership_type
->save();
$this->normalUser = $this
->drupalCreateUser();
}