GroupSubscribeFormatterTest.php in Organic groups 8
File
tests/src/Functional/GroupSubscribeFormatterTest.php
View source
<?php
declare (strict_types=1);
namespace Drupal\Tests\og\Functional;
use Drupal\Tests\BrowserTestBase;
use Drupal\node\Entity\Node;
use Drupal\node\Entity\NodeType;
use Drupal\og\Entity\OgRole;
use Drupal\og\Og;
use Drupal\og\OgRoleInterface;
class GroupSubscribeFormatterTest extends BrowserTestBase {
public static $modules = [
'node',
'og',
];
protected $defaultTheme = 'stark';
protected $group;
protected $groupBundle;
protected $user1;
protected $user2;
protected function setUp() : void {
parent::setUp();
$this->groupBundle = mb_strtolower($this
->randomMachineName());
$node_type = NodeType::create([
'type' => $this->groupBundle,
'name' => $this->groupBundle,
]);
$node_type
->save();
Og::groupTypeManager()
->addGroup('node', $this->groupBundle);
$user = $this
->createUser();
$this->group = Node::create([
'type' => $this->groupBundle,
'title' => $this
->randomString(),
'uid' => $user
->id(),
]);
$this->group
->save();
$role = OgRole::getRole('node', $this->groupBundle, OgRoleInterface::ANONYMOUS);
$role
->grantPermission('subscribe without approval')
->save();
$this->user1 = $this
->drupalCreateUser();
$this->user2 = $this
->drupalCreateUser();
}
public function testFormatter() {
$this
->drupalLogin($this->user1);
$this
->drupalGet('node/' . $this->group
->id());
$this
->clickLink('Subscribe to group');
$this
->click('#edit-submit');
$this
->drupalGet('node/' . $this->group
->id());
$this
->assertSession()
->linkExists('Unsubscribe from group');
$this
->drupalLogin($this->user2);
$this
->drupalGet('node/' . $this->group
->id());
$this
->clickLink('Subscribe to group');
}
}