public function EntityFieldTest::testSave

Tries to save and load an entity again.

File

drupal/core/modules/system/lib/Drupal/system/Tests/Entity/EntityFieldTest.php, line 257
Definition of Drupal\Core\Entity\Tests\EntityFieldTest.

Class

EntityFieldTest
Tests Entity API base functionality.

Namespace

Drupal\system\Tests\Entity

Code

public function testSave() {
  $entity = $this
    ->createTestEntity();
  $entity
    ->save();
  $this
    ->assertTrue((bool) $entity
    ->id(), 'Entity has received an id.');
  $entity = entity_load('entity_test', $entity
    ->id());
  $this
    ->assertTrue((bool) $entity
    ->id(), 'Entity loaded.');

  // Access the name field.
  $this
    ->assertEqual(1, $entity->id->value, 'ID value can be read.');
  $this
    ->assertTrue(is_string($entity->uuid->value), 'UUID value can be read.');
  $this
    ->assertEqual(LANGUAGE_NOT_SPECIFIED, $entity->langcode->value, 'Language code can be read.');
  $this
    ->assertEqual(language_load(LANGUAGE_NOT_SPECIFIED), $entity->langcode->language, 'Language object can be read.');
  $this
    ->assertEqual($this->entity_user->uid, $entity->user_id->value, 'User id can be read.');
  $this
    ->assertEqual($this->entity_user->name, $entity->user_id->entity->name, 'User name can be read.');
  $this
    ->assertEqual($this->entity_field_text, $entity->field_test_text->value, 'Text field can be read.');
}