You are here

protected function ContentAccessAclTest::setUp in Content Access 8

Setup configuration before each test.

Overrides BrowserTestBase::setUp

File

tests/src/Functional/ContentAccessAclTest.php, line 61

Class

ContentAccessAclTest
Automated BrowserTest Case for using content access module with acl module.

Namespace

Drupal\Tests\content_access\Functional

Code

protected function setUp() {
  parent::setUp();
  if (!\Drupal::moduleHandler()
    ->moduleExists('acl')) {
    $this
      ->pass('No ACL module present, skipping test');
    return;
  }

  // Create test user with separate role.
  $this->testUser = $this
    ->drupalCreateUser();

  // Get the value of the new role.
  // @see drupalCreateUser().
  $testUserRoles = $this->testUser
    ->getRoles();
  foreach ($testUserRoles as $role) {
    if (!in_array($role, [
      AccountInterface::AUTHENTICATED_ROLE,
    ])) {
      $this->rid = $role;
      break;
    }
  }

  // Create admin user.
  $this->adminUser = $this
    ->drupalCreateUser([
    'access content',
    'administer content types',
    'grant content access',
    'grant own content access',
    'bypass node access',
    'access administration pages',
  ]);
  $this
    ->drupalLogin($this->adminUser);

  // Rebuild content access permissions.
  node_access_rebuild();

  // Create test content type.
  $this->contentType = $this
    ->drupalCreateContentType();

  // Create test node.
  $this->node1 = $this
    ->drupalCreateNode([
    'type' => $this->contentType
      ->id(),
  ]);
}