1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Drupal\Tests\graphql_core\Kernel; |
4
|
|
|
|
5
|
|
|
use Drupal\field\Entity\FieldConfig; |
6
|
|
|
use Drupal\field\Entity\FieldStorageConfig; |
7
|
|
|
use Drupal\Tests\graphql_core\Traits\RevisionsTestTrait; |
8
|
|
|
use Drupal\simpletest\ContentTypeCreationTrait; |
9
|
|
|
use Drupal\simpletest\NodeCreationTrait; |
10
|
|
|
use Drupal\simpletest\UserCreationTrait; |
11
|
|
|
|
12
|
|
|
/** |
13
|
|
|
* Base class for node based tests. |
14
|
|
|
*/ |
15
|
|
|
class GraphQLContentTestBase extends GraphQLCoreTestBase { |
16
|
|
|
use ContentTypeCreationTrait; |
17
|
|
|
use UserCreationTrait; |
18
|
|
|
use NodeCreationTrait; |
19
|
|
|
use RevisionsTestTrait; |
20
|
|
|
|
21
|
|
|
/** |
22
|
|
|
* {@inheritdoc} |
23
|
|
|
*/ |
24
|
|
|
public static $modules = [ |
25
|
|
|
'node', |
26
|
|
|
'field', |
27
|
|
|
'filter', |
28
|
|
|
'text', |
29
|
|
|
]; |
30
|
|
|
|
31
|
|
|
/** |
32
|
|
|
* {@inheritdoc} |
33
|
|
|
* |
34
|
|
|
* Add the 'access content' permission to the mocked account. |
35
|
|
|
*/ |
36
|
|
|
protected function userPermissions() { |
37
|
|
|
$perms = parent::userPermissions(); |
38
|
|
|
$perms[] = 'access content'; |
39
|
|
|
$perms[] = 'access user profiles'; |
40
|
|
|
return $perms; |
41
|
|
|
} |
42
|
|
|
|
43
|
|
|
/** |
44
|
|
|
* {@inheritdoc} |
45
|
|
|
*/ |
46
|
|
|
protected function setUp() { |
47
|
|
|
parent::setUp(); |
48
|
|
|
|
49
|
|
|
$this->installConfig(['node', 'filter', 'text']); |
50
|
|
|
$this->installEntitySchema('node'); |
51
|
|
|
|
52
|
|
|
$this->installSchema('node', 'node_access'); |
53
|
|
|
$this->installSchema('system', 'sequences'); |
54
|
|
|
|
55
|
|
|
$this->createContentType([ |
56
|
|
|
'type' => 'test', |
57
|
|
|
]); |
58
|
|
|
} |
59
|
|
|
|
60
|
|
|
/** |
61
|
|
|
* {@inheritdoc} |
62
|
|
|
*/ |
63
|
|
|
protected function defaultCacheTags() { |
64
|
|
|
// graphql_core adds the node body field to the schema, which means |
65
|
|
|
// it's always part of the result cache tags, even if it has not been |
66
|
|
|
// queried. |
67
|
|
|
// |
68
|
|
|
// https://github.com/drupal-graphql/graphql/issues/500 |
69
|
|
|
return array_merge(parent::defaultCacheTags(), [ |
70
|
|
|
'config:field.storage.node.body', |
71
|
|
|
]); |
72
|
|
|
} |
73
|
|
|
|
74
|
|
|
/** |
75
|
|
|
* Add a field to test content type. |
76
|
|
|
* |
77
|
|
|
* @param string $type |
78
|
|
|
* Field type. |
79
|
|
|
* @param string $fieldName |
80
|
|
|
* Field machine name. |
81
|
|
|
* @param string $label |
82
|
|
|
* Label for the field. |
83
|
|
|
*/ |
84
|
|
|
protected function addField($type, $fieldName, $label = 'Label', $bundle = 'test') { |
85
|
|
|
FieldStorageConfig::create([ |
86
|
|
|
'field_name' => $fieldName, |
87
|
|
|
'entity_type' => 'node', |
88
|
|
|
'type' => $type, |
89
|
|
|
'cardinality' => -1, |
90
|
|
|
])->save(); |
91
|
|
|
|
92
|
|
|
FieldConfig::create([ |
93
|
|
|
'entity_type' => 'node', |
94
|
|
|
'bundle' => $bundle, |
95
|
|
|
'field_name' => $fieldName, |
96
|
|
|
'label' => $label, |
97
|
|
|
])->save(); |
98
|
|
|
} |
99
|
|
|
|
100
|
|
|
} |
101
|
|
|
|