Skip to content
Snippets Groups Projects
Verified Commit a9b2d321 authored by Alex Pott's avatar Alex Pott
Browse files

Issue #3119761 by dww, aleevas, Hardik_Patel_12, quietone, tedbow,...

Issue #3119761 by dww, aleevas, Hardik_Patel_12, quietone, tedbow, _utsavsharma, smustgrave, xjm, longwave: Replace multiple test methods in InfoParserUnitTest with 1 testInfoException and a dataprovider

(cherry picked from commit 9f6b172c)
parent 545bd6a5
Branches
Tags
7 merge requests!8376Drupal views: adding more granularity to the ‘use ajax’ functionality,!8300Issue #3443586 View area displays even when parent view has no results.,!7567Issue #3153723 by quietone, Hardik_Patel_12: Change the scaffolding...,!7565Issue #3153723 by quietone, Hardik_Patel_12: Change the scaffolding...,!7509Change label "Block description" to "Block type",!7344Issue #3292350 by O'Briat, KlemenDEV, hswong3i, smustgrave, quietone: Update...,!6922Issue #3412959 by quietone, smustgrave, longwave: Fix 12 'un' words
Pipeline #111396 passed with warnings
Pipeline: drupal

#111451

    Pipeline: drupal

    #111442

      Pipeline: drupal

      #111436

        +6
        ......@@ -55,94 +55,101 @@ public function testInfoParserNonExisting() {
        /**
        * Tests if correct exception is thrown for a broken info file.
        *
        * @covers ::parse
        * @param string $yaml
        * The YAML to use to create the file to parse.
        * @param string $expected_exception_message
        * The expected exception message.
        *
        * @dataProvider providerInfoException
        */
        public function testInfoParserBroken() {
        $broken_info = <<<BROKEN_INFO
        # info.yml for testing broken YAML parsing exception handling.
        name: File
        type: module
        description: 'Defines a file field type.'
        package: Core
        version: VERSION
        core_version_requirement: '*'
        dependencies::;;
        - field
        BROKEN_INFO;
        public function testInfoException($yaml, $expected_exception_message): void {
        vfsStream::setup('modules');
        vfsStream::create([
        'fixtures' => [
        'broken.info.txt' => $broken_info,
        "broken.info.txt" => $yaml,
        "broken-duplicate.info.txt" => $yaml,
        ],
        ]);
        $filename = vfsStream::url('modules/fixtures/broken.info.txt');
        $this->expectException('\Drupal\Core\Extension\InfoParserException');
        $this->expectExceptionMessage('broken.info.txt');
        $this->infoParser->parse($filename);
        try {
        $this->infoParser->parse(vfsStream::url("modules/fixtures/broken.info.txt"));
        }
        catch (InfoParserException $exception) {
        $this->assertSame("$expected_exception_message vfs://modules/fixtures/broken.info.txt", $exception->getMessage());
        }
        $this->expectException(InfoParserException::class);
        $this->expectExceptionMessage("$expected_exception_message vfs://modules/fixtures/broken-duplicate.info.txt");
        $this->infoParser->parse(vfsStream::url("modules/fixtures/broken-duplicate.info.txt"));
        }
        /**
        * Tests that missing required keys are detected.
        *
        * @covers ::parse
        * Data provider for testInfoException().
        */
        public function testInfoParserMissingKeys() {
        $missing_keys = <<<MISSING_KEYS
        # info.yml for testing missing name, description, and type keys.
        public static function providerInfoException(): array {
        return [
        'missing required key, type' => [
        <<<YML
        name: File
        description: Missing key
        package: Core
        version: VERSION
        dependencies:
        - field
        MISSING_KEYS;
        vfsStream::setup('modules');
        vfsStream::create([
        'fixtures' => [
        'missing_keys.info.txt' => $missing_keys,
        YML,
        "Missing required keys (type) in",
        ],
        ]);
        $filename = vfsStream::url('modules/fixtures/missing_keys.info.txt');
        $this->expectException('\Drupal\Core\Extension\InfoParserException');
        $this->expectExceptionMessage('Missing required keys (type, name) in vfs://modules/fixtures/missing_keys.info.txt');
        $this->infoParser->parse($filename);
        'missing core_version_requirement' => [
        <<<YML
        version: VERSION
        type: module
        name: Skynet
        dependencies:
        - self_awareness
        YML,
        "The 'core_version_requirement' key must be present in",
        ],
        'missing two required keys' => [
        <<<YML
        package: Core
        version: VERSION
        dependencies:
        - field
        YML,
        'Missing required keys (type, name) in',
        ],
        ];
        }
        /**
        * Tests that a missing 'core_version_requirement' key is detected.
        * Tests that the correct exception is thrown for a broken info file.
        *
        * @covers ::parse
        */
        public function testMissingCoreVersionRequirement() {
        $missing_core_version_requirement = <<<MISSING_CORE_VERSION_REQUIREMENT
        # info.yml for testing core_version_requirement.
        version: VERSION
        public function testInfoParserBroken() {
        $broken_info = <<<BROKEN_INFO
        # info.yml for testing broken YAML parsing exception handling.
        name: File
        type: module
        name: Skynet
        dependencies:
        - self_awareness
        MISSING_CORE_VERSION_REQUIREMENT;
        description: 'Defines a file field type.'
        package: Core
        version: VERSION
        core_version_requirement: '*'
        dependencies::;;
        - field
        BROKEN_INFO;
        vfsStream::setup('modules');
        vfsStream::create([
        'fixtures' => [
        'missing_core_version_requirement.info.txt' => $missing_core_version_requirement,
        'missing_core_version_requirement-duplicate.info.txt' => $missing_core_version_requirement,
        'broken.info.txt' => $broken_info,
        ],
        ]);
        $exception_message = "The 'core_version_requirement' key must be present in vfs://modules/fixtures/missing_core_version_requirement";
        // Set the expected exception for the 2nd call to parse().
        $filename = vfsStream::url('modules/fixtures/broken.info.txt');
        $this->expectException('\Drupal\Core\Extension\InfoParserException');
        $this->expectExceptionMessage("$exception_message-duplicate.info.txt");
        try {
        $this->infoParser->parse(vfsStream::url('modules/fixtures/missing_core_version_requirement.info.txt'));
        }
        catch (InfoParserException $exception) {
        $this->assertSame("$exception_message.info.txt", $exception->getMessage());
        $this->infoParser->parse(vfsStream::url('modules/fixtures/missing_core_version_requirement-duplicate.info.txt'));
        }
        $this->expectExceptionMessage('Unable to parse vfs://modules/fixtures/broken.info.txt');
        $this->infoParser->parse($filename);
        }
        /**
        ......@@ -169,43 +176,6 @@ public function testTestingPackageMissingCoreVersionRequirement() {
        $this->assertSame($info_values['core_version_requirement'], \Drupal::VERSION);
        }
        /**
        * Tests that missing required key is detected.
        *
        * @covers ::parse
        */
        public function testInfoParserMissingKey() {
        $missing_key = <<<MISSING_KEY
        # info.yml for testing missing type key.
        name: File
        description: 'Defines a file field type.'
        package: Core
        version: VERSION
        dependencies:
        - field
        MISSING_KEY;
        vfsStream::setup('modules');
        vfsStream::create([
        'fixtures' => [
        'missing_key.info.txt' => $missing_key,
        'missing_key-duplicate.info.txt' => $missing_key,
        ],
        ]);
        // Set the expected exception for the 2nd call to parse().
        $this->expectException(InfoParserException::class);
        $this->expectExceptionMessage('Missing required keys (type) in vfs://modules/fixtures/missing_key-duplicate.info.txt');
        try {
        $this->infoParser->parse(vfsStream::url('modules/fixtures/missing_key.info.txt'));
        }
        catch (InfoParserException $exception) {
        $this->assertSame('Missing required keys (type) in vfs://modules/fixtures/missing_key.info.txt', $exception->getMessage());
        $this->infoParser->parse(vfsStream::url('modules/fixtures/missing_key-duplicate.info.txt'));
        }
        }
        /**
        * Tests common info file.
        *
        ......
        0% Loading or .
        You are about to add 0 people to the discussion. Proceed with caution.
        Please register or to comment