|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Drupal\Tests\graphql_core\Kernel\Entity; |
|
4
|
|
|
|
|
5
|
|
|
use Drupal\Tests\graphql_core\Kernel\GraphQLContentTestBase; |
|
6
|
|
|
|
|
7
|
|
|
/** |
|
8
|
|
|
* Test entity query support in GraphQL. |
|
9
|
|
|
* |
|
10
|
|
|
* @group graphql_content |
|
11
|
|
|
*/ |
|
12
|
|
|
class EntityByIdTest extends GraphQLContentTestBase { |
|
13
|
|
|
|
|
14
|
|
|
/** |
|
15
|
|
|
* {@inheritdoc} |
|
16
|
|
|
*/ |
|
17
|
|
|
public static $modules = [ |
|
18
|
|
|
'language', |
|
19
|
|
|
'content_translation', |
|
20
|
|
|
]; |
|
21
|
|
|
|
|
22
|
|
|
/** |
|
23
|
|
|
* The added French language. |
|
24
|
|
|
* |
|
25
|
|
|
* @var string |
|
26
|
|
|
*/ |
|
27
|
|
|
protected $frenchLangcode = 'fr'; |
|
28
|
|
|
|
|
29
|
|
|
/** |
|
30
|
|
|
* The added Chinese simplified language. |
|
31
|
|
|
* |
|
32
|
|
|
* @var string |
|
33
|
|
|
*/ |
|
34
|
|
|
protected $chineseSimplifiedLangcode = 'zh-hans'; |
|
35
|
|
|
|
|
36
|
|
|
/** |
|
37
|
|
|
* {@inheritdoc} |
|
38
|
|
|
*/ |
|
39
|
|
|
protected function setUp() { |
|
40
|
|
|
parent::setUp(); |
|
41
|
|
|
|
|
42
|
|
|
$languageStorage = $this->container->get('entity.manager')->getStorage('configurable_language'); |
|
43
|
|
|
$language = $languageStorage->create([ |
|
44
|
|
|
'id' => $this->frenchLangcode, |
|
45
|
|
|
]); |
|
46
|
|
|
$language->save(); |
|
47
|
|
|
|
|
48
|
|
|
$language = $languageStorage->create([ |
|
49
|
|
|
'id' => $this->chineseSimplifiedLangcode, |
|
50
|
|
|
]); |
|
51
|
|
|
$language->save(); |
|
52
|
|
|
} |
|
53
|
|
|
|
|
54
|
|
|
/** |
|
55
|
|
|
* Test that the entity query returns all nodes if no args are given. |
|
56
|
|
|
*/ |
|
57
|
|
|
public function testEntityByIdWithTranslation() { |
|
58
|
|
|
$node = $this->createNode([ |
|
59
|
|
|
'title' => 'English node', |
|
60
|
|
|
'type' => 'test', |
|
61
|
|
|
]); |
|
62
|
|
|
$node->save(); |
|
63
|
|
|
$node->addTranslation($this->frenchLangcode, ['title' => 'French node'])->save(); |
|
64
|
|
|
$node->addTranslation($this->chineseSimplifiedLangcode, ['title' => 'Chinese simplified node'])->save(); |
|
65
|
|
|
|
|
66
|
|
|
// Save a new draft. |
|
67
|
|
|
$this |
|
68
|
|
|
->getNewDraft($node) |
|
69
|
|
|
->setPublished(FALSE) |
|
70
|
|
|
->setTitle('English node unpublished') |
|
71
|
|
|
->save(); |
|
72
|
|
|
|
|
73
|
|
|
// TODO: Check chache metadata. |
|
74
|
|
|
$metadata = $this->defaultCacheMetaData(); |
|
75
|
|
|
$metadata->addCacheTags([ |
|
76
|
|
|
'entity_bundles', |
|
77
|
|
|
'entity_field_info', |
|
78
|
|
|
'entity_types', |
|
79
|
|
|
'node:1', |
|
80
|
|
|
'config:field.storage.node.body', |
|
81
|
|
|
]); |
|
82
|
|
|
|
|
83
|
|
|
// Check English node. |
|
84
|
|
|
$this->assertResults($this->getQueryFromFile('entity_by_id.gql'), [ |
|
85
|
|
|
'id' => $node->id(), |
|
86
|
|
|
'language' => 'en', |
|
87
|
|
|
], [ |
|
88
|
|
|
'nodeById' => [ |
|
89
|
|
|
'entityLabel' => 'English node', |
|
90
|
|
|
], |
|
91
|
|
|
], $metadata); |
|
92
|
|
|
|
|
93
|
|
|
// Check French translation. |
|
94
|
|
|
$this->assertResults($this->getQueryFromFile('entity_by_id.gql'), [ |
|
95
|
|
|
'id' => $node->id(), |
|
96
|
|
|
'language' => 'fr', |
|
97
|
|
|
], [ |
|
98
|
|
|
'nodeById' => [ |
|
99
|
|
|
'entityLabel' => 'French node', |
|
100
|
|
|
], |
|
101
|
|
|
], $metadata); |
|
102
|
|
|
|
|
103
|
|
|
// Check Chinese simplified translation. |
|
104
|
|
|
$this->assertResults($this->getQueryFromFile('entity_by_id.gql'), [ |
|
105
|
|
|
'id' => $node->id(), |
|
106
|
|
|
'language' => 'zh_hans', |
|
107
|
|
|
], [ |
|
108
|
|
|
'nodeById' => [ |
|
109
|
|
|
'entityLabel' => 'Chinese simplified node', |
|
110
|
|
|
], |
|
111
|
|
|
], $metadata); |
|
112
|
|
|
} |
|
113
|
|
|
|
|
114
|
|
|
} |
|
115
|
|
|
|