Commit 9ab4ed2b authored by catch's avatar catch
Browse files

Issue #3239287 by alexpott, longwave: Fix...

Issue #3239287 by alexpott, longwave: Fix \Drupal\Core\Extension\ModuleDependencyMessageTrait to not cause deprecations in PHP 8.1

(cherry picked from commit 205729d9)
parent fcc9a6b1
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -39,7 +39,7 @@ public function checkDependencyMessage(array $modules, $dependency, Dependency $
      }

      // Check if the module is incompatible with the dependency constraints.
      $version = str_replace(\Drupal::CORE_COMPATIBILITY . '-', '', $modules[$dependency]->info['version']);
      $version = str_replace(\Drupal::CORE_COMPATIBILITY . '-', '', $modules[$dependency]->info['version'] ?? '');
      if (!$dependency_object->isCompatible($version)) {
        $constraint_string = $dependency_object->getConstraintString();
        return $this->t('@module_name (<span class="admin-missing">incompatible with</span> version @version)', [
+1 −1
Original line number Diff line number Diff line
@@ -953,7 +953,7 @@ function system_requirements($phase) {
        // Check for an incompatible version.
        $required_file = $files[$required_module];
        $required_name = $required_file->info['name'];
        $version = str_replace(\Drupal::CORE_COMPATIBILITY . '-', '', $required_file->info['version']);
        $version = str_replace(\Drupal::CORE_COMPATIBILITY . '-', '', $required_file->info['version'] ?? '');
        if (!$requirement->isCompatible($version)) {
          $requirements["$extension_name-$required_module"] = [
            'title' => t('Unresolved dependency'),
+43 −0
Original line number Diff line number Diff line
@@ -2,6 +2,7 @@

namespace Drupal\Tests\system\Functional\Module;

use Drupal\Component\Serialization\Yaml;
use Drupal\Component\Utility\Unicode;

/**
@@ -96,6 +97,48 @@ public function testIncompatibleCoreVersionDependency() {
    $this->assertSession()->fieldDisabled('modules[system_incompatible_core_version_dependencies_test][enable]');
  }

  /**
   * Tests visiting admin/modules when a module outside of core has no version.
   */
  public function testNoVersionInfo() {
    // Create a module for testing. We set core_version_requirement to '*' for
    // the test so that it does not need to be updated between major versions.
    $info = [
      'type' => 'module',
      'core_version_requirement' => '*',
      'name' => 'System no module version dependency test',
    ];
    $path = $this->siteDirectory . '/modules/system_no_module_version_dependency_test';
    mkdir($path, 0777, TRUE);
    file_put_contents("$path/system_no_module_version_dependency_test.info.yml", Yaml::encode($info));

    $info = [
      'type' => 'module',
      'core_version_requirement' => '*',
      'name' => 'System no module version test',
      'dependencies' => ['system_no_module_version_dependency_test'],
    ];
    $path = $this->siteDirectory . '/modules/system_no_module_version_test';
    mkdir($path, 0777, TRUE);
    file_put_contents("$path/system_no_module_version_test.info.yml", Yaml::encode($info));

    $this->drupalGet('admin/modules');
    $this->assertSession()->pageTextContains('System no module version dependency test');
    $this->assertSession()->pageTextContains('System no module version test');

    // Ensure the modules can actually be installed.
    $edit['modules[system_no_module_version_test][enable]'] = 'system_no_module_version_test';
    $edit['modules[system_no_module_version_dependency_test][enable]'] = 'system_no_module_version_dependency_test';
    $this->drupalGet('admin/modules');
    $this->submitForm($edit, 'Install');
    $this->assertSession()->pageTextContains('2 modules have been enabled: System no module version dependency test, System no module version test.');

    // Ensure status report is working.
    $this->drupalLogin($this->createUser(['administer site configuration']));
    $this->drupalGet('admin/reports/status');
    $this->assertSession()->statusCodeEquals(200);
  }

  /**
   * Tests failing PHP version requirements.
   */