1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Drupal\Tests\graphql_views\Kernel; |
4
|
|
|
|
5
|
|
|
use GraphQL\Server\OperationParams; |
|
|
|
|
6
|
|
|
|
7
|
|
|
/** |
8
|
|
|
* Test contextual views support in GraphQL. |
9
|
|
|
* |
10
|
|
|
* @group graphql_views |
11
|
|
|
*/ |
12
|
|
|
class ContextualViewsTest extends ViewsTestBase { |
13
|
|
|
|
14
|
|
|
/** |
15
|
|
|
* {@inheritdoc} |
16
|
|
|
*/ |
17
|
|
|
protected function setUp(): void { |
18
|
|
|
parent::setUp(); |
19
|
|
|
$this->createContentType(['type' => 'test2']); |
20
|
|
|
} |
21
|
|
|
|
22
|
|
|
/** |
23
|
|
|
* {@inheritdoc} |
24
|
|
|
*/ |
25
|
|
|
protected function defaultCacheContexts(): array { |
26
|
|
|
return array_merge([ |
27
|
|
|
'languages:language_content', |
28
|
|
|
'languages:language_interface', |
29
|
|
|
'user.permissions', |
30
|
|
|
'user.node_grants:view', |
31
|
|
|
], parent::defaultCacheContexts()); |
32
|
|
|
} |
33
|
|
|
|
34
|
|
|
/** |
35
|
|
|
* {@inheritdoc} |
36
|
|
|
*/ |
37
|
|
|
protected function defaultCacheTags(): array { |
38
|
|
|
return array_merge([ |
39
|
|
|
'config:field.storage.node.field_tags', |
40
|
|
|
], parent::defaultCacheTags()); |
41
|
|
|
} |
42
|
|
|
|
43
|
|
|
/** |
44
|
|
|
* Test if view contextual filters are set properly. |
45
|
|
|
*/ |
46
|
|
|
public function testContextualViewArgs() { |
47
|
|
|
$test2Node = $this->createNode(['type' => 'test2']); |
48
|
|
|
|
49
|
|
|
$this->graphQlProcessor()->processQuery( |
50
|
|
|
$this->getDefaultSchema(), |
51
|
|
|
OperationParams::create([ |
52
|
|
|
'query' => $this->getQueryFromFile('contextual.gql'), |
53
|
|
|
'variables' => ['test2NodeId' => $test2Node->id()], |
54
|
|
|
]) |
55
|
|
|
); |
56
|
|
|
|
57
|
|
|
$this->assertEquals(drupal_static('graphql_views_test:view:args'), [ |
|
|
|
|
58
|
|
|
'graphql_test:contextual_title_arg' => [ |
59
|
|
|
0 => [NULL], |
60
|
|
|
1 => ['X'], |
61
|
|
|
], |
62
|
|
|
'graphql_test:contextual_node' => [ |
63
|
|
|
0 => [NULL], |
64
|
|
|
1 => ['X'], |
65
|
|
|
2 => ['1'], |
66
|
|
|
3 => ['X'], |
67
|
|
|
4 => ['1'], |
68
|
|
|
5 => ['X'], |
69
|
|
|
], |
70
|
|
|
'graphql_test:contextual_nodetest' => [ |
71
|
|
|
0 => [NULL], |
72
|
|
|
1 => ['X'], |
73
|
|
|
2 => ['1'], |
74
|
|
|
3 => ['X'], |
75
|
|
|
], |
76
|
|
|
'graphql_test:contextual_node_and_nodetest' => [ |
77
|
|
|
0 => [NULL, NULL], |
78
|
|
|
1 => ['X', 'X'], |
79
|
|
|
2 => [$test2Node->id(), NULL], |
80
|
|
|
3 => ['X', 'X'], |
81
|
|
|
4 => ['1', '1'], |
82
|
|
|
5 => ['X', 'X'], |
83
|
|
|
], |
84
|
|
|
]); |
85
|
|
|
} |
86
|
|
|
|
87
|
|
|
/** |
88
|
|
|
* Test if view fields are attached to correct types. |
89
|
|
|
*/ |
90
|
|
|
public function testContextualViewFields() { |
91
|
|
|
$schema = $this->introspect(); |
92
|
|
|
|
93
|
|
|
$field = 'graphqlTestContextualTitleArgView'; |
94
|
|
|
$this->assertArrayHasKey($field, $schema['types']['Query']['fields']); |
95
|
|
|
$this->assertArrayNotHasKey($field, $schema['types']['Node']['fields']); |
96
|
|
|
$this->assertArrayNotHasKey($field, $schema['types']['NodeTest']['fields']); |
97
|
|
|
|
98
|
|
|
$field = 'graphqlTestContextualNodeView'; |
99
|
|
|
$this->assertArrayHasKey($field, $schema['types']['Query']['fields']); |
100
|
|
|
$this->assertArrayHasKey($field, $schema['types']['Node']['fields']); |
101
|
|
|
$this->assertArrayHasKey($field, $schema['types']['NodeTest']['fields']); |
102
|
|
|
|
103
|
|
|
$field = 'graphqlTestContextualNodetestView'; |
104
|
|
|
$this->assertArrayHasKey($field, $schema['types']['Query']['fields']); |
105
|
|
|
$this->assertArrayNotHasKey($field, $schema['types']['Node']['fields']); |
106
|
|
|
$this->assertArrayHasKey($field, $schema['types']['NodeTest']['fields']); |
107
|
|
|
|
108
|
|
|
$field = 'graphqlTestContextualNodeAndNodetestView'; |
109
|
|
|
$this->assertArrayHasKey($field, $schema['types']['Query']['fields']); |
110
|
|
|
$this->assertArrayHasKey($field, $schema['types']['Node']['fields']); |
111
|
|
|
$this->assertArrayHasKey($field, $schema['types']['NodeTest']['fields']); |
112
|
|
|
} |
113
|
|
|
|
114
|
|
|
} |
115
|
|
|
|
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"]
, you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths