function UpdateScriptTest::testExtensionCompatibilityChange

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

Tests that extension compatibility changes are handled correctly.

@dataProvider providerExtensionCompatibilityChange

Parameters

array $correct_info: The initial values for info.yml fail. These should compatible with core.

array $breaking_info: The values to the info.yml that are not compatible with core.

string $expected_error: The expected error.

File

core/modules/system/tests/src/Functional/UpdateSystem/UpdateScriptTest.php, line 234

Class

UpdateScriptTest
Tests the update script access and functionality.

Namespace

Drupal\Tests\system\Functional\UpdateSystem

Code

public function testExtensionCompatibilityChange(array $correct_info, array $breaking_info, string $expected_error) : void {
    $extension_type = $correct_info['type'];
    $this->drupalLogin($this->drupalCreateUser([
        'administer software updates',
        'administer site configuration',
        $extension_type === 'module' ? 'administer modules' : 'administer themes',
    ]));
    $extension_machine_names = [
        'changing_extension',
    ];
    $extension_name = "{$extension_machine_names[0]} name";
    $test_error_urls = [
        'https://www.drupal.org/docs/updating-drupal/troubleshooting-database-updates',
    ];
    $test_error_text = "Incompatible {$extension_type} " . $expected_error . $extension_name . static::HANDBOOK_MESSAGE;
    $base_info = [
        'name' => $extension_name,
    ];
    if ($extension_type === 'theme') {
        $base_info['base theme'] = FALSE;
    }
    $folder_path = \Drupal::getContainer()->getParameter('site.path') . "/{$extension_type}s/{$extension_machine_names[0]}";
    $file_path = "{$folder_path}/{$extension_machine_names[0]}.info.yml";
    mkdir($folder_path, 0777, TRUE);
    $this->writeInfoFile($file_path, $base_info + $correct_info);
    $this->enableExtensions($extension_type, $extension_machine_names, [
        $extension_name,
    ]);
    $this->assertInstalledExtensionsConfig($extension_type, $extension_machine_names);
    // If there are no requirements warnings or errors, we expect to be able to
    // go through the update process uninterrupted.
    $this->drupalGet($this->statusReportUrl);
    $this->assertUpdateWithNoErrors([
        $test_error_text,
    ], $extension_type, $extension_machine_names);
    // Change the values in the info.yml and confirm updating is not possible.
    $this->writeInfoFile($file_path, $base_info + $breaking_info);
    $this->drupalGet($this->statusReportUrl);
    $this->assertErrorOnUpdates([
        $test_error_text,
    ], $extension_type, $extension_machine_names, $test_error_urls);
    // Fix the values in the info.yml file and confirm updating is possible
    // again.
    $this->writeInfoFile($file_path, $base_info + $correct_info);
    $this->drupalGet($this->statusReportUrl);
    $this->assertUpdateWithNoErrors([
        $test_error_text,
    ], $extension_type, $extension_machine_names);
}

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