infoParser = new InfoParser(); } /** * Tests the functionality of the infoParser object. * * @covers ::parse */ public function testInfoParserNonExisting() { vfsStream::setup('modules'); $info = $this->infoParser->parse(vfsStream::url('modules') . '/does_not_exist.info.txt'); $this->assertTrue(empty($info), 'Non existing info.yml returns empty array.'); } /** * Test if correct exception is thrown for a broken info file. * * @covers ::parse */ public function testInfoParserBroken() { $broken_info = << [ 'broken.info.txt' => $broken_info, ], ]); $filename = vfsStream::url('modules/fixtures/broken.info.txt'); $this->setExpectedException('\Drupal\Core\Extension\InfoParserException', 'broken.info.txt'); $this->infoParser->parse($filename); } /** * Tests that missing required keys are detected. * * @covers ::parse */ public function testInfoParserMissingKeys() { $missing_keys = << [ 'missing_keys.info.txt' => $missing_keys, ], ]); $filename = vfsStream::url('modules/fixtures/missing_keys.info.txt'); $this->setExpectedException('\Drupal\Core\Extension\InfoParserException', 'Missing required keys (type, core, name) in vfs://modules/fixtures/missing_keys.info.txt'); $this->infoParser->parse($filename); } /** * Tests that missing required key is detected. * * @covers ::parse */ public function testInfoParserMissingKey() { $missing_key = << [ 'missing_key.info.txt' => $missing_key, ], ]); $filename = vfsStream::url('modules/fixtures/missing_key.info.txt'); $this->setExpectedException('\Drupal\Core\Extension\InfoParserException', 'Missing required keys (type) in vfs://modules/fixtures/missing_key.info.txt'); $this->infoParser->parse($filename); } /** * Tests common info file. * * @covers ::parse */ public function testInfoParserCommonInfo() { $common = << [ 'common_test.info.txt' => $common, ], ]); $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->assertEquals($info_values['double_colon'], 'dummyClassName::method', 'Value containing double-colon was parsed correctly.'); } }