|
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_core |
|
12
|
|
|
*/ |
|
13
|
|
|
class EntityBasicFieldsTest extends GraphQLContentTestBase { |
|
14
|
|
|
|
|
15
|
|
|
/** |
|
16
|
|
|
* Set the prophesized permissions. |
|
17
|
|
|
* |
|
18
|
|
|
* @return string[] |
|
19
|
|
|
* The permissions to set on the prophesized user. |
|
20
|
|
|
*/ |
|
21
|
|
|
protected function userPermissions() { |
|
22
|
|
|
$perms = parent::userPermissions(); |
|
23
|
|
|
$perms[] = 'edit any test content'; |
|
24
|
|
|
return $perms; |
|
25
|
|
|
} |
|
26
|
|
|
|
|
27
|
|
|
/** |
|
28
|
|
|
* Test if the basic fields are available on the interface. |
|
29
|
|
|
*/ |
|
30
|
|
|
public function testBasicFields() { |
|
31
|
|
|
$user = $this->createUser(); |
|
32
|
|
|
$node = $this->createNode([ |
|
33
|
|
|
'title' => 'Node in default language', |
|
34
|
|
|
'type' => 'test', |
|
35
|
|
|
'status' => 1, |
|
36
|
|
|
'uid' => $user->id(), |
|
37
|
|
|
]); |
|
38
|
|
|
|
|
39
|
|
|
$translation = $node->addTranslation('fr', ['title' => 'French node']); |
|
40
|
|
|
$translation->save(); |
|
41
|
|
|
|
|
42
|
|
|
$created = (new DateTime())->setTimestamp($node->getCreatedTime())->format(DateTime::ISO8601); |
|
43
|
|
|
$changed = (new DateTime())->setTimestamp($node->getChangedTime())->format(DateTime::ISO8601); |
|
44
|
|
|
|
|
45
|
|
|
$values = [ |
|
46
|
|
|
'entityId' => $node->id(), |
|
47
|
|
|
'entityUuid' => $node->uuid(), |
|
48
|
|
|
'entityLabel' => $node->label(), |
|
49
|
|
|
'entityType' => $node->getEntityTypeId(), |
|
50
|
|
|
'entityBundle' => $node->bundle(), |
|
51
|
|
|
'entityLanguage' => [ |
|
52
|
|
|
'id' => $node->language()->getId(), |
|
53
|
|
|
'name' => $node->language()->getName(), |
|
54
|
|
|
'direction' => $node->language()->getDirection(), |
|
55
|
|
|
'weight' => $node->language()->getWeight(), |
|
56
|
|
|
], |
|
57
|
|
|
'entityUrl' => [ |
|
58
|
|
|
'path' => '/node/' . $node->id(), |
|
59
|
|
|
], |
|
60
|
|
|
'entityOwner' => [ |
|
61
|
|
|
'entityLabel' => $user->label(), |
|
62
|
|
|
], |
|
63
|
|
|
// TODO: Fix this. |
|
64
|
|
|
'entityTranslation' => [ |
|
65
|
|
|
'entityLabel' => $translation->label(), |
|
66
|
|
|
], |
|
67
|
|
|
'entityPublished' => TRUE, |
|
68
|
|
|
'entityCreated' => $created, |
|
69
|
|
|
'entityChanged' => $changed, |
|
70
|
|
|
'viewAccess' => TRUE, |
|
71
|
|
|
'updateAccess' => TRUE, |
|
72
|
|
|
'deleteAccess' => FALSE, |
|
73
|
|
|
]; |
|
74
|
|
|
|
|
75
|
|
|
$query = $this->getQueryFromFile('basic_fields.gql'); |
|
76
|
|
|
|
|
77
|
|
|
// TODO: Check cache metadata. |
|
78
|
|
|
$metadata = $this->defaultCacheMetaData(); |
|
79
|
|
|
$metadata->addCacheContexts([ |
|
80
|
|
|
'user.node_grants:view', |
|
81
|
|
|
]); |
|
82
|
|
|
|
|
83
|
|
|
$metadata->addCacheTags([ |
|
84
|
|
|
'node:1', |
|
85
|
|
|
'node_list', |
|
86
|
|
|
'user:1', |
|
87
|
|
|
]); |
|
88
|
|
|
|
|
89
|
|
|
$this->assertResults($query, ['nid' => (string) $node->id()], [ |
|
90
|
|
|
'node' => ['entities' => [$values]], |
|
91
|
|
|
], $metadata); |
|
92
|
|
|
} |
|
93
|
|
|
|
|
94
|
|
|
} |
|
95
|
|
|
|