You are here

public function NodeViewPermissionsTest::testViewAny in Node View Permissions 8

Test users with a "view any content" permission.

Ensure that these users can view any node of this type, including ones that they did not create.

Throws

\Behat\Mink\Exception\ExpectationException

\Drupal\Core\Entity\EntityStorageException

File

tests/src/Functional/NodeViewPermissionsTest.php, line 81

Class

NodeViewPermissionsTest
Tests for Node View Permissions.

Namespace

Drupal\Tests\node_view_permissions\Functional

Code

public function testViewAny() {
  $user1 = $this
    ->drupalCreateUser([
    'view any article content',
  ]);
  $user2 = $this
    ->drupalCreateUser([
    'view any article content',
  ]);
  $node = $this
    ->drupalCreateNode([
    'type' => 'article',
    'uid' => $user1
      ->id(),
  ]);
  foreach ([
    $user1,
    $user2,
  ] as $user) {
    $this
      ->drupalLogin($user);
    $this
      ->drupalGet(Url::fromRoute('entity.node.canonical', [
      'node' => $node
        ->id(),
    ]));
    $this
      ->assertSession()
      ->statusCodeEquals(Response::HTTP_OK);
  }
}