You are here

UserPermissionsContextTest.php in GraphQL 8.4

Same filename and directory in other branches
  1. 8.3 tests/src/Kernel/Framework/UserPermissionsContextTest.php

File

tests/src/Kernel/Framework/UserPermissionsContextTest.php
View source
<?php

namespace Drupal\Tests\graphql\Kernel\Framework;

use Drupal\Tests\graphql\Kernel\GraphQLTestBase;

/**
 * Verify that all queries declare the user.permissions cache context.
 *
 * This is imperative to ensure that authorized queries are not cached
 * and served to unauthorized users.
 *
 * @group graphql
 */
class UserPermissionsContextTest extends GraphQLTestBase {

  /**
   * {@inheritdoc}
   */
  protected function setUp() : void {
    parent::setUp();
    $schema = <<<GQL
      schema {
        query: Query
      }

      type Query {
        root: String
      }
GQL;
    $this
      ->setUpSchema($schema);
  }

  /**
   * Assert user.permissions tag on results.
   */
  public function testUserPermissionsContext() : void {
    $this
      ->mockResolver('Query', 'root', 'test');
    $this
      ->assertResults('{ root }', [], [
      'root' => 'test',
    ]);
  }

}

Classes

Namesort descending Description
UserPermissionsContextTest Verify that all queries declare the user.permissions cache context.