You are here

public function InfoParserUnitTest::testLifecycleLink in Drupal 10

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

Tests an info file's lifecycle_link values.

@covers ::parse

@dataProvider providerLifecycleLink

File

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

Class

InfoParserUnitTest
Tests InfoParser class and exception.

Namespace

Drupal\Tests\Core\Extension

Code

public function testLifecycleLink($lifecycle, $lifecycle_link = NULL, $exception_message = NULL) {
  $info = <<<INFO
package: Core
core_version_requirement: '*'
version: VERSION
type: module
name: Module for That
lifecycle: {<span class="php-variable">$lifecycle</span>}
INFO;
  if ($lifecycle_link) {
    $info .= "\nlifecycle_link: {$lifecycle_link}\n";
  }
  vfsStream::setup('modules');

  // Use a random file name to bypass the static caching in
  // \Drupal\Core\Extension\InfoParser.
  $random = mb_strtolower($this
    ->randomMachineName());
  $filename = "lifecycle-{$random}.info.yml";
  vfsStream::create([
    'fixtures' => [
      $filename => $info,
    ],
  ]);
  $path = vfsStream::url("modules/fixtures/{$filename}");
  if ($exception_message) {
    $this
      ->expectException(InfoParserException::class);
    $this
      ->expectExceptionMessage(sprintf($exception_message, $path));
  }
  $info_values = $this->infoParser
    ->parse($path);
  $this
    ->assertSame($lifecycle, $info_values[ExtensionLifecycle::LIFECYCLE_IDENTIFIER]);
}