function EntityUpdateTest::testEntityUpdate

Same name in other branches
  1. 9 core/modules/editor/tests/src/Kernel/EntityUpdateTest.php \Drupal\Tests\editor\Kernel\EntityUpdateTest::testEntityUpdate()
  2. 10 core/modules/editor/tests/src/Kernel/EntityUpdateTest.php \Drupal\Tests\editor\Kernel\EntityUpdateTest::testEntityUpdate()

Tests updating an existing entity.

See also

editor_test_entity_update()

File

core/modules/editor/tests/src/Kernel/EntityUpdateTest.php, line 47

Class

EntityUpdateTest
Tests updating an entity.

Namespace

Drupal\Tests\editor\Kernel

Code

public function testEntityUpdate() : void {
    // Create a node.
    $node = Node::create([
        'type' => 'page',
        'title' => 'test',
    ]);
    $node->save();
    // Update the node.
    // What happens is the following:
    // 1. \Drupal\Core\Entity\EntityStorageBase::doPostSave() gets called.
    // 2. editor_test_entity_update() gets called.
    // 3. A resave of the updated entity gets triggered (second save call).
    // 4. \Drupal\Core\Entity\EntityStorageBase::doPostSave() gets called.
    // 5. editor_test_entity_update() gets called.
    // 6. editor_entity_update() gets called (caused by the second save call).
    // 7. editor_entity_update() gets called (caused by the first save call).
    $node->title->value = 'test updated';
    $node->save();
}

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