diff --git a/core/modules/rest/src/Tests/NodeTest.php b/core/modules/rest/src/Tests/NodeTest.php index 8269699..c2b26a4 100644 --- a/core/modules/rest/src/Tests/NodeTest.php +++ b/core/modules/rest/src/Tests/NodeTest.php @@ -157,7 +157,6 @@ public function testBundleNormalization() { 'title' => [['value' => $this->randomString() ]], ]; - // testing $this->postNode($data); // Make sure the response is "CREATED". diff --git a/core/modules/rest/src/Tests/RESTTestBase.php b/core/modules/rest/src/Tests/RESTTestBase.php index 79a207d..6a461ab 100644 --- a/core/modules/rest/src/Tests/RESTTestBase.php +++ b/core/modules/rest/src/Tests/RESTTestBase.php @@ -395,7 +395,7 @@ protected function removeNodeFieldsForNonAdminUsers(NodeInterface $node) { } /** - * Check to see if the http request response body is identical to the expected + * Check to see if the HTTP request response body is identical to the expected * value. * * @param $expected @@ -415,6 +415,6 @@ protected function removeNodeFieldsForNonAdminUsers(NodeInterface $node) { * TRUE if the assertion succeeded, FALSE otherwise. */ protected function assertResponseBody($expected, $message = '', $group = 'REST Response') { - return $this->assertIdentical($expected, $this->responseBody, $message ? $message : SafeMarkup::format('Response body @expected (expected) is equal to @response (actual).', array('@expected' => var_export($expected, TRUE), '@response' => var_export($this->responseBody, TRUE))), $group); + return $this->assertIdentical($expected, $this->responseBody, $message ? $message : strtr('Response body @expected (expected) is equal to @response (actual).', array('@expected' => var_export($expected, TRUE), '@response' => var_export($this->responseBody, TRUE))), $group); } } diff --git a/core/modules/serialization/src/Normalizer/EntityNormalizer.php b/core/modules/serialization/src/Normalizer/EntityNormalizer.php index 1706f9a..e806ff6 100644 --- a/core/modules/serialization/src/Normalizer/EntityNormalizer.php +++ b/core/modules/serialization/src/Normalizer/EntityNormalizer.php @@ -53,7 +53,7 @@ public function denormalize($data, $class, $format = NULL, array $context = []) // Don't try to create an entity without an entity type id. if (!$entity_type_definition) { - throw new UnexpectedValueException('A valid entity type is required for denormalization.'); + throw new UnexpectedValueException(sprintf('The specified entity type "%s" does not exist. A valid etnity type is required for denormalization', $entity_type_id)); } // The bundle property will be required to denormalize a bundleable entity. @@ -62,24 +62,24 @@ public function denormalize($data, $class, $format = NULL, array $context = []) // Get the base field definitions for this entity type. $base_field_definitions = $this->entityManager->getBaseFieldDefinitions($entity_type_id); - // Set a default key ID. - $key_id = 'value'; - // Get the ID key from the base field definition for the bundle key. - if (isset($base_field_definitions[$bundle_key])) { - $key_id = $base_field_definitions[$bundle_key]->getFieldStorageDefinition()->getMainPropertyName(); - } + // Get the ID key from the base field definition for the bundle key or + // default to 'value'. + $key_id = isset($base_field_definitions[$bundle_key]) ? $base_field_definitions[$bundle_key]->getFieldStorageDefinition()->getMainPropertyName() : 'value'; // Normalize the bundle if it is not explicitly set. - $data[$bundle_key] = isset($data[$bundle_key][0][$key_id]) - ? $data[$bundle_key][0][$key_id] - : (isset($data[$bundle_key]) ? $data[$bundle_key] : NULL); + $data[$bundle_key] = isset($data[$bundle_key][0][$key_id]) ? $data[$bundle_key][0][$key_id] : (isset($data[$bundle_key]) ? $data[$bundle_key] : NULL); // Get the bundle entity type from the entity type definition. $bundle_type_id = $entity_type_definition->getBundleEntityType(); $bundle_types = $bundle_type_id ? $this->entityManager->getStorage($bundle_type_id)->getQuery()->execute() : []; + // Make sure a bundle has been provided. + if (!is_string($data[$bundle_key])) { + throw new UnexpectedValueException('A string must be provided as a bundle value.'); + } + // Make sure the submitted bundle is a valid bundle for the entity type. - if (!is_string($data[$bundle_key]) || ($bundle_types && !in_array($data[$bundle_key], $bundle_types))) { + if ($bundle_types && !in_array($data[$bundle_key], $bundle_types)) { throw new UnexpectedValueException(sprintf('"%s" is not a valid bundle type for denormalization.', $data[$bundle_key])); } }