1616
1717class AccessTest extends TestCase
1818{
19- const USER_RYAN = 'ryan ' ;
20- const USER_ADMIN = 'admin ' ;
21- const ANONYMOUS_USER = null ;
19+ private $ userNameQuery = 'query { user { name } } ' ;
2220
23- private $ userNameQuery = 'query MyQuery { user { name } } ' ;
21+ private $ userRolesQuery = 'query { user { roles } } ' ;
2422
25- private $ userRolesQuery = 'query MyQuery { user { roles } } ' ;
26-
27- private $ userIsEnabledQuery = 'query MyQuery { user { isEnabled } } ' ;
23+ private $ userIsEnabledQuery = 'query { user { isEnabled } } ' ;
2824
2925 private $ userFriendsQuery = <<<'EOF'
30- query MyQuery {
26+ query {
3127 user {
3228 friends(first: 2) {
3329 edges {
@@ -61,14 +57,14 @@ public function testNotAuthenticatedUserAccessToUserName()
6157 'warnings ' => [
6258 [
6359 'message ' => 'Access denied to this field. ' ,
64- 'locations ' => [['line ' => 1 , 'column ' => 24 ]],
60+ 'locations ' => [['line ' => 1 , 'column ' => 16 ]],
6561 'path ' => ['user ' , 'name ' ],
6662 ],
6763 ],
6864 ],
6965 ];
7066
71- $ this ->assertResponse ($ this ->userNameQuery , $ expected , static ::ANONYMOUS_USER );
67+ $ this ->assertResponse ($ this ->userNameQuery , $ expected , static ::ANONYMOUS_USER , ' access ' );
7268 }
7369
7470 public function testFullyAuthenticatedUserAccessToUserName ()
@@ -81,17 +77,17 @@ public function testFullyAuthenticatedUserAccessToUserName()
8177 ],
8278 ];
8379
84- $ this ->assertResponse ($ this ->userNameQuery , $ expected , static ::USER_RYAN );
80+ $ this ->assertResponse ($ this ->userNameQuery , $ expected , static ::USER_RYAN , ' access ' );
8581 }
8682
8783 public function testNotAuthenticatedUserAccessToUserRoles ()
8884 {
89- $ this ->assertResponse ($ this ->userRolesQuery , $ this ->expectedFailedUserRoles (), static ::ANONYMOUS_USER );
85+ $ this ->assertResponse ($ this ->userRolesQuery , $ this ->expectedFailedUserRoles (), static ::ANONYMOUS_USER , ' access ' );
9086 }
9187
9288 public function testAuthenticatedUserAccessToUserRolesWithoutEnoughRights ()
9389 {
94- $ this ->assertResponse ($ this ->userRolesQuery , $ this ->expectedFailedUserRoles (), static ::USER_RYAN );
90+ $ this ->assertResponse ($ this ->userRolesQuery , $ this ->expectedFailedUserRoles (), static ::USER_RYAN , ' access ' );
9591 }
9692
9793 public function testUserWithCorrectRightsAccessToUserRoles ()
@@ -104,7 +100,7 @@ public function testUserWithCorrectRightsAccessToUserRoles()
104100 ],
105101 ];
106102
107- $ this ->assertResponse ($ this ->userRolesQuery , $ expected , static ::USER_ADMIN );
103+ $ this ->assertResponse ($ this ->userRolesQuery , $ expected , static ::USER_ADMIN , ' access ' );
108104 }
109105
110106 public function testUserForbiddenField ()
@@ -137,7 +133,7 @@ public function testUserForbiddenField()
137133}
138134EOF;
139135
140- $ this ->assertResponse ($ query , $ expected , static ::USER_ADMIN );
136+ $ this ->assertResponse ($ query , $ expected , static ::USER_ADMIN , ' access ' );
141137 }
142138
143139 public function testUserAccessToUserFriends ()
@@ -155,7 +151,7 @@ public function testUserAccessToUserFriends()
155151 ],
156152 ];
157153
158- $ this ->assertResponse ($ this ->userFriendsQuery , $ expected , static ::USER_ADMIN );
154+ $ this ->assertResponse ($ this ->userFriendsQuery , $ expected , static ::USER_ADMIN , ' access ' );
159155 }
160156
161157 public function testMutationAllowedUser ()
@@ -171,7 +167,7 @@ public function testMutationAllowedUser()
171167 ],
172168 ];
173169
174- $ this ->assertResponse (sprintf ($ this ->simpleMutationWithThunkQuery , $ result ), $ expected , static ::USER_ADMIN );
170+ $ this ->assertResponse (sprintf ($ this ->simpleMutationWithThunkQuery , $ result ), $ expected , static ::USER_ADMIN , ' access ' );
175171 $ this ->assertTrue (SimpleMutationWithThunkFieldsMutation::hasMutate (true ));
176172 }
177173
@@ -200,7 +196,7 @@ public function testMutationAllowedButNoRightsToDisplayPayload()
200196 ],
201197 ];
202198
203- $ this ->assertResponse (sprintf ($ this ->simpleMutationWithThunkQuery , 321 ), $ expected , static ::USER_ADMIN );
199+ $ this ->assertResponse (sprintf ($ this ->simpleMutationWithThunkQuery , 321 ), $ expected , static ::USER_ADMIN , ' access ' );
204200 $ this ->assertTrue (SimpleMutationWithThunkFieldsMutation::hasMutate (true ));
205201 }
206202
@@ -224,7 +220,7 @@ public function testMutationNotAllowedUser()
224220 ],
225221 ];
226222
227- $ this ->assertResponse (sprintf ($ this ->simpleMutationWithThunkQuery , 123 ), $ expected , static ::USER_RYAN );
223+ $ this ->assertResponse (sprintf ($ this ->simpleMutationWithThunkQuery , 123 ), $ expected , static ::USER_RYAN , ' access ' );
228224 $ this ->assertFalse (SimpleMutationWithThunkFieldsMutation::hasMutate (true ));
229225 }
230226
@@ -238,30 +234,4 @@ private function expectedFailedUserRoles()
238234 ],
239235 ];
240236 }
241-
242- private static function assertResponse ($ query , array $ expected , $ username )
243- {
244- $ client = self ::createClientAuthenticated ($ username );
245- $ client ->request ('GET ' , '/ ' , ['query ' => $ query ]);
246-
247- $ result = $ client ->getResponse ()->getContent ();
248-
249- static ::assertEquals ($ expected , json_decode ($ result , true ), $ result );
250-
251- return $ client ;
252- }
253-
254- private static function createClientAuthenticated ($ username )
255- {
256- $ client = static ::createClient (['test_case ' => 'access ' ]);
257-
258- if ($ username ) {
259- $ client ->setServerParameters ([
260- 'PHP_AUTH_USER ' => $ username ,
261- 'PHP_AUTH_PW ' => '123 ' ,
262- ]);
263- }
264-
265- return $ client ;
266- }
267237}
0 commit comments