function InfoParserUnitTest::testInvalidCore

Same name in other branches
  1. 9 core/tests/Drupal/Tests/Core/Extension/InfoParserUnitTest.php \Drupal\Tests\Core\Extension\InfoParserUnitTest::testInvalidCore()

Tests a invalid 'core' key.

@covers ::parse

File

core/tests/Drupal/Tests/Core/Extension/InfoParserUnitTest.php, line 241

Class

InfoParserUnitTest
Tests InfoParser class and exception.

Namespace

Drupal\Tests\Core\Extension

Code

public function testInvalidCore() {
    $invalid_core = <<<INVALID_CORE
# info.yml for testing invalid core key.
package: Core
core: ^8
version: VERSION
type: module
name: Llama or Alpaca
description: Tells whether an image is of a Llama or Alpaca
dependencies:
  - llama_detector
  - alpaca_detector
INVALID_CORE;
    vfsStream::setup('modules');
    vfsStream::create([
        'fixtures' => [
            'invalid_core.info.txt' => $invalid_core,
            'invalid_core-duplicate.info.txt' => $invalid_core,
        ],
    ]);
    $exception_message = "Invalid 'core' value \"^8\" in vfs://modules/fixtures/invalid_core";
    // Set the expected exception for the 2nd call to parse().
    $this->expectException('\\Drupal\\Core\\Extension\\InfoParserException');
    $this->expectExceptionMessage("{$exception_message}-duplicate.info.txt");
    try {
        $this->infoParser
            ->parse(vfsStream::url('modules/fixtures/invalid_core.info.txt'));
    } catch (InfoParserException $exception) {
        $this->assertSame("{$exception_message}.info.txt", $exception->getMessage());
        $this->infoParser
            ->parse(vfsStream::url('modules/fixtures/invalid_core-duplicate.info.txt'));
    }
}

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