You are here

public function EntityApiTest::testUpdateWithId in Drupal 8

Same name and namespace in other branches
  1. 9 core/tests/Drupal/KernelTests/Core/Entity/EntityApiTest.php \Drupal\KernelTests\Core\Entity\EntityApiTest::testUpdateWithId()
  2. 10 core/tests/Drupal/KernelTests/Core/Entity/EntityApiTest.php \Drupal\KernelTests\Core\Entity\EntityApiTest::testUpdateWithId()

Tests that resaving an entity with a different entity ID throws an exception.

File

core/tests/Drupal/KernelTests/Core/Entity/EntityApiTest.php, line 265

Class

EntityApiTest
Tests basic CRUD functionality.

Namespace

Drupal\KernelTests\Core\Entity

Code

public function testUpdateWithId() {
  $storage = \Drupal::entityTypeManager()
    ->getStorage('entity_test_mulrev');

  // Create a new entity.

  /** @var \Drupal\entity_test\Entity\EntityTestMulRev $entity */
  $entity = $storage
    ->create([
    'name' => 'revision_test',
  ]);
  $entity
    ->save();
  $this
    ->expectException(EntityStorageException::class);
  $this
    ->expectExceptionMessage("Update existing 'entity_test_mulrev' entity while changing the ID is not supported.");
  $entity->id = 60;
  $entity
    ->save();
}