diff --git a/core/modules/hal/tests/src/Functional/EntityResource/Node/NodeHalJsonCookieTranslationsTest.php b/core/modules/hal/tests/src/Functional/EntityResource/Node/NodeHalJsonCookieTranslationsTest.php new file mode 100644 index 0000000..838b3ed --- /dev/null +++ b/core/modules/hal/tests/src/Functional/EntityResource/Node/NodeHalJsonCookieTranslationsTest.php @@ -0,0 +1,122 @@ + 'languages:language_content', + 1 => 'languages:language_interface', + 2 => 'url.site', + 3 => 'user.permissions', + ]; + } + + /** + * {@inheritdoc} + */ + protected function setUpAuthorization($method) { + parent::setUpAuthorization($method); + $this->grantPermissionsToTestedRole(['translate any entity']); + } + + /** + * {@inheritdoc} + */ + protected function createEntity() { + if (!ConfigurableLanguage::load('de')) { + ConfigurableLanguage::createFromLangcode('de')->save(); + } + + /** @var \Drupal\node\NodeInterface $node */ + $node = parent::createEntity(); + $translation = $node->addTranslation('de', $node->toArray()); + $translation->get('title')->value = 'Lama'; + $node->save(); + return $node; + } + + /** + * {@inheritdoc} + */ + protected function getExpectedNormalizedEntity() { + $normalization = parent::getExpectedNormalizedEntity(); + + foreach ($this->entity->getFieldDefinitions() as $field_name => $field_definition) { + // @todo It seems that currently two items exist if the *storage* is + // translatable, should be when the field is? + if ($field_definition->getFieldStorageDefinition()->isTranslatable() && isset($normalization[$field_name])) { + $normalization[$field_name][1] = [ + 'lang' => 'de', + ] + $normalization[$field_name][0]; + } + } + + $normalization['title'][1]['value'] = 'Lama'; + $normalization['langcode'][1]['value'] = 'de'; + $normalization['default_langcode'][1]['value'] = '0'; + + $author = User::load($this->entity->getOwnerId()); + $normalization['_links'][$this->baseUrl . '/rest/relation/node/camelids/uid'][1] = [ + 'href' => $this->baseUrl . '/user/' . $author->id() . '?_format=hal_json', + 'lang' => 'de', + ]; + $normalization['_embedded'][$this->baseUrl . '/rest/relation/node/camelids/uid'][1] = [ + '_links' => [ + 'self' => [ + 'href' => $this->baseUrl . '/user/' . $author->id() . '?_format=hal_json', + ], + 'type' => [ + 'href' => $this->baseUrl . '/rest/type/user/user', + ], + ], + 'uuid' => [ + ['value' => $author->uuid()] + ], + 'lang' => 'de', + ]; + + return $normalization; + } + +} diff --git a/core/modules/rest/tests/src/Functional/EntityResource/EntityResourceTestBase.php b/core/modules/rest/tests/src/Functional/EntityResource/EntityResourceTestBase.php index 992e3b0..85f4dc0 100644 --- a/core/modules/rest/tests/src/Functional/EntityResource/EntityResourceTestBase.php +++ b/core/modules/rest/tests/src/Functional/EntityResource/EntityResourceTestBase.php @@ -435,12 +435,16 @@ public function testGet() { // Finally, assert that the expected 'Link' headers are present. $this->assertArrayHasKey('Link', $response->getHeaders()); $link_relation_type_manager = $this->container->get('plugin.manager.link_relation_type'); - $expected_link_relation_headers = array_map(function ($rel) use ($link_relation_type_manager) { + $expected_link_relation_headers = array_filter(array_map(function ($rel) use ($link_relation_type_manager) { + // @todo What to do about content_translation link relationships? + if (strpos($rel, 'drupal:content-translation') !== FALSE) { + return FALSE; + } $definition = $link_relation_type_manager->getDefinition($rel, FALSE); return (!empty($definition['uri'])) ? $definition['uri'] : $rel; - }, array_keys($this->entity->getEntityType()->getLinkTemplates())); + }, array_keys($this->entity->getEntityType()->getLinkTemplates()))); $parse_rel_from_link_header = function ($value) use ($link_relation_type_manager) { $matches = []; if (preg_match('/rel="([^"]+)"/', $value, $matches) === 1) {