You are here

protected function ContentEntityAutosaveFormTestBase::createTestEntity in Autosave Form 8

Creates a new test entity.

Return value

\Drupal\Core\Entity\ContentEntityInterface The newly created entity.

5 calls to ContentEntityAutosaveFormTestBase::createTestEntity()
ContentEntityAutosaveFormTestBase::doTestAutosaveAfterFormValidationFail in tests/src/FunctionalJavascript/ContentEntity/ContentEntityAutosaveFormTestBase.php
Tests the autosave message not being shown on reload after validation fail.
ContentEntityAutosaveFormTestBase::doTestAutosaveFormExistingEntity in tests/src/FunctionalJavascript/ContentEntity/ContentEntityAutosaveFormTestBase.php
Tests the autosave support on entity forms.
ContentEntityAutosaveFormTestBase::doTestAutosaveStatesPurgingOnConfigEvent in tests/src/FunctionalJavascript/ContentEntity/ContentEntityAutosaveFormTestBase.php
Tests that autosave states are purged on modifying a form related config.
ContentEntityAutosaveFormTestBase::doTestConcurrentEditing in tests/src/FunctionalJavascript/ContentEntity/ContentEntityAutosaveFormTestBase.php
Tests concurrent editing.
ContentEntityAutosaveFormTestBase::doTestSavingRestoredEntityForm in tests/src/FunctionalJavascript/ContentEntity/ContentEntityAutosaveFormTestBase.php
Tests saving an entity form restored from an autosaved state.

File

tests/src/FunctionalJavascript/ContentEntity/ContentEntityAutosaveFormTestBase.php, line 632

Class

ContentEntityAutosaveFormTestBase
Base test class for testing autosave support for entity forms.

Namespace

Drupal\Tests\autosave_form\FunctionalJavascript\ContentEntity

Code

protected function createTestEntity() {
  $entity_type_manager = \Drupal::entityTypeManager();
  $entity_type = $entity_type_manager
    ->getDefinition($this->entityType);
  $storage = $entity_type_manager
    ->getStorage($this->entityType);
  $values = [
    'type' => $this->bundle,
  ];
  if ($label_field_name = $entity_type
    ->getKey('label')) {
    $values[$label_field_name] = 'original title';
  }
  $entity = $storage
    ->create($values);
  if ($entity instanceof EntityOwnerInterface) {
    $entity
      ->setOwner($this->webUser);
  }
  elseif ($entity_type
    ->hasKey('uid')) {
    $entity
      ->set('uid', $this->webUser
      ->id());
  }
  $entity
    ->save();
  $this->originalEntityTitle = $entity
    ->label();
  return $entity;
}