1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Drupal\Tests\graphql_core\Kernel\Entity; |
4
|
|
|
|
5
|
|
|
use Drupal\Tests\graphql_core\Kernel\GraphQLContentTestBase; |
6
|
|
|
use DateTime; |
7
|
|
|
|
8
|
|
|
/** |
9
|
|
|
* Test basic entity fields. |
10
|
|
|
* |
11
|
|
|
* @group graphql_content |
12
|
|
|
*/ |
13
|
|
|
class EntityBasicFieldsTest extends GraphQLContentTestBase { |
14
|
|
|
|
15
|
|
|
public static $modules = [ |
16
|
|
|
'language', |
17
|
|
|
'content_translation', |
18
|
|
|
]; |
19
|
|
|
|
20
|
|
|
/** |
21
|
|
|
* {@inheritdoc} |
22
|
|
|
*/ |
23
|
|
|
protected function setUp() { |
24
|
|
|
parent::setUp(); |
25
|
|
|
|
26
|
|
|
$language = $this->container->get('entity.manager')->getStorage('configurable_language')->create([ |
27
|
|
|
'id' => 'fr', |
28
|
|
|
]); |
29
|
|
|
$language->save(); |
30
|
|
|
} |
31
|
|
|
|
32
|
|
|
/** |
33
|
|
|
* Set the prophesized permissions. |
34
|
|
|
* |
35
|
|
|
* @return string[] |
36
|
|
|
* The permissions to set on the prophesized user. |
37
|
|
|
*/ |
38
|
|
|
protected function userPermissions() { |
39
|
|
|
$perms = parent::userPermissions(); |
40
|
|
|
$perms[] = 'edit any test content'; |
41
|
|
|
return $perms; |
42
|
|
|
} |
43
|
|
|
|
44
|
|
|
/** |
45
|
|
|
* Test if the basic fields are available on the interface. |
46
|
|
|
*/ |
47
|
|
|
public function testBasicFields() { |
48
|
|
|
$user = $this->createUser(); |
49
|
|
|
|
50
|
|
|
$node = $this->createNode([ |
51
|
|
|
'title' => 'Node in default language', |
52
|
|
|
'type' => 'test', |
53
|
|
|
'status' => 1, |
54
|
|
|
'uid' => $user->id(), |
55
|
|
|
]); |
56
|
|
|
|
57
|
|
|
$translation = $node->addTranslation('fr', ['title' => 'French node']); |
58
|
|
|
$translation->save(); |
59
|
|
|
|
60
|
|
|
$created = (new DateTime())->setTimestamp($node->getCreatedTime())->format(DateTime::ISO8601); |
61
|
|
|
$changed = (new DateTime())->setTimestamp($node->getChangedTime())->format(DateTime::ISO8601); |
62
|
|
|
|
63
|
|
|
$values = [ |
64
|
|
|
'entityId' => $node->id(), |
65
|
|
|
'entityUuid' => $node->uuid(), |
66
|
|
|
'entityLabel' => $node->label(), |
67
|
|
|
'entityType' => $node->getEntityTypeId(), |
68
|
|
|
'entityBundle' => $node->bundle(), |
69
|
|
|
'entityLanguage' => [ |
70
|
|
|
'id' => $node->language()->getId(), |
71
|
|
|
'name' => $node->language()->getName(), |
72
|
|
|
'direction' => $node->language()->getDirection(), |
73
|
|
|
'weight' => $node->language()->getWeight(), |
74
|
|
|
], |
75
|
|
|
'entityRoute' => [ |
76
|
|
|
'internalPath' => '/node/' . $node->id(), |
77
|
|
|
'aliasedPath' => '/node/' . $node->id(), |
78
|
|
|
], |
79
|
|
|
'entityOwner' => [ |
80
|
|
|
'entityLabel' => $user->label(), |
81
|
|
|
], |
82
|
|
|
'entityTranslation' => [ |
83
|
|
|
'entityLabel' => $translation->label(), |
84
|
|
|
], |
85
|
|
|
// EntityPublishedInterface has been added with 8.3. |
86
|
|
|
// Below the field will return false. |
87
|
|
|
'entityPublished' => version_compare(\Drupal::VERSION, '8.3', '<') ? FALSE : TRUE, |
88
|
|
|
'entityCreated' => $created, |
89
|
|
|
'entityChanged' => $changed, |
90
|
|
|
'viewAccess' => TRUE, |
91
|
|
|
'updateAccess' => TRUE, |
92
|
|
|
'deleteAccess' => FALSE, |
93
|
|
|
]; |
94
|
|
|
|
95
|
|
|
|
96
|
|
|
$query = $this->getQueryFromFile('basic_fields.gql'); |
97
|
|
|
|
98
|
|
|
// TODO: Check cache metadata. |
99
|
|
|
$metadata = $this->defaultCacheMetaData(); |
100
|
|
|
$metadata->addCacheContexts([ |
101
|
|
|
'languages:language_content', |
102
|
|
|
'user.node_grants:view', |
103
|
|
|
]); |
104
|
|
|
|
105
|
|
|
$metadata->addCacheTags([ |
106
|
|
|
'entity_bundles', |
107
|
|
|
'entity_field_info', |
108
|
|
|
'entity_types', |
109
|
|
|
'node:1', |
110
|
|
|
'node_list', |
111
|
|
|
'user:1', |
112
|
|
|
]); |
113
|
|
|
|
114
|
|
|
$this->assertResults($query, ['nid' => (int) $node->id()], [ |
115
|
|
|
'node' => ['entities' => [$values]], |
116
|
|
|
], $metadata); |
117
|
|
|
} |
118
|
|
|
|
119
|
|
|
} |
120
|
|
|
|