function UpdatePostUpdateTest::setUp

Same name in other branches
  1. 9 core/modules/system/tests/src/Functional/UpdateSystem/UpdatePostUpdateTest.php \Drupal\Tests\system\Functional\UpdateSystem\UpdatePostUpdateTest::setUp()
  2. 10 core/modules/system/tests/src/Functional/UpdateSystem/UpdatePostUpdateTest.php \Drupal\Tests\system\Functional\UpdateSystem\UpdatePostUpdateTest::setUp()
  3. 11.x core/modules/system/tests/src/Functional/UpdateSystem/UpdatePostUpdateTest.php \Drupal\Tests\system\Functional\UpdateSystem\UpdatePostUpdateTest::setUp()

Overrides BrowserTestBase::setUp

File

core/modules/system/tests/src/Functional/UpdateSystem/UpdatePostUpdateTest.php, line 26

Class

UpdatePostUpdateTest
Tests hook_post_update().

Namespace

Drupal\Tests\system\Functional\UpdateSystem

Code

protected function setUp() {
    parent::setUp();
    $connection = Database::getConnection();
    // Set the schema version.
    $connection->merge('key_value')
        ->condition('collection', 'system.schema')
        ->condition('name', 'update_test_postupdate')
        ->fields([
        'collection' => 'system.schema',
        'name' => 'update_test_postupdate',
        'value' => 'i:8000;',
    ])
        ->execute();
    // Update core.extension.
    $extensions = $connection->select('config')
        ->fields('config', [
        'data',
    ])
        ->condition('collection', '')
        ->condition('name', 'core.extension')
        ->execute()
        ->fetchField();
    $extensions = unserialize($extensions);
    $extensions['module']['update_test_postupdate'] = 8000;
    $connection->update('config')
        ->fields([
        'data' => serialize($extensions),
    ])
        ->condition('collection', '')
        ->condition('name', 'core.extension')
        ->execute();
    // Mimic the behavior of ModuleInstaller::install() for removed post
    // updates. Don't include the actual post updates because we want them to
    // run.
    $key_value = \Drupal::service('keyvalue');
    $existing_updates = $key_value->get('post_update')
        ->get('existing_updates', []);
    $post_updates = [
        'update_test_postupdate_post_update_foo',
        'update_test_postupdate_post_update_bar',
        'update_test_postupdate_post_update_pub',
        'update_test_postupdate_post_update_baz',
    ];
    $key_value->get('post_update')
        ->set('existing_updates', array_merge($existing_updates, $post_updates));
}

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