You are here

public function EntityQueryTest::testSingleNodeQuery in GraphQL 8

Same name and namespace in other branches
  1. 8.2 src/Tests/EntityQueryTest.php \Drupal\graphql\Tests\EntityQueryTest::testSingleNodeQuery()

Helper function to issue a HTTP request with simpletest's cURL.

Return value

string The content returned from the request.

File

src/Tests/EntityQueryTest.php, line 17

Class

EntityQueryTest
Test fetching lists of entities through entity queries.

Namespace

Drupal\graphql\Tests

Code

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));
}