You are here

protected function ResourceTestBase::createAnotherEntity in JSON:API 8

Same name and namespace in other branches
  1. 8.2 tests/src/Functional/ResourceTestBase.php \Drupal\Tests\jsonapi\Functional\ResourceTestBase::createAnotherEntity()

Creates another entity to be tested.

Parameters

mixed $key: A unique key to be used for the ID and/or label of the duplicated entity.

Return value

\Drupal\Core\Entity\EntityInterface Another entity based on $this->entity.

Throws

\Drupal\Core\Entity\EntityStorageException

4 calls to ResourceTestBase::createAnotherEntity()
FileTest::createAnotherEntity in tests/src/Functional/FileTest.php
Creates another entity to be tested.
ResourceTestBase::doTestRelationshipPost in tests/src/Functional/ResourceTestBase.php
Performs one round of relationship POST, PATCH and DELETE route testing.
ResourceTestBase::getEntityCollection in tests/src/Functional/ResourceTestBase.php
Sets up a collection of entities of the same type for testing.
ResourceTestBase::testPatchIndividual in tests/src/Functional/ResourceTestBase.php
Tests PATCHing an individual resource, plus edge cases to ensure good DX.
10 methods override ResourceTestBase::createAnotherEntity()
BaseFieldOverrideTest::createAnotherEntity in tests/src/Functional/BaseFieldOverrideTest.php
Creates another entity to be tested.
ContentLanguageSettingsTest::createAnotherEntity in tests/src/Functional/ContentLanguageSettingsTest.php
Creates another entity to be tested.
EditorTest::createAnotherEntity in tests/src/Functional/EditorTest.php
Creates another entity to be tested.
EntityFormDisplayTest::createAnotherEntity in tests/src/Functional/EntityFormDisplayTest.php
Creates another entity to be tested.
EntityViewDisplayTest::createAnotherEntity in tests/src/Functional/EntityViewDisplayTest.php
Creates another entity to be tested.

... See full list

File

tests/src/Functional/ResourceTestBase.php, line 351

Class

ResourceTestBase
Subclass this for every JSON API resource type.

Namespace

Drupal\Tests\jsonapi\Functional

Code

protected function createAnotherEntity($key) {
  $duplicate = $this
    ->getEntityDuplicate($this->entity, $key);

  // Some entity types are not stored, hence they cannot be reloaded.
  if (get_class($this->entityStorage) !== ContentEntityNullStorage::class) {
    $duplicate
      ->set('field_rest_test', 'Second collection entity');
  }
  $duplicate
    ->save();
  return $duplicate;
}