public function CreateTest::assertReadEntityIdFromHeaderAndDb in Zircon Profile 8
Same name and namespace in other branches
- 8.0 core/modules/rest/src/Tests/CreateTest.php \Drupal\rest\Tests\CreateTest::assertReadEntityIdFromHeaderAndDb()
 
Gets the new entity ID from the location header and tries to read it from the database.
Parameters
string $entity_type: Entity type we need to load the entity from DB.
\Drupal\Core\Entity\EntityInterface $entity: The entity we want to check that was inserted correctly.
array $entity_values: The values of $entity.
4 calls to CreateTest::assertReadEntityIdFromHeaderAndDb()
- CreateTest::testCreateComment in core/
modules/ rest/ src/ Tests/ CreateTest.php  - Test comment creation.
 - CreateTest::testCreateEntityTest in core/
modules/ rest/ src/ Tests/ CreateTest.php  - Tests valid and invalid create requests for 'entity_test' entity type.
 - CreateTest::testCreateNode in core/
modules/ rest/ src/ Tests/ CreateTest.php  - Tests several valid and invalid create requests for 'node' entity type.
 - CreateTest::testCreateUser in core/
modules/ rest/ src/ Tests/ CreateTest.php  - Tests several valid and invalid create requests for 'user' entity type.
 
File
- core/
modules/ rest/ src/ Tests/ CreateTest.php, line 379  - Contains \Drupal\rest\Tests\CreateTest.
 
Class
- CreateTest
 - Tests the creation of resources.
 
Namespace
Drupal\rest\TestsCode
public function assertReadEntityIdFromHeaderAndDb($entity_type, EntityInterface $entity, array $entity_values = array()) {
  // Get the location from the HTTP response header.
  $location_url = $this
    ->drupalGetHeader('location');
  $url_parts = explode('/', $location_url);
  $id = end($url_parts);
  // Get the entity using the ID found.
  $loaded_entity = \Drupal::entityManager()
    ->getStorage($entity_type)
    ->load($id);
  $this
    ->assertNotIdentical(FALSE, $loaded_entity, 'The new ' . $entity_type . ' was found in the database.');
  $this
    ->assertEqual($entity
    ->uuid(), $loaded_entity
    ->uuid(), 'UUID of created entity is correct.');
  // Verify that the field values sent and received from DB are the same.
  foreach ($entity_values as $property => $value) {
    $actual_value = $loaded_entity
      ->get($property)->value;
    $send_value = $entity
      ->get($property)->value;
    $this
      ->assertEqual($send_value, $actual_value, 'Created property ' . $property . ' expected: ' . $send_value . ', actual: ' . $actual_value);
  }
  // Delete the entity loaded from DB.
  $loaded_entity
    ->delete();
}