diff --git a/core/modules/rest/lib/Drupal/rest/Tests/CreateTest.php b/core/modules/rest/lib/Drupal/rest/Tests/CreateTest.php index 4ccc0b6..3a8d0db 100644 --- a/core/modules/rest/lib/Drupal/rest/Tests/CreateTest.php +++ b/core/modules/rest/lib/Drupal/rest/Tests/CreateTest.php @@ -105,6 +105,15 @@ public function testCreate() { $this->assertResponse(403); $this->assertFalse(entity_load_multiple($entity_type, NULL, TRUE), 'No entity has been created in the database.'); + // Try to send invalid data to trigger the entity validation constraints. + // Send a UUID that is too long. + $entity->set('uuid', $this->randomName(129)); + $invalid_serialized = $serializer->serialize($entity, $this->defaultFormat); + $response = $this->httpRequest('entity/' . $entity_type, 'POST', $invalid_serialized, $this->defaultMimeType); + $this->assertResponse(400); + $error = drupal_json_decode($response); + $this->assertEqual($error['error'], "Entity validation failed.\nuuid.0.value: This value is too long. It should have 128 characters or less.\n"); + // Try to create an entity without proper permissions. $this->drupalLogout(); $this->httpRequest('entity/' . $entity_type, 'POST', $serialized, $this->defaultMimeType); diff --git a/core/modules/rest/lib/Drupal/rest/Tests/UpdateTest.php b/core/modules/rest/lib/Drupal/rest/Tests/UpdateTest.php index eca41bc..60eb670 100644 --- a/core/modules/rest/lib/Drupal/rest/Tests/UpdateTest.php +++ b/core/modules/rest/lib/Drupal/rest/Tests/UpdateTest.php @@ -114,6 +114,15 @@ public function testPatchUpdate() { $loaded_entity = entity_load($entity_type, 9999, TRUE); $this->assertFalse($loaded_entity, 'Entity 9999 was not created.'); + // Try to send invalid data to trigger the entity validation constraints. + // Send a UUID that is too long. + $entity->set('uuid', $this->randomName(129)); + $invalid_serialized = $serializer->serialize($entity, $this->defaultFormat); + $response = $this->httpRequest('entity/' . $entity_type . '/' . $entity->id(), 'PATCH', $invalid_serialized, $this->defaultMimeType); + $this->assertResponse(400); + $error = drupal_json_decode($response); + $this->assertEqual($error['error'], "Entity validation failed.\nuuid.0.value: This value is too long. It should have 128 characters or less.\n"); + // Try to update an entity without proper permissions. $this->drupalLogout(); $this->httpRequest('entity/' . $entity_type . '/' . $entity->id(), 'PATCH', $serialized, $this->defaultMimeType);