/**
     * Tests common info file.
     *
     * @covers ::parse
     */
    public function testInfoParserCommonInfo()
    {
        $common = <<<COMMONTEST
core: 8.x
name: common_test
type: module
description: 'testing info file parsing'
simple_string: 'A simple string'
version: "VERSION"
double_colon: dummyClassName::
COMMONTEST;
        vfsStream::setup('modules');
        vfsStream::create(['fixtures' => ['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::', 'Value containing double-colon was parsed correctly.');
    }
 /**
  * Tests the functionality of the infoParser object.
  */
 public function testInfoParser()
 {
     $info = $this->infoParser->parse('core/modules/system/tests/fixtures/does_not_exist.info.txt');
     $this->assertTrue(empty($info), 'Non existing info.yml returns empty array.');
     // Test that invalid YAML throws an exception and that message contains the
     // filename that caused it.
     $filename = 'core/modules/system/tests/fixtures/broken.info.txt';
     try {
         $this->infoParser->parse($filename);
         $this->fail('Expected InfoParserException not thrown when reading broken.info.txt');
     } catch (InfoParserException $e) {
         $this->assertTrue(strpos($e->getMessage(), $filename) !== FALSE, 'Exception message contains info.yml filename.');
     }
     // Tests that missing required keys are detected.
     $filename = 'core/modules/system/tests/fixtures/missing_keys.info.txt';
     try {
         $this->infoParser->parse($filename);
         $this->fail('Expected InfoParserException not thrown when reading missing_keys.info.txt');
     } catch (InfoParserException $e) {
         $expected_message = "Missing required keys (type, core, name) in {$filename}.";
         $this->assertEqual($e->getMessage(), $expected_message);
     }
     // Tests that a single missing required key is detected.
     $filename = 'core/modules/system/tests/fixtures/missing_key.info.txt';
     try {
         $this->infoParser->parse($filename);
         $this->fail('Expected InfoParserException not thrown when reading missing_key.info.txt');
     } catch (InfoParserException $e) {
         $expected_message = "Missing required key (type) in {$filename}.";
         $this->assertEqual($e->getMessage(), $expected_message);
     }
     $info_values = $this->infoParser->parse('core/modules/system/tests/fixtures/common_test.info.txt');
     $this->assertEqual($info_values['simple_string'], 'A simple string', 'Simple string value was parsed correctly.', 'System');
     $this->assertEqual($info_values['version'], \Drupal::VERSION, 'Constant value was parsed correctly.', 'System');
     $this->assertEqual($info_values['double_colon'], 'dummyClassName::', 'Value containing double-colon was parsed correctly.', 'System');
 }
示例#3
0
 /**
  * Tests rebuild the theme data with theme parents.
  */
 public function testRebuildThemeDataWithThemeParents()
 {
     $this->extensionDiscovery->expects($this->at(0))->method('scan')->with('theme')->will($this->returnValue(array('test_subtheme' => new Extension($this->root, 'theme', $this->root . '/core/modules/system/tests/themes/test_subtheme/test_subtheme.info.yml', 'test_subtheme.info.yml'), 'test_basetheme' => new Extension($this->root, 'theme', $this->root . '/core/modules/system/tests/themes/test_basetheme/test_basetheme.info.yml', 'test_basetheme.info.yml'))));
     $this->extensionDiscovery->expects($this->at(1))->method('scan')->with('theme_engine')->will($this->returnValue(array('twig' => new Extension($this->root, 'theme_engine', $this->root . '/core/themes/engines/twig/twig.info.yml', 'twig.engine'))));
     $this->infoParser->expects($this->at(0))->method('parse')->with($this->root . '/core/modules/system/tests/themes/test_subtheme/test_subtheme.info.yml')->will($this->returnCallback(function ($file) {
         $info_parser = new InfoParser();
         return $info_parser->parse($file);
     }));
     $this->infoParser->expects($this->at(1))->method('parse')->with($this->root . '/core/modules/system/tests/themes/test_basetheme/test_basetheme.info.yml')->will($this->returnCallback(function ($file) {
         $info_parser = new InfoParser();
         return $info_parser->parse($file);
     }));
     $this->moduleHandler->expects($this->once())->method('buildModuleDependencies')->will($this->returnArgument(0));
     $theme_data = $this->themeHandler->rebuildThemeData();
     $this->assertCount(2, $theme_data);
     $info_basetheme = $theme_data['test_basetheme'];
     $info_subtheme = $theme_data['test_subtheme'];
     // Ensure some basic properties.
     $this->assertInstanceOf('Drupal\\Core\\Extension\\Extension', $info_basetheme);
     $this->assertEquals('test_basetheme', $info_basetheme->getName());
     $this->assertInstanceOf('Drupal\\Core\\Extension\\Extension', $info_subtheme);
     $this->assertEquals('test_subtheme', $info_subtheme->getName());
     // Test the parent/child-theme properties.
     $info_subtheme->info['base theme'] = 'test_basetheme';
     $info_basetheme->sub_themes = array('test_subtheme');
     $this->assertEquals($this->root . '/core/themes/engines/twig/twig.engine', $info_basetheme->owner);
     $this->assertEquals('twig', $info_basetheme->prefix);
     $this->assertEquals($this->root . '/core/themes/engines/twig/twig.engine', $info_subtheme->owner);
     $this->assertEquals('twig', $info_subtheme->prefix);
 }