public function InfoParserUnitTest::testLifecycleLink in Drupal 9
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\ExtensionCode
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]);
}