diff --git a/core/modules/hal/tests/src/Functional/EntityResource/MenuLinkContent/MenuLinkContentHalJsonAnonTest.php b/core/modules/hal/tests/src/Functional/EntityResource/MenuLinkContent/MenuLinkContentHalJsonAnonTest.php index 02d7446..5abe6c4 100644 --- a/core/modules/hal/tests/src/Functional/EntityResource/MenuLinkContent/MenuLinkContentHalJsonAnonTest.php +++ b/core/modules/hal/tests/src/Functional/EntityResource/MenuLinkContent/MenuLinkContentHalJsonAnonTest.php @@ -3,6 +3,7 @@ namespace Drupal\Tests\hal\Functional\EntityResource\MenuLinkContent; use Drupal\Core\Cache\Cache; +use Drupal\Tests\hal\Functional\EntityResource\HalEntityNormalizationTrait; use Drupal\Tests\rest\Functional\AnonResourceTestTrait; use Drupal\Tests\rest\Functional\EntityResource\MenuLinkContent\MenuLinkContentResourceTestBase; @@ -13,6 +14,7 @@ */ class MenuLinkContentHalJsonAnonTest extends MenuLinkContentResourceTestBase { + use HalEntityNormalizationTrait; use AnonResourceTestTrait; /** @@ -33,7 +35,35 @@ class MenuLinkContentHalJsonAnonTest extends MenuLinkContentResourceTestBase { /** * {@inheritdoc} */ - protected static $expectedErrorMimeType = 'application/json'; + protected function getExpectedNormalizedEntity() { + $default_normalization = parent::getExpectedNormalizedEntity(); + + $normalization = $this->applyHalFieldNormalization($default_normalization); + + return $normalization + [ + '_links' => [ + 'self' => [ + 'href' => $this->baseUrl . '/admin/structure/menu/item/1/edit?_format=hal_json', + ], + 'type' => [ + 'href' => $this->baseUrl . '/rest/type/menu_link_content/menu_link_content', + ], + ], + ]; + } + + /** + * {@inheritdoc} + */ + protected function getNormalizedPostEntity() { + return parent::getNormalizedPostEntity() + [ + '_links' => [ + 'type' => [ + 'href' => $this->baseUrl . '/rest/type/menu_link_content/menu_link_content', + ], + ], + ]; + } /** * {@inheritdoc} diff --git a/core/modules/rest/tests/src/Functional/EntityResource/EntityResourceTestBase.php b/core/modules/rest/tests/src/Functional/EntityResource/EntityResourceTestBase.php index e9d9c48..e904728 100644 --- a/core/modules/rest/tests/src/Functional/EntityResource/EntityResourceTestBase.php +++ b/core/modules/rest/tests/src/Functional/EntityResource/EntityResourceTestBase.php @@ -561,7 +561,7 @@ public function testPost() { // DX: 422 when invalid entity: multiple values sent for single-value field. $response = $this->request('POST', $url, $request_options); $label_field = $this->entity->getEntityType()->hasKey('label') ? $this->entity->getEntityType()->getKey('label') : static::$labelFieldName; - $label_field_capitalized = ucfirst($label_field); + $label_field_capitalized = $this->entity->getFieldDefinition($label_field)->getLabel(); $this->assertResourceErrorResponse(422, "Unprocessable Entity: validation failed.\n$label_field: $label_field_capitalized: this field cannot hold more than 1 values.\n", $response); @@ -751,7 +751,7 @@ public function testPatch() { // DX: 422 when invalid entity: multiple values sent for single-value field. $response = $this->request('PATCH', $url, $request_options); $label_field = $this->entity->getEntityType()->hasKey('label') ? $this->entity->getEntityType()->getKey('label') : static::$labelFieldName; - $label_field_capitalized = ucfirst($label_field); + $label_field_capitalized = $this->entity->getFieldDefinition($label_field)->getLabel(); $this->assertResourceErrorResponse(422, "Unprocessable Entity: validation failed.\n$label_field: $label_field_capitalized: this field cannot hold more than 1 values.\n", $response); diff --git a/core/modules/rest/tests/src/Functional/EntityResource/MenuLinkContent/MenuLinkContentResourceTestBase.php b/core/modules/rest/tests/src/Functional/EntityResource/MenuLinkContent/MenuLinkContentResourceTestBase.php index 77c093b..825e556 100644 --- a/core/modules/rest/tests/src/Functional/EntityResource/MenuLinkContent/MenuLinkContentResourceTestBase.php +++ b/core/modules/rest/tests/src/Functional/EntityResource/MenuLinkContent/MenuLinkContentResourceTestBase.php @@ -23,7 +23,9 @@ /** * {@inheritdoc} */ - protected static $patchProtectedFieldNames = []; + protected static $patchProtectedFieldNames = [ + 'changed' + ]; /** * The MenuLinkContent entity. @@ -66,96 +68,16 @@ protected function createEntity() { /** * {@inheritdoc} */ - protected function getExpectedNormalizedEntity() { + protected function getNormalizedPostEntity() { return [ - 'uuid' => [ - [ - 'value' => $this->entity->uuid(), - ], - ], - 'id' => [ - [ - 'value' => '1', - ], - ], 'title' => [ [ - 'value' => 'Llama Gabilondo', - 'lang' => 'en', + 'value' => 'Dramallama', ], ], 'link' => [ [ - 'uri' => 'https://nl.wikipedia.org/wiki/Llama', - 'title' => NULL, - 'options' => [], - ], - ], - 'weight' => [ - [ - 'value' => 0, - ], - ], - 'menu_name' => [ - [ - 'value' => 'main', - ], - ], - 'langcode' => [ - [ - 'value' => 'en', - 'lang' => 'en', - ], - ], - '_links' => [ - 'self' => [ - 'href' => $this->baseUrl . '/admin/structure/menu/item/1/edit?_format=hal_json', - ], - 'type' => [ - 'href' => $this->baseUrl . '/rest/type/menu_link_content/menu_link_content', - ], - ], - 'bundle' => [ - [ - 'value' => 'menu_link_content', - ], - ], - 'description' => [ - [ - 'value' => 'Llama Gabilondo', - 'lang' => 'en', - ], - ], - 'external' => [ - [ - 'value' => '0', - ], - ], - 'rediscover' => [ - [ - 'value' => '0', - ], - ], - 'expanded' => [ - [ - 'value' => '0', - ], - ], - 'enabled' => [ - [ - 'value' => TRUE, - ], - ], - 'changed' => [ - [ - 'value' => $this->entity->getChangedTime(), - 'lang' => 'en', - ], - ], - 'default_langcode' => [ - [ - 'value' => '1', - 'lang' => 'en', + 'uri' => 'http://www.urbandictionary.com/define.php?term=drama%20llama', ], ], ]; @@ -164,19 +86,88 @@ protected function getExpectedNormalizedEntity() { /** * {@inheritdoc} */ - protected function getNormalizedPostEntity() { + protected function getExpectedNormalizedEntity() { return [ - 'name' => [ - [ - 'title' => 'Dramallama', - ], - ], - 'link' => [ - [ - 'uri' => 'http://www.urbandictionary.com/define.php?term=drama%20llama', - ], - ], - ]; + 'uuid' => [ + [ + 'value' => $this->entity->uuid(), + ], + ], + 'id' => [ + [ + 'value' => '1', + ], + ], + 'title' => [ + [ + 'value' => 'Llama Gabilondo', + ], + ], + 'link' => [ + [ + 'uri' => 'https://nl.wikipedia.org/wiki/Llama', + 'title' => NULL, + 'options' => [], + ], + ], + 'weight' => [ + [ + 'value' => 0, + ], + ], + 'menu_name' => [ + [ + 'value' => 'main', + ], + ], + 'langcode' => [ + [ + 'value' => 'en', + ], + ], + 'bundle' => [ + [ + 'value' => 'menu_link_content', + ], + ], + 'description' => [ + [ + 'value' => 'Llama Gabilondo', + ], + ], + 'external' => [ + [ + 'value' => '0', + ], + ], + 'rediscover' => [ + [ + 'value' => '0', + ], + ], + 'expanded' => [ + [ + 'value' => '0', + ], + ], + 'enabled' => [ + [ + 'value' => TRUE, + ], + ], + 'changed' => [ + [ + 'value' => $this->entity->getChangedTime(), + ], + ], + 'default_langcode' => [ + [ + 'value' => '1', + ], + ], + ]; } + + }