diff --git a/core/modules/hal/tests/src/Functional/EntityResource/BlockContent/BlockContentHalJsonAnonTest.php b/core/modules/hal/tests/src/Functional/EntityResource/BlockContent/BlockContentHalJsonAnonTest.php new file mode 100644 index 0000000..6e1938f --- /dev/null +++ b/core/modules/hal/tests/src/Functional/EntityResource/BlockContent/BlockContentHalJsonAnonTest.php @@ -0,0 +1,137 @@ +applyHalFieldNormalization($default_normalization); + + return $normalization + [ + '_links' => [ + 'self' => [ + 'href' => $this->baseUrl . '/block/1?_format=hal_json', + ], + 'type' => [ + 'href' => $this->baseUrl . '/rest/type/block_content/basic', + ], + ], + 'body' => [ + [ + 'value' => 'The name "llama" was adopted by European settlers from native Peruvians.', + 'format' => 'plain_text', + 'summary' => NULL, + 'lang' => 'en', + ], + ], + 'changed' => [ + [ + 'value' => $this->entity->getChangedTime(), + 'lang' => 'en', + ], + ], + 'default_langcode' => [ + [ + 'value' => TRUE, + 'lang' => 'en', + ], + ], + 'id' => [ + [ + 'value' => $this->entity->id(), + ], + ], + 'info' => [ + [ + 'value' => 'Llama', + 'lang' => 'en', + ], + ], + 'langcode' => [ + [ + 'value' => 'en', + 'lang' => 'en', + ], + ], + 'revision_created' => [ + [ + 'value' => (int) $this->entity->getRevisionCreationTime(), + ], + ], + 'revision_id' => [ + [ + 'value' => $this->entity->getRevisionId(), + ], + ], + 'revision_translation_affected' => [ + [ + 'value' => TRUE, + 'lang' => 'en', + ], + ], + 'type' => [ + [ + 'target_id' => 'basic', + ], + ], + 'uuid' => [ + [ + 'value' => $this->entity->uuid(), + ], + ], + ]; + } + + /** + * {@inheritdoc} + */ + protected function getNormalizedPostEntity() { + return parent::getNormalizedPostEntity() + [ + '_links' => [ + 'type' => [ + 'href' => $this->baseUrl . '/rest/type/block_content/basic', + ], + ], + ]; + } + + /** + * {@inheritdoc} + */ + protected function getExpectedCacheContexts() { + // The 'url.site' cache context is added for '_links' in the response. + return Cache::mergeTags(parent::getExpectedCacheContexts(), ['url.site']); + } + +} diff --git a/core/modules/hal/tests/src/Functional/EntityResource/BlockContent/BlockContentHalJsonBasicAuthTest.php b/core/modules/hal/tests/src/Functional/EntityResource/BlockContent/BlockContentHalJsonBasicAuthTest.php new file mode 100644 index 0000000..94d3ff4 --- /dev/null +++ b/core/modules/hal/tests/src/Functional/EntityResource/BlockContent/BlockContentHalJsonBasicAuthTest.php @@ -0,0 +1,24 @@ +assertResourceErrorResponse(200, FALSE, $response); - } - } diff --git a/core/modules/rest/tests/src/Functional/EntityResource/BlockContent/BlockContentResourceTestBase.php b/core/modules/rest/tests/src/Functional/EntityResource/BlockContent/BlockContentResourceTestBase.php index f5d8889..4d30111 100644 --- a/core/modules/rest/tests/src/Functional/EntityResource/BlockContent/BlockContentResourceTestBase.php +++ b/core/modules/rest/tests/src/Functional/EntityResource/BlockContent/BlockContentResourceTestBase.php @@ -27,7 +27,7 @@ protected static $patchProtectedFieldNames = [ 'id', 'revision_id', - 'changed' + 'changed', ]; /** @@ -43,26 +43,27 @@ protected function setUpAuthorization($method) { } /** - * @return mixed + * {@inheritdoc} */ protected function createEntity() { - $block_content_type = BlockContentType::create(array( + $block_content_type = BlockContentType::create([ 'id' => 'basic', 'label' => 'basic', - 'revision' => FALSE - )); + 'revision' => FALSE, + ]); $block_content_type->save(); block_content_add_body_field($block_content_type->id()); // Create a "Llama" custom block. - $block_content = BlockContent::create(array( + $block_content = BlockContent::create([ 'info' => 'Llama', 'type' => 'basic', - 'body' => array( + 'body' => [ 'value' => 'The name "llama" was adopted by European settlers from native Peruvians.', 'format' => 'plain_text', - ), - )); + ], + ]); + $block_content->setChangedTime(123456789) ->setRevisionCreationTime(123456789) ->save(); @@ -71,18 +72,18 @@ protected function createEntity() { } /** - * @return mixed + * {@inheritdoc} */ protected function getExpectedNormalizedEntity() { return [ 'id' => [ [ - 'value' => '1' + 'value' => 1, ], ], 'uuid' => [ [ - 'value' => $this->entity->uuid() + 'value' => $this->entity->uuid(), ], ], 'langcode' => [ @@ -94,33 +95,34 @@ protected function getExpectedNormalizedEntity() { [ 'target_id' => 'basic', 'target_type' => 'block_content_type', - 'target_uuid' => BlockContentType::load('basic')->uuid() + 'target_uuid' => BlockContentType::load('basic')->uuid(), ], ], 'info' => [ [ - 'value' => 'Llama' + 'value' => 'Llama', ], ], - 'revision_log' => [ - - ], + 'revision_log' => [], 'changed' => [ [ - 'value' => '123456789' + 'value' => $this->entity->getChangedTime(), ], ], - 'revision_created' => [ + 'revision_id' => [ [ - 'value' => '123456789' + 'value' => 1, ], ], - 'revision_user' => [ - + 'revision_created' => [ + [ + 'value' => (int) $this->entity->getRevisionCreationTime(), + ], ], + 'revision_user' => [], 'revision_translation_affected' => [ [ - 'value' => 1 + 'value' => TRUE, ], ], 'default_langcode' => [ @@ -132,8 +134,9 @@ protected function getExpectedNormalizedEntity() { [ 'value' => 'The name "llama" was adopted by European settlers from native Peruvians.', 'format' => 'plain_text', - ] - ] + 'summary' => NULL, + ], + ], ]; }