You are here

public function EntityByIdTest::testEntityByIdWithTranslation in GraphQL 8.3

Test that the entity query returns all nodes if no args are given.

File

modules/graphql_core/tests/src/Kernel/Entity/EntityByIdTest.php, line 46

Class

EntityByIdTest
Test entity query support in GraphQL.

Namespace

Drupal\Tests\graphql_core\Kernel\Entity

Code

public function testEntityByIdWithTranslation() {
  $node = $this
    ->createNode([
    'title' => 'English node',
    'type' => 'test',
  ]);
  $node
    ->save();
  $node
    ->addTranslation($this->frenchLangcode, [
    'title' => 'French node',
  ])
    ->save();
  $node
    ->addTranslation($this->chineseSimplifiedLangcode, [
    'title' => 'Chinese simplified node',
  ])
    ->save();

  // Save a new draft.
  $this
    ->getNewDraft($node)
    ->setPublished(FALSE)
    ->setTitle('English node unpublished')
    ->save();

  // TODO: Check chache metadata.
  $metadata = $this
    ->defaultCacheMetaData();
  $metadata
    ->addCacheTags([
    'node:1',
  ]);

  // Check English node.
  $this
    ->assertResults($this
    ->getQueryFromFile('entity_by_id.gql'), [
    'id' => $node
      ->id(),
    'language' => 'EN',
  ], [
    'nodeById' => [
      'entityLabel' => 'English node',
    ],
  ], $metadata);

  // Check French translation.
  $this
    ->assertResults($this
    ->getQueryFromFile('entity_by_id.gql'), [
    'id' => $node
      ->id(),
    'language' => 'FR',
  ], [
    'nodeById' => [
      'entityLabel' => 'French node',
    ],
  ], $metadata);

  // Check Chinese simplified translation.
  $this
    ->assertResults($this
    ->getQueryFromFile('entity_by_id.gql'), [
    'id' => $node
      ->id(),
    'language' => 'ZH_HANS',
  ], [
    'nodeById' => [
      'entityLabel' => 'Chinese simplified node',
    ],
  ], $metadata);
}