Verified Commit d9ef1091 authored by Lee Rowlands's avatar Lee Rowlands
Browse files

Issue #3086845 by jonathan1055, smustgrave: Module constraint checks fail...

Issue #3086845 by jonathan1055, smustgrave: Module constraint checks fail incorrectly due to str_replace

(cherry picked from commit 1b4abdb0)
parent 379c2266
Loading
Loading
Loading
Loading
+2 −1
Original line number Diff line number Diff line
@@ -39,7 +39,8 @@ 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'] ?? '');
      // Remove CORE_COMPATIBILITY- only from the start of the string.
      $version = preg_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)', [
+2 −1
Original line number Diff line number Diff line
@@ -1058,7 +1058,8 @@ 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'] ?? '');
        // Remove CORE_COMPATIBILITY- only from the start of the string.
        $version = preg_replace('/^(' . \Drupal::CORE_COMPATIBILITY . '\-)/', '', $required_file->info['version'] ?? '');
        if (!$requirement->isCompatible($version)) {
          $requirements["$extension_name-$required_module"] = [
            'title' => t('Unresolved dependency'),
+5 −0
Original line number Diff line number Diff line
name: 'Dependency version test'
type: module
description: 'Support module for version comparison checks.'
package: Testing
version: VERSION
+25 −0
Original line number Diff line number Diff line
<?php

/**
 * @file
 * Module for testing the dependency version comparisons.
 */

use Drupal\Core\Extension\Extension;

/**
 * Implements hook_system_info_alter().
 */
function dependency_version_test_system_info_alter(&$info, Extension $file, $type) {
  // Simulate that the core version for Views module contains the string '8.x'.
  if ($file->getName() == 'views') {
    $info['version'] = '9.8.x-dev';
  }

  // Make the test_module require Views 9.2, which should be compatible with
  // core version 9.8.x-dev from above.
  if ($file->getName() == 'test_module') {
    $info['dependencies'] = ['drupal:views (>=9.2)'];
  }

}
+15 −0
Original line number Diff line number Diff line
@@ -191,6 +191,21 @@ public function testCoreCompatibility() {
    $this->assertModules(['common_test', 'system_core_semver_test'], TRUE);
  }

  /**
   * Tests the dependency checks when core version contains '8.x' within it.
   */
  public function testCoreVersionContains8X() {
    // Enable the helper module that alters the version and dependencies.
    \Drupal::service('module_installer')->install(['dependency_version_test']);

    // Check that the above module installed OK.
    $this->drupalGet('admin/modules');
    $this->assertModules(['dependency_version_test'], TRUE);

    // Check that test_module dependencies are met and the box is not greyed.
    $this->assertSession()->fieldEnabled('modules[test_module][enable]');
  }

  /**
   * Tests enabling a module that depends on a module which fails hook_requirements().
   */