diff --git a/core/modules/rest/lib/Drupal/rest/Tests/UpdateTest.php b/core/modules/rest/lib/Drupal/rest/Tests/UpdateTest.php index f438043..accf33d 100644 --- a/core/modules/rest/lib/Drupal/rest/Tests/UpdateTest.php +++ b/core/modules/rest/lib/Drupal/rest/Tests/UpdateTest.php @@ -32,7 +32,7 @@ public static function getInfo() { /** * Tests several valid and invalid update requests on test entities. */ - public function testCreate() { + public function testUpdate() { $serializer = drupal_container()->get('serializer'); // @todo once EntityNG is implemented for other entity types test all other // entity types here as well. @@ -48,16 +48,20 @@ public function testCreate() { $entity_values = $this->entityValues($entity_type); $entity = entity_create($entity_type, $entity_values); $entity->save(); - // Create a second entity that will overwrite the original. + + // Create a second set of entity values that will overwrite the original. $update_values = $this->entityValues($entity_type); - // @todo Remove the next line once deserialization is implemented. For now - // we set the update value to the same that is used in the RequestHandler. - $update_values['name'] = 'test'; - $update_entity = entity_create($entity_type, $entity_values); + // @todo Remove the user reference field for now until deserialization for + // entity references is implemented. + unset($update_values['user_id']); + // Overwrite the properties with the updated values. + foreach ($update_values as $property => $value) { + $entity->set($property, $value); + } - $serialized = $serializer->serialize($update_entity, 'drupal_jsonld'); + $serialized = $serializer->serialize($entity, 'drupal_jsonld'); // Update the entity over the web API. - $response = $this->httpRequest('entity/' . $entity_type . '/' . $entity->id(), 'PUT', $serialized, 'application/vnd.drupal.ld+json'); + $this->httpRequest('entity/' . $entity_type . '/' . $entity->id(), 'PUT', $serialized, 'application/vnd.drupal.ld+json'); $this->assertResponse('200', 'HTTP response code is correct.'); // Re-load updated entity from the database. @@ -69,7 +73,7 @@ public function testCreate() { // Try to update an entity without proper permissions. $this->drupalLogout(); - $response = $this->httpRequest('entity/' . $entity_type . '/' . $entity->id(), 'PUT', $serialized, 'application/vnd.drupal.ld+json'); + $this->httpRequest('entity/' . $entity_type . '/' . $entity->id(), 'PUT', $serialized, 'application/vnd.drupal.ld+json'); $this->assertResponse(403); // Try to update a resource which is not web API enabled. @@ -78,7 +82,7 @@ public function testCreate() { // options. unset($this->curlHandle); $this->drupalLogin($account); - $response = $this->httpRequest('entity/' . $entity_type . '/' . $entity->id(), 'PUT', $serialized, 'application/vnd.drupal.ld+json'); + $this->httpRequest('entity/' . $entity_type . '/' . $entity->id(), 'PUT', $serialized, 'application/vnd.drupal.ld+json'); $this->assertResponse(404); } }