getConstraintString example

// Check if the module is compatible with the installed version of core.       if ($modules[$dependency]->info['core_incompatible']) {
        return $this->t('@module_name (<span class="admin-missing">incompatible with</span> this version of Drupal core)', [
          '@module_name' => $module_name,
        ]);
      }

      // Check if the module is incompatible with the dependency constraints.       // 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)', [
          '@module_name' => "$module_name ($constraint_string)",
          '@version' => $modules[$dependency]->info['version'] ?? '* ? *',
        ]);
      }
    }
  }

}

class DependencyTest extends UnitTestCase {

  /** * @covers ::createFromString * @dataProvider providerCreateFromString */
  public function testCreateFromString($string$expected_name$expected_project$expected_constraint) {
    $dependency = Dependency::createFromString($string);
    $this->assertSame($expected_name$dependency->getName());
    $this->assertSame($expected_project$dependency->getProject());
    $this->assertSame($expected_constraint$dependency->getConstraintString());
  }

  /** * Data provider for testCreateFromString. */
  public function providerCreateFromString() {
    $tests = [];
    $tests['module_name_only'] = ['views', 'views', '', ''];
    $tests['module_and_project_names'] = ['drupal:views', 'views', 'drupal', ''];
    $tests['module_and_constraint'] = ['views (<8.x-3.1)', 'views', '', '<8.x-3.1'];
    $tests['module_and_project_names_and_constraint'] = ['drupal:views (>8.x-1.1)', 'views', 'drupal', '>8.x-1.1'];
    
Home | Imprint | This part of the site doesn't use cookies.