You are here

public function EntityAPITestCase::testChanges in Entity API 7

Tests determining changes.

File

./entity.test, line 386
Entity CRUD API tests.

Class

EntityAPITestCase
Test basic API.

Code

public function testChanges() {
  module_enable(array(
    'entity_feature',
  ));
  $types = entity_load_multiple_by_name('entity_test_type');

  // Override the default entity, such it gets saved in the DB.
  $types['test']->label = 'test_changes';
  $types['test']
    ->save();

  // Now test an update without applying any changes.
  $types['test']
    ->save();
  $this
    ->assertEqual($types['test']->label, 'test_changes', 'No changes have been determined.');

  // Apply changes.
  $types['test']->label = 'updated';
  $types['test']
    ->save();

  // The hook implementations entity_test_entity_test_type_presave() and
  // entity_test_entity_test_type_update() determine changes and change the
  // label.
  $this
    ->assertEqual($types['test']->label, 'updated_presave_update', 'Changes have been determined.');

  // Test the static load cache to be cleared.
  $types = entity_load_multiple_by_name('entity_test_type');
  $this
    ->assertEqual($types['test']->label, 'updated_presave', 'Static cache has been cleared.');
}