diff --git a/core/tests/Drupal/Tests/Core/Extension/InfoParserUnitTest.php b/core/tests/Drupal/Tests/Core/Extension/InfoParserUnitTest.php index ee8a45e900..4c4f4dbdea 100644 --- a/core/tests/Drupal/Tests/Core/Extension/InfoParserUnitTest.php +++ b/core/tests/Drupal/Tests/Core/Extension/InfoParserUnitTest.php @@ -98,10 +98,68 @@ public function testInfoParserMissingKeys() { ]); $filename = vfsStream::url('modules/fixtures/missing_keys.info.txt'); $this->expectException('\Drupal\Core\Extension\InfoParserException'); - $this->expectExceptionMessage('Missing required keys (type, core, name) in vfs://modules/fixtures/missing_keys.info.txt'); + $this->expectExceptionMessage('Missing required keys (type, name) in vfs://modules/fixtures/missing_keys.info.txt'); $this->infoParser->parse($filename); } + /** + * Tests that missing 'core' and 'core_dependency' keys are detected. + * + * @covers ::parse + */ + public function testMissingCoreCoreDependency() { + $missing_keys = << [ + 'missing_keys.info.txt' => $missing_keys, + ], + ]); + $filename = vfsStream::url('modules/fixtures/missing_keys.info.txt'); + $this->expectException('\Drupal\Core\Extension\InfoParserException'); + $this->expectExceptionMessage("The 'core' or the 'core_dependency' key must be present in vfs://modules/fixtures/missing_keys.info.txt"); + $this->infoParser->parse($filename); + } + + /** + * Tests that 'core' and 'core_dependency' retain their values. + * + * @covers ::parse + */ + public function testCoreCoreDependency() { + $core_and_core_dependency = << [ + 'core_and_core_dependency.info.txt' => $core_and_core_dependency, + ], + ]); + $filename = vfsStream::url('modules/fixtures/core_and_core_dependency.info.txt'); + $info_values = $this->infoParser->parse($filename); + $this->assertSame($info_values['core'], '8.x'); + $this->assertSame($info_values['core_dependency'], '^8.8'); + } + /** * Tests that missing required key is detected. * @@ -131,6 +189,36 @@ public function testInfoParserMissingKey() { $this->infoParser->parse($filename); } + /** + * Tests that 'core_dependency' throws an exception if constraint is invalid. + * + * @covers ::parse + */ + public function testCoreDependencyInvalid() { + $core_dependency = << [ + 'core_dependency.info.txt' => $core_dependency, + ], + ]); + $filename = vfsStream::url('modules/fixtures/core_dependency.info.txt'); + $this->expectException('\Drupal\Core\Extension\InfoParserException'); + $this->expectExceptionMessage("The 'core_dependency' can not be used to specify compatibility specific version before 8.7.7 in vfs://modules/fixtures/core_dependency.info.txt"); + $this->infoParser->parse($filename); + } + /** * Tests common info file. * @@ -156,6 +244,7 @@ public function testInfoParserCommonInfo() { $info_values = $this->infoParser->parse(vfsStream::url('modules/fixtures/common_test.info.txt')); $this->assertEquals($info_values['simple_string'], 'A simple string', 'Simple string value was parsed correctly.'); $this->assertEquals($info_values['version'], \Drupal::VERSION, 'Constant value was parsed correctly.'); + $this->assertSame($info_values['core_dependency'], '8.x'); $this->assertEquals($info_values['double_colon'], 'dummyClassName::method', 'Value containing double-colon was parsed correctly.'); }