You are here

public function UpdateScriptTest::testMissingExtension in Drupal 10

Same name and namespace in other branches
  1. 8 core/modules/system/tests/src/Functional/UpdateSystem/UpdateScriptTest.php \Drupal\Tests\system\Functional\UpdateSystem\UpdateScriptTest::testMissingExtension()
  2. 9 core/modules/system/tests/src/Functional/UpdateSystem/UpdateScriptTest.php \Drupal\Tests\system\Functional\UpdateSystem\UpdateScriptTest::testMissingExtension()

Tests that a missing extension prevents updates.

@dataProvider providerMissingExtension

Parameters

string $extension_type: The extension type, either 'module' or 'theme'.

File

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

Class

UpdateScriptTest
Tests the update script access and functionality.

Namespace

Drupal\Tests\system\Functional\UpdateSystem

Code

public function testMissingExtension($extension_type) {
  $this
    ->drupalLogin($this
    ->drupalCreateUser([
    'administer software updates',
    'administer site configuration',
    $extension_type === 'module' ? 'administer modules' : 'administer themes',
  ]));
  $extension_machine_name = "disappearing_{$extension_type}";
  $extension_name = 'The magically disappearing extension';
  $test_error_text = "Missing or invalid {$extension_type} " . "The following {$extension_type} is marked as installed in the core.extension configuration, but it is missing:" . $extension_machine_name . static::HANDBOOK_MESSAGE;
  $extension_info = [
    'name' => $extension_name,
    'type' => $extension_type,
    'core_version_requirement' => '^8 || ^9 || ^10',
  ];
  if ($extension_type === 'theme') {
    $extension_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($extension_info));
  $this
    ->enableExtension($extension_type, $extension_machine_name, $extension_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);

  // Delete the info.yml and confirm updates are prevented.
  unlink($file_path);
  $this
    ->assertErrorOnUpdate($test_error_text, $extension_type, $extension_machine_name);

  // Add the info.yml file back and confirm we are able to go through the
  // update process uninterrupted.
  file_put_contents($file_path, Yaml::encode($extension_info));
  $this
    ->assertUpdateWithNoError($test_error_text, $extension_type, $extension_machine_name);
}