function EntityResourceTestBase::createAnotherEntity

Same name in other branches
  1. 8.9.x core/modules/rest/tests/src/Functional/EntityResource/EntityResourceTestBase.php \Drupal\Tests\rest\Functional\EntityResource\EntityResourceTestBase::createAnotherEntity()
  2. 10 core/modules/rest/tests/src/Functional/EntityResource/EntityResourceTestBase.php \Drupal\Tests\rest\Functional\EntityResource\EntityResourceTestBase::createAnotherEntity()
  3. 11.x 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 258

Class

EntityResourceTestBase
Defines a base class for testing all entity resources.

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;
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.