diff --git a/core/modules/hal/tests/src/Functional/EntityResource/Node/NodeHalJsonCookieTranslationsTest.php b/core/modules/hal/tests/src/Functional/EntityResource/Node/NodeHalJsonCookieTranslationsTest.php index 838b3ed..1a107ce 100644 --- a/core/modules/hal/tests/src/Functional/EntityResource/Node/NodeHalJsonCookieTranslationsTest.php +++ b/core/modules/hal/tests/src/Functional/EntityResource/Node/NodeHalJsonCookieTranslationsTest.php @@ -2,9 +2,11 @@ namespace Drupal\Tests\hal\Functional\EntityResource\Node; +use Drupal\Component\Utility\NestedArray; use Drupal\language\Entity\ConfigurableLanguage; use Drupal\Tests\hal\Functional\EntityResource\HalEntityNormalizationTrait; use Drupal\user\Entity\User; +use GuzzleHttp\RequestOptions; /** * @group hal @@ -119,4 +121,35 @@ protected function getExpectedNormalizedEntity() { return $normalization; } + /** + * {@inheritdoc} + */ + public function testPost() { + parent::testPost(); + + // Create an entity with a translation. + $entity_body_with_a_translations = $this->serializer->encode($this->getExpectedNormalizedEntity(), static::$format); + + $request_options = []; + $request_options[RequestOptions::HEADERS]['Content-Type'] = static::$mimeType; + $request_options[RequestOptions::BODY] = $entity_body_with_a_translations; + $request_options = NestedArray::mergeDeep($request_options, $this->getAuthenticationRequestOptions('POST')); + + $url = $this->getPostUrl(); + $url->setOption('query', ['_format' => static::$format]); + + // 201 for well-formed request. + $response = $this->request('POST', $url, $request_options); + $this->assertResourceResponse(201, FALSE, $response); + /** @var \Drupal\node\NodeInterface $created_node */ + $created_node = $this->serializer->denormalize((string) $response->getBody(), static::$format); + $this->assertSame([$created_node->toUrl('canonical')->setAbsolute(TRUE)->toString()], $response->getHeader('Location')); + $this->assertFalse($response->hasHeader('X-Drupal-Cache')); + + $this->assertSame('Llama', $created_node->getTitle()); + $this->assertSame('Lama', $created_node->getTranslation('de')->getTitle()); + + + } + }