Mercurial > hg > cmmr2012-drupal-site
comparison core/modules/jsonapi/tests/src/Functional/ContentLanguageSettingsTest.php @ 5:12f9dff5fda9 tip
Update to Drupal core 8.7.1
author | Chris Cannam |
---|---|
date | Thu, 09 May 2019 15:34:47 +0100 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
4:a9cd425dd02b | 5:12f9dff5fda9 |
---|---|
1 <?php | |
2 | |
3 namespace Drupal\Tests\jsonapi\Functional; | |
4 | |
5 use Drupal\Core\Cache\Cache; | |
6 use Drupal\Core\Session\AccountInterface; | |
7 use Drupal\Core\Url; | |
8 use Drupal\language\Entity\ContentLanguageSettings; | |
9 use Drupal\node\Entity\NodeType; | |
10 | |
11 /** | |
12 * JSON:API integration test for "ContentLanguageSettings" config entity type. | |
13 * | |
14 * @group jsonapi | |
15 */ | |
16 class ContentLanguageSettingsTest extends ResourceTestBase { | |
17 | |
18 /** | |
19 * {@inheritdoc} | |
20 */ | |
21 public static $modules = ['language', 'node']; | |
22 | |
23 /** | |
24 * {@inheritdoc} | |
25 */ | |
26 protected static $entityTypeId = 'language_content_settings'; | |
27 | |
28 /** | |
29 * {@inheritdoc} | |
30 */ | |
31 protected static $resourceTypeName = 'language_content_settings--language_content_settings'; | |
32 | |
33 /** | |
34 * {@inheritdoc} | |
35 * | |
36 * @var \Drupal\language\ContentLanguageSettingsInterface | |
37 */ | |
38 protected $entity; | |
39 | |
40 /** | |
41 * {@inheritdoc} | |
42 */ | |
43 protected function setUpAuthorization($method) { | |
44 $this->grantPermissionsToTestedRole(['administer languages']); | |
45 } | |
46 | |
47 /** | |
48 * {@inheritdoc} | |
49 */ | |
50 protected function createEntity() { | |
51 // Create a "Camelids" node type. | |
52 $camelids = NodeType::create([ | |
53 'name' => 'Camelids', | |
54 'type' => 'camelids', | |
55 ]); | |
56 $camelids->save(); | |
57 | |
58 $entity = ContentLanguageSettings::create([ | |
59 'target_entity_type_id' => 'node', | |
60 'target_bundle' => 'camelids', | |
61 ]); | |
62 $entity->setDefaultLangcode('site_default') | |
63 ->save(); | |
64 | |
65 return $entity; | |
66 } | |
67 | |
68 /** | |
69 * {@inheritdoc} | |
70 */ | |
71 protected function getExpectedDocument() { | |
72 $self_url = Url::fromUri('base:/jsonapi/language_content_settings/language_content_settings/' . $this->entity->uuid())->setAbsolute()->toString(TRUE)->getGeneratedUrl(); | |
73 return [ | |
74 'jsonapi' => [ | |
75 'meta' => [ | |
76 'links' => [ | |
77 'self' => ['href' => 'http://jsonapi.org/format/1.0/'], | |
78 ], | |
79 ], | |
80 'version' => '1.0', | |
81 ], | |
82 'links' => [ | |
83 'self' => ['href' => $self_url], | |
84 ], | |
85 'data' => [ | |
86 'id' => $this->entity->uuid(), | |
87 'type' => 'language_content_settings--language_content_settings', | |
88 'links' => [ | |
89 'self' => ['href' => $self_url], | |
90 ], | |
91 'attributes' => [ | |
92 'default_langcode' => 'site_default', | |
93 'dependencies' => [ | |
94 'config' => [ | |
95 'node.type.camelids', | |
96 ], | |
97 ], | |
98 'langcode' => 'en', | |
99 'language_alterable' => FALSE, | |
100 'status' => TRUE, | |
101 'target_bundle' => 'camelids', | |
102 'target_entity_type_id' => 'node', | |
103 'drupal_internal__id' => 'node.camelids', | |
104 ], | |
105 ], | |
106 ]; | |
107 } | |
108 | |
109 /** | |
110 * {@inheritdoc} | |
111 */ | |
112 protected function getPostDocument() { | |
113 // @todo Update in https://www.drupal.org/node/2300677. | |
114 } | |
115 | |
116 /** | |
117 * {@inheritdoc} | |
118 */ | |
119 protected function getExpectedCacheContexts(array $sparse_fieldset = NULL) { | |
120 return Cache::mergeContexts(parent::getExpectedCacheContexts(), ['languages:language_interface']); | |
121 } | |
122 | |
123 /** | |
124 * {@inheritdoc} | |
125 */ | |
126 protected function createAnotherEntity($key) { | |
127 NodeType::create([ | |
128 'name' => 'Llamaids', | |
129 'type' => 'llamaids', | |
130 ])->save(); | |
131 | |
132 $entity = ContentLanguageSettings::create([ | |
133 'target_entity_type_id' => 'node', | |
134 'target_bundle' => 'llamaids', | |
135 ]); | |
136 $entity->setDefaultLangcode('site_default'); | |
137 $entity->save(); | |
138 | |
139 return $entity; | |
140 } | |
141 | |
142 /** | |
143 * {@inheritdoc} | |
144 */ | |
145 protected static function getExpectedCollectionCacheability(AccountInterface $account, array $collection, array $sparse_fieldset = NULL, $filtered = FALSE) { | |
146 $cacheability = parent::getExpectedCollectionCacheability($account, $collection, $sparse_fieldset, $filtered); | |
147 if (static::entityAccess(reset($collection), 'view', $account)->isAllowed()) { | |
148 $cacheability->addCacheContexts(['languages:language_interface']); | |
149 } | |
150 return $cacheability; | |
151 } | |
152 | |
153 } |