Skip to content
This repository was archived by the owner on Feb 10, 2019. It is now read-only.

Commit 064adcc

Browse files
committed
add custom authenticated test
1 parent 52247ed commit 064adcc

File tree

4 files changed

+42
-0
lines changed

4 files changed

+42
-0
lines changed

tests/GraphQLQueryTest.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,18 @@ public function testQueryAndReturnResultWithAuthenticated()
138138
$this->assertEquals('Unauthenticated', $result['errors'][0]['message']);
139139
}
140140

141+
/**
142+
* Test query with authorize
143+
*
144+
* @test
145+
*/
146+
public function testQueryAndReturnResultWithCustomAuthenticated()
147+
{
148+
$result = GraphQL::query($this->queries['examplesWithCustomAuthenticated']);
149+
$this->assertNull($result['data']['examplesCustomAuthenticated']);
150+
$this->assertEquals('custom', $result['errors'][0]['message']);
151+
}
152+
141153
/**
142154
* Test query with schema
143155
*
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<?php
2+
3+
use GraphQL\Type\Definition\Type;
4+
use Folklore\GraphQL\Support\Query;
5+
6+
class ExamplesCustomAuthenticatedQuery extends ExamplesQuery
7+
{
8+
protected $attributes = [
9+
'name' => 'Examples authenticate query'
10+
];
11+
12+
public function authenticated($root, $args, $context)
13+
{
14+
return false;
15+
}
16+
17+
protected function unauthenticated()
18+
{
19+
return 'custom';
20+
}
21+
}

tests/Objects/queries.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,14 @@
6565
}
6666
",
6767

68+
'examplesWithCustomAuthenticated' => "
69+
query QueryExamplesCustomAuthenticated {
70+
examplesCustomAuthenticated {
71+
test
72+
}
73+
}
74+
",
75+
6876
'examplesWithRoot' => "
6977
query QueryExamplesRoot {
7078
examplesRoot {

tests/TestCase.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ protected function getEnvironmentSetUp($app)
2828
'examplesAuthorize' => ExamplesAuthorizeQuery::class,
2929
'examplesCustomAuthorize' => ExamplesCustomAuthorizeQuery::class,
3030
'examplesAuthenticated' => ExamplesAuthenticatedQuery::class,
31+
'examplesCustomAuthenticated' => ExamplesCustomAuthenticatedQuery::class,
3132
'examplesPagination' => ExamplesPaginationQuery::class,
3233
],
3334
'mutation' => [

0 commit comments

Comments
 (0)