You are here

public function EntityUuidBufferTest::testEntityUuidBuffer in GraphQL 8.4

Tests the entity UUID buffer.

File

tests/src/Kernel/EntityUuidBufferTest.php, line 62

Class

EntityUuidBufferTest
Tests the entity buffer with loading by UUID data producers.

Namespace

Drupal\Tests\graphql\Kernel

Code

public function testEntityUuidBuffer() : void {
  $query = <<<GQL
      query {
        a:node(uuid: "{<span class="php-variable">$this</span>-&gt;<span class="php-function-or-constant property member-of-self">nodeUuids</span>[<span class="php-constant">0</span>]}") {
          title
        }

        b:node(uuid: "{<span class="php-variable">$this</span>-&gt;<span class="php-function-or-constant property member-of-self">nodeUuids</span>[<span class="php-constant">1</span>]}") {
          title
        }

        c:node(uuid: "{<span class="php-variable">$this</span>-&gt;<span class="php-function-or-constant property member-of-self">nodeUuids</span>[<span class="php-constant">2</span>]}") {
          title
        }
      }
GQL;
  $this
    ->mockResolver('Query', 'node', $this->builder
    ->produce('entity_load_by_uuid')
    ->map('type', $this->builder
    ->fromValue('node'))
    ->map('uuid', $this->builder
    ->fromArgument('uuid')));
  $this
    ->mockResolver('Node', 'title', $this->builder
    ->produce('entity_label')
    ->map('entity', $this->builder
    ->fromParent()));
  $metadata = $this
    ->defaultCacheMetaData();
  $metadata
    ->addCacheTags([
    'node:1',
    'node:2',
    'node:3',
  ]);
  $this
    ->assertResults($query, [], [
    'a' => [
      'title' => 'Node 1',
    ],
    'b' => [
      'title' => 'Node 2',
    ],
    'c' => [
      'title' => 'Node 3',
    ],
  ], $metadata);
}