function UpdateScriptTest::testExtensionCompatibilityChange

Same name and namespace in other branches
  1. 8.9.x core/modules/system/tests/src/Functional/UpdateSystem/UpdateScriptTest.php \Drupal\Tests\system\Functional\UpdateSystem\UpdateScriptTest::testExtensionCompatibilityChange()
  2. 10 core/modules/system/tests/src/Functional/UpdateSystem/UpdateScriptTest.php \Drupal\Tests\system\Functional\UpdateSystem\UpdateScriptTest::testExtensionCompatibilityChange()
  3. 11.x 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 227

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, $expected_error) {
    $extension_type = $correct_info['type'];
    $this->drupalLogin($this->drupalCreateUser([
        'administer software updates',
        'administer site configuration',
        $extension_type === 'module' ? 'administer modules' : 'administer themes',
    ]));
    $extension_machine_name = "changing_extension";
    $extension_name = "{$extension_machine_name} name";
    $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_name}";
    $file_path = "{$folder_path}/{$extension_machine_name}.info.yml";
    mkdir($folder_path, 0777, TRUE);
    file_put_contents($file_path, Yaml::encode($base_info + $correct_info));
    $this->enableExtension($extension_type, $extension_machine_name, $extension_name);
    $this->assertInstalledExtensionConfig($extension_type, $extension_machine_name);
    // If there are no requirements warnings or errors, we expect to be able to
    // go through the update process uninterrupted.
    $this->assertUpdateWithNoError($test_error_text, $extension_type, $extension_machine_name);
    // Change the values in the info.yml and confirm updating is not possible.
    file_put_contents($file_path, Yaml::encode($base_info + $breaking_info));
    $this->assertErrorOnUpdate($test_error_text, $extension_type, $extension_machine_name);
    // Fix the values in the info.yml file and confirm updating is possible
    // again.
    file_put_contents($file_path, Yaml::encode($base_info + $correct_info));
    $this->assertUpdateWithNoError($test_error_text, $extension_type, $extension_machine_name);
}

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