function InfoParserUnitTest::testLifecycleLink

Same name and namespace in other branches
  1. 10 core/tests/Drupal/Tests/Core/Extension/InfoParserUnitTest.php \Drupal\Tests\Core\Extension\InfoParserUnitTest::testLifecycleLink()
  2. 11.x 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 811

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: 8.x
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]);
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.