protected function EntityFieldTest::assertSave

Executes the save tests for the given entity type.

Parameters

string $entity_type: The entity type to run the tests with.

1 call to EntityFieldTest::assertSave()
EntityFieldTest::testSave in drupal/core/modules/system/lib/Drupal/system/Tests/Entity/EntityFieldTest.php
Tries to save and load an entity again.

File

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

Class

EntityFieldTest
Tests Entity API base functionality.

Namespace

Drupal\system\Tests\Entity

Code

protected function assertSave($entity_type) {
  $entity = $this
    ->createTestEntity($entity_type);
  $entity
    ->save();
  $this
    ->assertTrue((bool) $entity
    ->id(), format_string('%entity_type: Entity has received an id.', array(
    '%entity_type' => $entity_type,
  )));
  $entity = entity_load($entity_type, $entity
    ->id());
  $this
    ->assertTrue((bool) $entity
    ->id(), format_string('%entity_type: Entity loaded.', array(
    '%entity_type' => $entity_type,
  )));

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