function InstallTest::testUninstallPostUpdateFunctions

Same name in other branches
  1. 9 core/modules/system/tests/src/Functional/Module/InstallTest.php \Drupal\Tests\system\Functional\Module\InstallTest::testUninstallPostUpdateFunctions()
  2. 8.9.x core/modules/system/tests/src/Functional/Module/InstallTest.php \Drupal\Tests\system\Functional\Module\InstallTest::testUninstallPostUpdateFunctions()
  3. 11.x core/modules/system/tests/src/Kernel/Module/InstallTest.php \Drupal\Tests\system\Kernel\Module\InstallTest::testUninstallPostUpdateFunctions()

Ensures that post update functions are removed on uninstallation.

File

core/modules/system/tests/src/Kernel/Module/InstallTest.php, line 87

Class

InstallTest
Tests the installation of modules.

Namespace

Drupal\Tests\system\Kernel\Module

Code

public function testUninstallPostUpdateFunctions() : void {
    // First, to avoid false positives, ensure that the post_update function
    // exists while the module is still installed.
    $post_update_key_value = $this->container
        ->get('keyvalue')
        ->get('post_update');
    $existing_updates = $post_update_key_value->get('existing_updates', []);
    $this->assertContains('module_test_post_update_test', $existing_updates);
    // Uninstall the module.
    $this->moduleInstaller
        ->uninstall([
        'module_test',
    ]);
    // Ensure the post update function is no longer listed.
    $existing_updates = $post_update_key_value->get('existing_updates', []);
    $this->assertNotContains('module_test_post_update_test', $existing_updates);
}

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