You are here

EntityQueryTest.php in GraphQL 8

Same filename and directory in other branches
  1. 8.2 src/Tests/EntityQueryTest.php

File

src/Tests/EntityQueryTest.php
View source
<?php

namespace Drupal\graphql\Tests;


/**
 * Test fetching lists of entities through entity queries.
 *
 * @group graphql
 */
class EntityQueryTest extends QueryTestBase {

  /**
   * Helper function to issue a HTTP request with simpletest's cURL.
   *
   * @return string
   *   The content returned from the request.
   */
  public function testSingleNodeQuery() {
    $content = $this
      ->randomMachineName(32);
    $node = $this
      ->createNode([
      'type' => 'article',
      'body' => [
        [
          'value' => $content,
          'format' => filter_default_format(),
        ],
      ],
    ]);
    $nodeId = $node
      ->id();
    $nodeTitle = $node
      ->getTitle();
    $author = $node
      ->getOwner();
    $authorName = $author
      ->getAccountName();
    $query = "{\n      node(id: {$nodeId}) {\n        nid\n        title\n        uid {\n          entity {\n            name\n            langcode {\n              language {\n                name\n              }\n            }\n          }\n        }\n\n        ... on EntityNodeArticle {\n          body {\n            value\n          }\n        }\n      }\n    }";
    $expected = [
      'data' => [
        'node' => [
          'nid' => (int) $nodeId,
          'title' => $nodeTitle,
          'uid' => [
            'entity' => [
              'name' => $authorName,
              'langcode' => [
                'language' => [
                  'name' => 'English',
                ],
              ],
            ],
          ],
          'body' => [
            'value' => $content,
          ],
        ],
      ],
    ];
    $this
      ->assertResponseBody($expected, $this
      ->query($query));
  }

}

Classes

Namesort descending Description
EntityQueryTest Test fetching lists of entities through entity queries.