PermissionsTest.php in GraphQL 8.4
File
tests/src/Kernel/Framework/PermissionsTest.php
View source
<?php
namespace Drupal\Tests\graphql\Kernel\Framework;
use Drupal\Tests\graphql\Kernel\GraphQLTestBase;
class PermissionsTest extends GraphQLTestBase {
protected function setUp() : void {
parent::setUp();
$schema = <<<GQL
schema {
query: Query
}
type Query {
root: String
}
GQL;
$this
->setUpSchema($schema);
$this
->mockResolver('Query', 'root', 'test');
}
public function testNoPermissions() : void {
$this
->setUpCurrentUser();
$this
->assertEquals(403, $this
->query('query')
->getStatusCode());
$batched = $this
->batchedQueries([
[
'query' => '{ root }',
],
[
'query' => '{ root }',
],
]);
$this
->assertEquals(403, $batched
->getStatusCode());
}
public function testFullQueryAccess() : void {
$this
->setUpCurrentUser([], [
"execute {$this->server->id()} arbitrary graphql requests",
]);
$this
->assertEquals(200, $this
->query('{ root }')
->getStatusCode());
$batched = $this
->batchedQueries([
[
'query' => '{ root }',
],
[
'query' => '{ root }',
],
]);
$this
->assertEquals(200, $batched
->getStatusCode());
$data = [
'data' => [
'root' => 'test',
],
];
$this
->assertEquals([
$data,
$data,
], json_decode($batched
->getContent(), TRUE));
}
}