You are here

public function InfoParserUnitTest::testCoreVersionRequirementInvalid in Drupal 9

Same name and namespace in other branches
  1. 8 core/tests/Drupal/Tests/Core/Extension/InfoParserUnitTest.php \Drupal\Tests\Core\Extension\InfoParserUnitTest::testCoreVersionRequirementInvalid()

Tests a invalid 'core_version_requirement'.

@covers ::parse

@dataProvider providerCoreVersionRequirementInvalid

File

core/tests/Drupal/Tests/Core/Extension/InfoParserUnitTest.php, line 413

Class

InfoParserUnitTest
Tests InfoParser class and exception.

Namespace

Drupal\Tests\Core\Extension

Code

public function testCoreVersionRequirementInvalid($test_case, $constraint) {
  $invalid_core_version_requirement = <<<INVALID_CORE_VERSION_REQUIREMENT
# info.yml for core_version_requirement validation.
name: Gracie Evaluator
description: 'Determines if Gracie is a "Good Dog". The answer is always "Yes".'
package: Core
type: module
version: VERSION
core_version_requirement: '{<span class="php-variable">$constraint</span>}'
dependencies:
  - goodness_api
INVALID_CORE_VERSION_REQUIREMENT;
  vfsStream::setup('modules');
  vfsStream::create([
    'fixtures' => [
      "invalid_core_version_requirement-{$test_case}.info.txt" => $invalid_core_version_requirement,
      "invalid_core_version_requirement-{$test_case}-duplicate.info.txt" => $invalid_core_version_requirement,
    ],
  ]);
  $exception_message = "The 'core_version_requirement' can not be used to specify compatibility for a specific version before 8.7.7 in vfs://modules/fixtures/invalid_core_version_requirement-{$test_case}";

  // Set the expected exception for the 2nd call to parse().
  $this
    ->expectException('\\Drupal\\Core\\Extension\\InfoParserException');
  $this
    ->expectExceptionMessage("{$exception_message}-duplicate.info.txt");
  try {
    $this->infoParser
      ->parse(vfsStream::url("modules/fixtures/invalid_core_version_requirement-{$test_case}.info.txt"));
  } catch (InfoParserException $exception) {
    $this
      ->assertSame("{$exception_message}.info.txt", $exception
      ->getMessage());
    $this->infoParser
      ->parse(vfsStream::url("modules/fixtures/invalid_core_version_requirement-{$test_case}-duplicate.info.txt"));
  }
}