You are here

protected function EntityResourceTestBase::createAnotherEntity in Drupal 9

Same name and namespace in other branches
  1. 8 core/modules/rest/tests/src/Functional/EntityResource/EntityResourceTestBase.php \Drupal\Tests\rest\Functional\EntityResource\EntityResourceTestBase::createAnotherEntity()

Creates another entity to be tested.

Return value

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

1 call to EntityResourceTestBase::createAnotherEntity()
EntityResourceTestBase::testPatch in core/modules/rest/tests/src/Functional/EntityResource/EntityResourceTestBase.php
Tests a PATCH request for an entity, plus edge cases to ensure good DX.
3 methods override EntityResourceTestBase::createAnotherEntity()
ItemResourceTestBase::createAnotherEntity in core/modules/aggregator/tests/src/Functional/Rest/ItemResourceTestBase.php
Creates another entity to be tested.
UserResourceTestBase::createAnotherEntity in core/modules/user/tests/src/Functional/Rest/UserResourceTestBase.php
Creates another entity to be tested.
WorkspaceResourceTestBase::createAnotherEntity in core/modules/workspaces/tests/src/Functional/EntityResource/WorkspaceResourceTestBase.php
Creates another entity to be tested.

File

core/modules/rest/tests/src/Functional/EntityResource/EntityResourceTestBase.php, line 259

Class

EntityResourceTestBase
Even though there is the generic EntityResource, it's necessary for every entity type to have its own test, because they each have different fields, validation constraints, et cetera. It's not because the generic case works, that every case…

Namespace

Drupal\Tests\rest\Functional\EntityResource

Code

protected function createAnotherEntity() {
  $entity = $this->entity
    ->createDuplicate();
  $label_key = $entity
    ->getEntityType()
    ->getKey('label');
  if ($label_key) {
    $entity
      ->set($label_key, $entity
      ->label() . '_dupe');
  }
  $entity
    ->save();
  return $entity;
}