-
Notifications
You must be signed in to change notification settings - Fork 201
Expand file tree
/
Copy pathExampleSchemaTest.php
More file actions
82 lines (70 loc) · 1.86 KB
/
ExampleSchemaTest.php
File metadata and controls
82 lines (70 loc) · 1.86 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
<?php
namespace Drupal\Tests\graphql_example\Kernel;
use Drupal\node\Entity\Node;
use Drupal\node\Entity\NodeType;
use Drupal\Tests\graphql\Kernel\GraphQLTestBase;
use Drupal\user\Entity\User;
class ExampleSchemaTest extends GraphQLTestBase {
/**
* {@inheritdoc}
*/
static $modules = ['graphql_examples'];
/**
* {@inheritdoc}
*/
protected function setUp() :void {
parent::setUp();
// Create the "article" node type since the schema relies on it.
NodeType::create([
'type' => 'article',
'name' => 'Article',
]);
// Create a test-server that uses the schema plugin defined in this module.
$this->createTestServer('example', '/graphql');
}
/**
* Test the example schema for article listing.
*/
public function testExampleSchema() : void {
// Create two authors.
$userA = User::create([
'name' => 'A'
]);
$userA->save();
$userB = User::create([
'name' => 'B'
]);
$userB->save();
// Create three articles.
Node::create([
'type' => 'article',
'title' => 'One',
'uid' => $userA->id(),
])->save();
Node::create([
'type' => 'article',
'title' => 'Two',
'uid' => $userB->id(),
])->save();
Node::create([
'type' => 'article',
'title' => 'Three',
'uid' => $userA->id(),
])->save();
// Execute the query and run assertions against its response content.
$response = $this->query('{ articles { total, items { title, author } } }');
$content = json_decode($response->getContent(), TRUE);
$this->assertEquals([
'data' => [
'articles' => [
'total' => 3,
'items' => [
['title' => 'ONE', 'author' => 'A'],
['title' => 'TWO', 'author' => 'B'],
['title' => 'THREE', 'author' => 'A'],
],
],
],
], $content);
}
}