class EntityUpdateTest
Same name and namespace in other branches
- 11.x core/modules/editor/tests/src/Kernel/EntityUpdateTest.php \Drupal\Tests\editor\Kernel\EntityUpdateTest
Tests updating an entity.
@group editor
Hierarchy
- class \Drupal\KernelTests\KernelTestBase extends \Drupal\Core\DependencyInjection\ServiceProviderInterface uses \Drupal\KernelTests\AssertLegacyTrait, \Drupal\KernelTests\AssertContentTrait, \Drupal\Tests\RandomGeneratorTrait, \Drupal\Tests\ConfigTestTrait, \Drupal\Tests\ExtensionListTestTrait, \Drupal\Tests\TestRequirementsTrait, \Drupal\Tests\Traits\PhpUnitWarnings, \Drupal\Tests\PhpUnitCompatibilityTrait, \Symfony\Bridge\PhpUnit\ExpectDeprecationTrait implements \PHPUnit\Framework\TestCase
- class \Drupal\KernelTests\Core\Entity\EntityKernelTestBase uses \Drupal\Tests\user\Traits\UserCreationTrait implements \Drupal\KernelTests\KernelTestBase
- class \Drupal\Tests\editor\Kernel\EntityUpdateTest implements \Drupal\KernelTests\Core\Entity\EntityKernelTestBase
- class \Drupal\KernelTests\Core\Entity\EntityKernelTestBase uses \Drupal\Tests\user\Traits\UserCreationTrait implements \Drupal\KernelTests\KernelTestBase
Expanded class hierarchy of EntityUpdateTest
File
-
core/
modules/ editor/ tests/ src/ Kernel/ EntityUpdateTest.php, line 14
Namespace
Drupal\Tests\editor\KernelView source
class EntityUpdateTest extends EntityKernelTestBase {
/**
* Modules to enable.
*
* @var array
*/
protected static $modules = [
'editor',
'editor_test',
'node',
];
/**
* {@inheritdoc}
*/
protected function setUp() : void {
parent::setUp();
$this->installSchema('node', [
'node_access',
]);
$this->installConfig([
'node',
]);
// Create a node type for testing.
$type = NodeType::create([
'type' => 'page',
'name' => 'page',
]);
$type->save();
// Set editor_test module weight to be lower than editor module's weight so
// that editor_test_entity_update() is called before editor_entity_update().
$extension_config = \Drupal::configFactory()->get('core.extension');
$editor_module_weight = $extension_config->get('module.editor');
module_set_weight('editor_test', $editor_module_weight - 1);
}
/**
* Tests updating an existing entity.
*
* @see editor_test_entity_update()
*/
public function testEntityUpdate() {
// 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.