You are here

public function ServicesEntityGenericEntityResource::testEntityDelete in Services Entity API 7.2

Test 'Delete' service.

File

tests/services_entity.test, line 514
Services Entity Tests

Class

ServicesEntityGenericEntityResource
Test resources on the Generic controller, using a test entity type.

Code

public function testEntityDelete() {

  // Create our privileged user.
  $this->privilegedUser = $this
    ->drupalCreateUser(array(
    'delete services_entity_test entities',
  ));

  // Create an entity to delete.
  $entity_data = array(
    'type' => 'alpha',
    'name' => $this
      ->randomString(),
    'uid' => $this->privilegedUser->uid,
  );
  $entity = entity_create('services_entity_test', $entity_data);
  $entity
    ->save();

  // Log in as the unprivileged user.
  $this
    ->drupalLogin($this->unPrivilegedUser);
  $response = $this
    ->servicesDelete($this->resource_path . '/' . $entity->eid);
  $this
    ->assertTrue($response['code'] == '401', "Deletion of an entity without 'delete' access returns a 401.");

  // Log in as the privileged user.
  $this
    ->drupalLogin($this->privilegedUser);
  $response = $this
    ->servicesDelete($this->resource_path . '/' . $entity->eid);

  // Load the entity from the DB to check it's been deleted.
  // Clear the cache first.
  entity_get_controller('services_entity_test')
    ->resetCache();
  $deleted_entity = entity_load_single('services_entity_test', $entity->eid);
  $this
    ->assertFalse($deleted_entity, 'The entity has been deleted.');
}