function ConfigEntityUpdaterTest::testUpdateDefaultCallback
Same name in other branches
- 9 core/tests/Drupal/KernelTests/Core/Config/Entity/ConfigEntityUpdaterTest.php \Drupal\KernelTests\Core\Config\Entity\ConfigEntityUpdaterTest::testUpdateDefaultCallback()
- 8.9.x core/tests/Drupal/KernelTests/Core/Config/Entity/ConfigEntityUpdaterTest.php \Drupal\KernelTests\Core\Config\Entity\ConfigEntityUpdaterTest::testUpdateDefaultCallback()
- 10 core/tests/Drupal/KernelTests/Core/Config/Entity/ConfigEntityUpdaterTest.php \Drupal\KernelTests\Core\Config\Entity\ConfigEntityUpdaterTest::testUpdateDefaultCallback()
@covers ::update
File
-
core/
tests/ Drupal/ KernelTests/ Core/ Config/ Entity/ ConfigEntityUpdaterTest.php, line 80
Class
Namespace
Drupal\KernelTests\Core\Config\EntityCode
public function testUpdateDefaultCallback() : void {
// Create some entities to update.
$storage = $this->container
->get('entity_type.manager')
->getStorage('config_test');
for ($i = 0; $i < 15; $i++) {
$entity_id = 'config_test_' . $i;
$storage->create([
'id' => $entity_id,
'label' => $entity_id,
])
->save();
}
// Set up the updater.
$sandbox = [];
$settings = Settings::getInstance() ? Settings::getAll() : [];
$settings['entity_update_batch_size'] = 9;
new Settings($settings);
$updater = $this->container
->get('class_resolver')
->getInstanceFromDefinition(ConfigEntityUpdater::class);
// Cause a dependency to be added during an update.
\Drupal::state()->set('config_test_new_dependency', 'system');
// This should run against the first 10 entities.
$updater->update($sandbox, 'config_test');
$entities = $storage->loadMultiple();
$this->assertEquals([
'system',
], $entities['config_test_7']->getDependencies()['module']);
$this->assertEquals([
'system',
], $entities['config_test_8']->getDependencies()['module']);
$this->assertEquals([], $entities['config_test_9']->getDependencies());
$this->assertEquals([], $entities['config_test_14']->getDependencies());
$this->assertEquals(15, $sandbox['config_entity_updater']['count']);
$this->assertCount(6, $sandbox['config_entity_updater']['entities']);
$this->assertEquals(9 / 15, $sandbox['#finished']);
// Update the rest.
$updater->update($sandbox, 'config_test');
$entities = $storage->loadMultiple();
$this->assertEquals([
'system',
], $entities['config_test_9']->getDependencies()['module']);
$this->assertEquals([
'system',
], $entities['config_test_14']->getDependencies()['module']);
$this->assertEquals(1, $sandbox['#finished']);
$this->assertCount(0, $sandbox['config_entity_updater']['entities']);
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.