You are here

protected function EntityFieldTest::doTestSave in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 core/modules/system/src/Tests/Entity/EntityFieldTest.php \Drupal\system\Tests\Entity\EntityFieldTest::doTestSave()

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::doTestSave()
EntityFieldTest::testSave in core/modules/system/src/Tests/Entity/EntityFieldTest.php
Tries to save and load an entity again.

File

core/modules/system/src/Tests/Entity/EntityFieldTest.php, line 364
Contains \Drupal\system\Tests\Entity\EntityFieldTest.

Class

EntityFieldTest
Tests the Entity Field API.

Namespace

Drupal\system\Tests\Entity

Code

protected function doTestSave($entity_type) {
  $langcode_key = $this->entityManager
    ->getDefinition($entity_type)
    ->getKey('langcode');
  $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('en', $entity->{$langcode_key}->value, format_string('%entity_type: Language code can be read.', array(
    '%entity_type' => $entity_type,
  )));
  $this
    ->assertEqual(\Drupal::languageManager()
    ->getLanguage('en'), $entity->{$langcode_key}->language, format_string('%entity_type: Language object can be read.', array(
    '%entity_type' => $entity_type,
  )));
  $this
    ->assertEqual($this->entityUser
    ->id(), $entity->user_id->target_id, format_string('%entity_type: User id can be read.', array(
    '%entity_type' => $entity_type,
  )));
  $this
    ->assertEqual($this->entityUser
    ->getUsername(), $entity->user_id->entity->name->value, format_string('%entity_type: User name can be read.', array(
    '%entity_type' => $entity_type,
  )));
  $this
    ->assertEqual($this->entityFieldText, $entity->field_test_text->value, format_string('%entity_type: Text field can be read.', array(
    '%entity_type' => $entity_type,
  )));
}