You are here

public function EntityBasicFieldsTest::testBasicFields in GraphQL 8.3

Test if the basic fields are available on the interface.

File

modules/graphql_core/tests/src/Kernel/Entity/EntityBasicFieldsTest.php, line 30

Class

EntityBasicFieldsTest
Test basic entity fields.

Namespace

Drupal\Tests\graphql_core\Kernel\Entity

Code

public function testBasicFields() {
  $user = $this
    ->createUser();
  $node = $this
    ->createNode([
    'title' => 'Node in default language',
    'type' => 'test',
    'status' => 1,
    'uid' => $user
      ->id(),
  ]);
  $translation = $node
    ->addTranslation('fr', [
    'title' => 'French node',
  ]);
  $translation
    ->save();
  $created = (new DateTime())
    ->setTimestamp($node
    ->getCreatedTime())
    ->format(DateTime::ISO8601);
  $changed = (new DateTime())
    ->setTimestamp($node
    ->getChangedTime())
    ->format(DateTime::ISO8601);
  $values = [
    'entityId' => $node
      ->id(),
    'entityUuid' => $node
      ->uuid(),
    'entityLabel' => $node
      ->label(),
    'entityType' => $node
      ->getEntityTypeId(),
    'entityBundle' => $node
      ->bundle(),
    'entityLanguage' => [
      'id' => $node
        ->language()
        ->getId(),
      'name' => $node
        ->language()
        ->getName(),
      'direction' => $node
        ->language()
        ->getDirection(),
      'weight' => $node
        ->language()
        ->getWeight(),
    ],
    'entityUrl' => [
      'path' => '/node/' . $node
        ->id(),
    ],
    'entityOwner' => [
      'entityLabel' => $user
        ->label(),
    ],
    // TODO: Fix this.
    'entityTranslation' => [
      'entityLabel' => $translation
        ->label(),
    ],
    'entityPublished' => TRUE,
    'entityCreated' => $created,
    'entityChanged' => $changed,
    'viewAccess' => TRUE,
    'updateAccess' => TRUE,
    'deleteAccess' => FALSE,
  ];
  $query = $this
    ->getQueryFromFile('basic_fields.gql');

  // TODO: Check cache metadata.
  $metadata = $this
    ->defaultCacheMetaData();
  $metadata
    ->addCacheContexts([
    'user.node_grants:view',
  ]);
  $metadata
    ->addCacheTags([
    'node:1',
    'node_list',
    'user:2',
  ]);
  $this
    ->assertResults($query, [
    'nid' => (string) $node
      ->id(),
  ], [
    'node' => [
      'entities' => [
        $values,
      ],
    ],
  ], $metadata);
}