-
Notifications
You must be signed in to change notification settings - Fork 20
Expand file tree
/
Copy pathContextualViewsTest.php
More file actions
114 lines (99 loc) · 3.17 KB
/
ContextualViewsTest.php
File metadata and controls
114 lines (99 loc) · 3.17 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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
<?php
namespace Drupal\Tests\graphql_views\Kernel;
use GraphQL\Server\OperationParams;
/**
* Test contextual views support in GraphQL.
*
* @group graphql_views
*/
class ContextualViewsTest extends ViewsTestBase {
/**
* {@inheritdoc}
*/
protected function setUp(): void {
parent::setUp();
$this->createContentType(['type' => 'test2']);
}
/**
* {@inheritdoc}
*/
protected function defaultCacheContexts() {
return array_merge([
'languages:language_content',
'languages:language_interface',
'user.permissions',
'user.node_grants:view',
], parent::defaultCacheContexts());
}
/**
* {@inheritdoc}
*/
protected function defaultCacheTags() {
return array_merge([
'config:field.storage.node.field_tags',
], parent::defaultCacheTags());
}
/**
* Test if view contextual filters are set properly.
*/
public function testContextualViewArgs() {
$test2Node = $this->createNode(['type' => 'test2']);
$this->graphQlProcessor()->processQuery(
$this->getDefaultSchema(),
OperationParams::create([
'query' => $this->getQueryFromFile('contextual.gql'),
'variables' => ['test2NodeId' => $test2Node->id()],
])
);
$this->assertEquals(drupal_static('graphql_views_test:view:args'), [
'graphql_test:contextual_title_arg' => [
0 => [NULL],
1 => ['X'],
],
'graphql_test:contextual_node' => [
0 => [NULL],
1 => ['X'],
2 => ['1'],
3 => ['X'],
4 => ['1'],
5 => ['X'],
],
'graphql_test:contextual_nodetest' => [
0 => [NULL],
1 => ['X'],
2 => ['1'],
3 => ['X'],
],
'graphql_test:contextual_node_and_nodetest' => [
0 => [NULL, NULL],
1 => ['X', 'X'],
2 => [$test2Node->id(), NULL],
3 => ['X', 'X'],
4 => ['1', '1'],
5 => ['X', 'X'],
],
]);
}
/**
* Test if view fields are attached to correct types.
*/
public function testContextualViewFields() {
$schema = $this->introspect();
$field = 'graphqlTestContextualTitleArgView';
$this->assertArrayHasKey($field, $schema['types']['Query']['fields']);
$this->assertArrayNotHasKey($field, $schema['types']['Node']['fields']);
$this->assertArrayNotHasKey($field, $schema['types']['NodeTest']['fields']);
$field = 'graphqlTestContextualNodeView';
$this->assertArrayHasKey($field, $schema['types']['Query']['fields']);
$this->assertArrayHasKey($field, $schema['types']['Node']['fields']);
$this->assertArrayHasKey($field, $schema['types']['NodeTest']['fields']);
$field = 'graphqlTestContextualNodetestView';
$this->assertArrayHasKey($field, $schema['types']['Query']['fields']);
$this->assertArrayNotHasKey($field, $schema['types']['Node']['fields']);
$this->assertArrayHasKey($field, $schema['types']['NodeTest']['fields']);
$field = 'graphqlTestContextualNodeAndNodetestView';
$this->assertArrayHasKey($field, $schema['types']['Query']['fields']);
$this->assertArrayHasKey($field, $schema['types']['Node']['fields']);
$this->assertArrayHasKey($field, $schema['types']['NodeTest']['fields']);
}
}