1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Overblog\GraphQLBundle\Tests\Functional\Security; |
4
|
|
|
|
5
|
|
|
use Overblog\GraphQLBundle\Tests\Functional\TestCase; |
6
|
|
|
|
7
|
|
|
class SchemaLanguageTest extends TestCase |
8
|
|
|
{ |
9
|
|
|
public function testQueryHumans() |
10
|
|
|
{ |
11
|
|
|
$query = <<<'QUERY' |
12
|
|
|
{ humans {id name direwolf {id name} } } |
13
|
|
|
QUERY; |
14
|
|
|
|
15
|
|
|
$expected = [ |
16
|
|
|
'data' => [ |
17
|
|
|
'humans' => [ |
18
|
|
|
[ |
19
|
|
|
'id' => 1, |
20
|
|
|
'name' => 'Jon Snow', |
21
|
|
|
'direwolf' => ['id' => 7, 'name' => 'Ghost'], |
22
|
|
|
], |
23
|
|
|
[ |
24
|
|
|
'id' => 2, |
25
|
|
|
'name' => 'Arya', |
26
|
|
|
'direwolf' => ['id' => 8, 'name' => 'Nymeria'], |
27
|
|
|
], |
28
|
|
|
[ |
29
|
|
|
'id' => 3, |
30
|
|
|
'name' => 'Bran', |
31
|
|
|
'direwolf' => ['id' => 9, 'name' => 'Summer'], |
32
|
|
|
], |
33
|
|
|
[ |
34
|
|
|
'id' => 4, |
35
|
|
|
'name' => 'Rickon', |
36
|
|
|
'direwolf' => ['id' => 10, 'name' => 'Shaggydog'], |
37
|
|
|
], |
38
|
|
|
[ |
39
|
|
|
'id' => 5, |
40
|
|
|
'name' => 'Robb', |
41
|
|
|
'direwolf' => ['id' => 11, 'name' => 'Grey Wind'], |
42
|
|
|
], |
43
|
|
|
[ |
44
|
|
|
'id' => 6, |
45
|
|
|
'name' => 'Sansa', |
46
|
|
|
'direwolf' => ['id' => 12, 'name' => 'Lady'], |
47
|
|
|
], |
48
|
|
|
], |
49
|
|
|
], |
50
|
|
|
]; |
51
|
|
|
|
52
|
|
|
$this->assertResponse($query, $expected, static::ANONYMOUS_USER, 'schemaLanguage'); |
53
|
|
|
} |
54
|
|
|
|
55
|
|
|
public function testQueryDirewolves() |
56
|
|
|
{ |
57
|
|
|
$query = <<<'QUERY' |
58
|
|
|
{ direwolves {name status} } |
59
|
|
|
QUERY; |
60
|
|
|
|
61
|
|
|
$expected = [ |
62
|
|
|
'data' => [ |
63
|
|
|
'direwolves' => [ |
64
|
|
|
['name' => 'Ghost', 'status' => 'ALIVE'], |
65
|
|
|
['name' => 'Nymeria', 'status' => 'ALIVE'], |
66
|
|
|
['name' => 'Summer', 'status' => 'DECEASED'], |
67
|
|
|
['name' => 'Shaggydog', 'status' => 'DECEASED'], |
68
|
|
|
['name' => 'Grey Wind', 'status' => 'DECEASED'], |
69
|
|
|
['name' => 'Lady', 'status' => 'DECEASED'], |
70
|
|
|
], |
71
|
|
|
], |
72
|
|
|
]; |
73
|
|
|
|
74
|
|
|
$this->assertResponse($query, $expected, static::ANONYMOUS_USER, 'schemaLanguage'); |
75
|
|
|
} |
76
|
|
|
|
77
|
|
|
public function testQueryACharacter() |
78
|
|
|
{ |
79
|
|
|
$query = <<<'QUERY' |
80
|
|
|
{ |
81
|
|
|
character(id: 1) { |
82
|
|
|
name |
83
|
|
|
...on Human { |
84
|
|
|
dateOfBirth |
85
|
|
|
} |
86
|
|
|
} |
87
|
|
|
} |
88
|
|
|
QUERY; |
89
|
|
|
|
90
|
|
|
$expected = [ |
91
|
|
|
'data' => [ |
92
|
|
|
'character' => [ |
93
|
|
|
'name' => 'Jon Snow', |
94
|
|
|
'dateOfBirth' => '281 AC', |
95
|
|
|
], |
96
|
|
|
], |
97
|
|
|
]; |
98
|
|
|
|
99
|
|
|
$this->assertResponse($query, $expected, static::ANONYMOUS_USER, 'schemaLanguage'); |
100
|
|
|
} |
101
|
|
|
|
102
|
|
|
public function testQueryHumanByDateOfBirth() |
103
|
|
|
{ |
104
|
|
|
$query = <<<'QUERY' |
105
|
|
|
{ |
106
|
|
|
findHumansByDateOfBirth(years: ["281 AC", "288 AC"]) { |
107
|
|
|
name |
108
|
|
|
dateOfBirth |
109
|
|
|
} |
110
|
|
|
} |
111
|
|
|
QUERY; |
112
|
|
|
|
113
|
|
|
$expected = [ |
114
|
|
|
'data' => [ |
115
|
|
|
'findHumansByDateOfBirth' => [ |
116
|
|
|
[ |
117
|
|
|
'name' => 'Jon Snow', |
118
|
|
|
'dateOfBirth' => '281 AC', |
119
|
|
|
], |
120
|
|
|
[ |
121
|
|
|
'name' => 'Bran', |
122
|
|
|
'dateOfBirth' => '288 AC', |
123
|
|
|
], |
124
|
|
|
[ |
125
|
|
|
'name' => 'Robb', |
126
|
|
|
'dateOfBirth' => '281 AC', |
127
|
|
|
], |
128
|
|
|
], |
129
|
|
|
], |
130
|
|
|
]; |
131
|
|
|
|
132
|
|
|
$this->assertResponse($query, $expected, static::ANONYMOUS_USER, 'schemaLanguage'); |
133
|
|
|
} |
134
|
|
|
|
135
|
|
|
public function testQueryHumanByDateOfBirthUsingVariables() |
136
|
|
|
{ |
137
|
|
|
$query = <<<'QUERY' |
138
|
|
|
query ($years: [Year!]!) { |
139
|
|
|
findHumansByDateOfBirth(years: $years) { |
140
|
|
|
name |
141
|
|
|
dateOfBirth |
142
|
|
|
} |
143
|
|
|
} |
144
|
|
|
QUERY; |
145
|
|
|
|
146
|
|
|
$expected = [ |
147
|
|
|
'data' => [ |
148
|
|
|
'findHumansByDateOfBirth' => [ |
149
|
|
|
[ |
150
|
|
|
'name' => 'Bran', |
151
|
|
|
'dateOfBirth' => '288 AC', |
152
|
|
|
], |
153
|
|
|
], |
154
|
|
|
], |
155
|
|
|
]; |
156
|
|
|
|
157
|
|
|
$this->assertResponse($query, $expected, static::ANONYMOUS_USER, 'schemaLanguage', null, ['years' => ['288 AC']]); |
158
|
|
|
} |
159
|
|
|
|
160
|
|
|
public function testMutation() |
161
|
|
|
{ |
162
|
|
|
$query = <<<'QUERY' |
163
|
|
|
mutation { resurrectZigZag {name status} } |
164
|
|
|
QUERY; |
165
|
|
|
|
166
|
|
|
$expected = [ |
167
|
|
|
'data' => [ |
168
|
|
|
'resurrectZigZag' => [ |
169
|
|
|
'name' => 'Rickon', |
170
|
|
|
'status' => 'ALIVE', |
171
|
|
|
], |
172
|
|
|
], |
173
|
|
|
]; |
174
|
|
|
|
175
|
|
|
$this->assertResponse($query, $expected, static::ANONYMOUS_USER, 'schemaLanguage'); |
176
|
|
|
} |
177
|
|
|
} |
178
|
|
|
|