You are here

public function PermissionsTest::testFullQueryAccess in GraphQL 8.3

Same name and namespace in other branches
  1. 8.4 tests/src/Kernel/Framework/PermissionsTest.php \Drupal\Tests\graphql\Kernel\Framework\PermissionsTest::testFullQueryAccess()

Test access to arbitrary queries.

The user is allowed to post any queries.

File

tests/src/Kernel/Framework/PermissionsTest.php, line 90

Class

PermissionsTest
Test if query handling respects permissions properly.

Namespace

Drupal\Tests\graphql\Kernel\Framework

Code

public function testFullQueryAccess() {
  $this->accountProphecy
    ->hasPermission(Argument::is('execute graphql requests'))
    ->willReturn(TRUE);
  $this->accountProphecy
    ->hasPermission(Argument::not('execute graphql requests'))
    ->willReturn(FALSE);

  // All queries should work.
  $this
    ->assertEquals(200, $this
    ->query('{ root }')
    ->getStatusCode());
  $this
    ->assertEquals(200, $this
    ->persistedQuery('persisted:a')
    ->getStatusCode());
  $batched = $this
    ->batchedQueries([
    [
      'query' => '{ root }',
    ],
    [
      'queryId' => 'persisted:a',
    ],
  ]);
  $this
    ->assertEquals(200, $batched
    ->getStatusCode());
  $data = [
    'data' => [
      'root' => 'test',
    ],
  ];
  $this
    ->assertEquals([
    $data,
    $data,
  ], json_decode($batched
    ->getContent(), TRUE));
}