You are here

public function FieldTestBase::testFieldBasics in Multiversion 8.2

File

src/Tests/FieldTestBase.php, line 90

Class

FieldTestBase

Namespace

Drupal\multiversion\Tests

Code

public function testFieldBasics() {
  foreach ($this->entityTypes as $entity_type_id => $info) {
    $storage = $this->entityTypeManager
      ->getStorage($entity_type_id);
    $entity = $storage
      ->create($info);
    $this
      ->assertTrue(is_a($entity->{$this->fieldName}, $this->itemListClass), "Field item list implements correct interface on created {$entity_type_id}.");
    $count = $entity->{$this->fieldName}
      ->count();
    $this
      ->assertTrue($this->createdEmpty ? empty($count) : !empty($count), "Field is created with no field items for {$entity_type_id}.");
    $entity
      ->save();
    $entity_id = $entity
      ->id();
    $entity = $storage
      ->load($entity_id);
    $this
      ->assertFalse($entity->{$this->fieldName}
      ->isEmpty(), "Field was attached on loaded {$entity_type_id}.");
    $storage
      ->loadMultiple([
      $entity_id,
    ]);
    $entity = $storage
      ->loadDeleted($entity_id);
    $this
      ->assertFalse($entity->{$this->fieldName}
      ->isEmpty(), "Field was attached on deleted {$entity_type_id}.");
  }
}