Completed
Pull Request — 8.x-3.x (#501)
by Philipp
03:58
created

EntityQueryTest::setUp()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 4
nc 1
nop 0
dl 0
loc 5
rs 9.4285
c 0
b 0
f 0
1
<?php
2
3
namespace Drupal\Tests\graphql_core\Kernel\EntityQuery;
4
5
use Drupal\Tests\graphql_core\Kernel\GraphQLContentTestBase;
6
7
/**
8
 * Test entity query support in GraphQL.
9
 *
10
 * @group graphql_core
11
 */
12
class EntityQueryTest extends GraphQLContentTestBase {
13
14
  /**
15
   * {@inheritdoc}
16
   */
17
  protected function setUp() {
18
    parent::setUp();
19
    $this->createContentType(['type' => 'a']);
20
    $this->createContentType(['type' => 'b']);
21
  }
22
23
  /**
24
   * Test that entity queries work.
25
   */
26
  public function testEntityQuery() {
27
    $a = $this->createNode([
28
      'title' => 'Node A',
29
      'type' => 'a',
30
    ]);
31
32
    $b = $this->createNode([
33
      'title' => 'Node B',
34
      'type' => 'a',
35
    ]);
36
37
    $c = $this->createNode([
38
      'title' => 'Node C',
39
      'type' => 'a',
40
    ]);
41
42
    $d = $this->createNode([
43
      'title' => 'Node D',
44
      'type' => 'b',
45
    ]);
46
47
    $a->save();
48
    $b->save();
49
    $c->save();
50
    $d->save();
51
52
    // TODO: Check cache metadata.
53
    $metadata = $this->defaultCacheMetaData();
54
    $metadata->addCacheContexts(['user.node_grants:view']);
55
    $metadata->addCacheTags([
56
      'entity_bundles',
57
      'entity_field_info',
58
      'entity_types',
59
      'node:' . $a->id(),
60
      'node:' . $b->id(),
61
      'node:' . $c->id(),
62
      'node:' . $d->id(),
63
      'node_list',
64
    ]);
65
66
    $this->assertResults($this->getQueryFromFile('entity_query.gql'), [], [
67
      'a' => [
68
        'entities' => [
69
          ['uuid' => $a->uuid()],
70
          ['uuid' => $b->uuid()],
71
          ['uuid' => $c->uuid()],
72
        ],
73
        'count' => 3,
74
      ],
75
      'b' => [
76
        'entities' => [
77
          ['uuid' => $d->uuid()],
78
        ],
79
        'count' => 1,
80
      ],
81
      'limit' => [
82
        'entities' => [
83
          ['uuid' => $a->uuid()],
84
          ['uuid' => $b->uuid()],
85
        ],
86
        'count' => 3,
87
      ],
88
      'offset' => [
89
        'entities' => [
90
          ['uuid' => $b->uuid()],
91
          ['uuid' => $c->uuid()],
92
        ],
93
        'count' => 3,
94
      ],
95
      'offset_limit' => [
96
        'entities' => [
97
          ['uuid' => $b->uuid()],
98
        ],
99
        'count' => 3,
100
      ],
101
      'all_nodes' => [
102
        'entities' => [
103
          ['uuid' => $a->uuid()],
104
          ['uuid' => $b->uuid()],
105
          ['uuid' => $c->uuid()],
106
          ['uuid' => $d->uuid()],
107
        ],
108
        'count' => 4,
109
      ],
110
    ], $metadata);
111
  }
112
113
}
114