You are here

protected function GroupSubscribeFormatterTest::setUp in Organic groups 8

Same name in this branch
  1. 8 tests/src/Functional/GroupSubscribeFormatterTest.php \Drupal\Tests\og\Functional\GroupSubscribeFormatterTest::setUp()
  2. 8 tests/src/Unit/GroupSubscribeFormatterTest.php \Drupal\Tests\og\Unit\GroupSubscribeFormatterTest::setUp()

Overrides BrowserTestBase::setUp

File

tests/src/Functional/GroupSubscribeFormatterTest.php, line 62

Class

GroupSubscribeFormatterTest
Tests subscribe and un-subscribe formatter.

Namespace

Drupal\Tests\og\Functional

Code

protected function setUp() : void {
  parent::setUp();

  // Create bundle.
  $this->groupBundle = mb_strtolower($this
    ->randomMachineName());

  // Create a node type.
  $node_type = NodeType::create([
    'type' => $this->groupBundle,
    'name' => $this->groupBundle,
  ]);
  $node_type
    ->save();

  // Define the bundles as groups.
  Og::groupTypeManager()
    ->addGroup('node', $this->groupBundle);

  // Create node author user.
  $user = $this
    ->createUser();

  // Create groups.
  $this->group = Node::create([
    'type' => $this->groupBundle,
    'title' => $this
      ->randomString(),
    'uid' => $user
      ->id(),
  ]);
  $this->group
    ->save();

  /** @var \Drupal\og\Entity\OgRole $role */
  $role = OgRole::getRole('node', $this->groupBundle, OgRoleInterface::ANONYMOUS);
  $role
    ->grantPermission('subscribe without approval')
    ->save();
  $this->user1 = $this
    ->drupalCreateUser();
  $this->user2 = $this
    ->drupalCreateUser();
}