ConfigTest.php

Same filename in this branch
  1. 9 core/modules/migrate_drupal/tests/src/Kernel/Plugin/migrate/source/d8/ConfigTest.php
  2. 9 core/modules/config/tests/config_test/src/Entity/ConfigTest.php
  3. 9 core/modules/migrate/tests/src/Unit/destination/ConfigTest.php
  4. 9 core/modules/system/tests/src/Functional/File/ConfigTest.php
  5. 9 core/tests/Drupal/Tests/Composer/Plugin/ProjectMessage/ConfigTest.php
  6. 9 core/tests/Drupal/Tests/Core/Config/ConfigTest.php
Same filename in other branches
  1. 8.9.x core/modules/migrate_drupal/tests/src/Kernel/Plugin/migrate/source/d8/ConfigTest.php
  2. 8.9.x core/modules/config/tests/config_test/src/Entity/ConfigTest.php
  3. 8.9.x core/modules/migrate/tests/src/Unit/destination/ConfigTest.php
  4. 8.9.x core/modules/system/tests/src/Functional/File/ConfigTest.php
  5. 8.9.x core/tests/Drupal/Tests/Composer/Plugin/ProjectMessage/ConfigTest.php
  6. 8.9.x core/tests/Drupal/Tests/Composer/Plugin/VendorHardening/ConfigTest.php
  7. 8.9.x core/tests/Drupal/Tests/Core/Config/ConfigTest.php
  8. 10 core/modules/migrate_drupal/tests/src/Kernel/Plugin/migrate/source/d8/ConfigTest.php
  9. 10 core/modules/config/tests/config_test/src/Entity/ConfigTest.php
  10. 10 core/modules/migrate/tests/src/Unit/destination/ConfigTest.php
  11. 10 core/modules/system/tests/src/Functional/File/ConfigTest.php
  12. 10 core/tests/Drupal/Tests/Composer/Plugin/ProjectMessage/ConfigTest.php
  13. 10 core/tests/Drupal/Tests/Composer/Plugin/VendorHardening/ConfigTest.php
  14. 10 core/tests/Drupal/Tests/Core/Config/ConfigTest.php
  15. 11.x core/modules/migrate_drupal/tests/src/Kernel/Plugin/migrate/source/d8/ConfigTest.php
  16. 11.x core/modules/config/tests/config_test/src/Entity/ConfigTest.php
  17. 11.x core/modules/migrate/tests/src/Unit/destination/ConfigTest.php
  18. 11.x core/modules/system/tests/src/Functional/File/ConfigTest.php
  19. 11.x core/tests/Drupal/Tests/Composer/Plugin/ProjectMessage/ConfigTest.php
  20. 11.x core/tests/Drupal/Tests/Composer/Plugin/VendorHardening/ConfigTest.php
  21. 11.x core/tests/Drupal/Tests/Core/Config/ConfigTest.php

Namespace

Drupal\Tests\Composer\Plugin\VendorHardening

File

core/tests/Drupal/Tests/Composer/Plugin/VendorHardening/ConfigTest.php

View source
<?php

namespace Drupal\Tests\Composer\Plugin\VendorHardening;

use Composer\Package\RootPackageInterface;
use Drupal\Composer\Plugin\VendorHardening\Config;
use Drupal\Tests\Traits\PhpUnitWarnings;
use PHPUnit\Framework\TestCase;

/**
 * @coversDefaultClass Drupal\Composer\Plugin\VendorHardening\Config
 * @group VendorHardening
 */
class ConfigTest extends TestCase {
    use PhpUnitWarnings;
    
    /**
     * @covers ::getPathsForPackage
     */
    public function testGetPathsForPackageMixedCase() {
        $config = $this->getMockBuilder(Config::class)
            ->onlyMethods([
            'getAllCleanupPaths',
        ])
            ->disableOriginalConstructor()
            ->getMock();
        $config->expects($this->once())
            ->method('getAllCleanupPaths')
            ->willReturn([
            'package' => [
                'path',
            ],
        ]);
        $this->assertSame([
            'path',
        ], $config->getPathsForPackage('pACKage'));
    }
    
    /**
     * @covers ::getAllCleanupPaths
     */
    public function testNoRootMergeConfig() {
        // Root package has no extra field.
        $root = $this->getMockBuilder(RootPackageInterface::class)
            ->onlyMethods([
            'getExtra',
        ])
            ->getMockForAbstractClass();
        $root->expects($this->once())
            ->method('getExtra')
            ->willReturn([]);
        $config = new Config($root);
        $ref_default = new \ReflectionProperty($config, 'defaultConfig');
        $ref_default->setAccessible(TRUE);
        $ref_plugin_config = new \ReflectionMethod($config, 'getAllCleanupPaths');
        $ref_plugin_config->setAccessible(TRUE);
        $this->assertEquals($ref_default->getValue($config), $ref_plugin_config->invoke($config));
    }
    
    /**
     * @covers ::getAllCleanupPaths
     */
    public function testRootMergeConfig() {
        // Root package has configuration in extra.
        $root = $this->getMockBuilder(RootPackageInterface::class)
            ->onlyMethods([
            'getExtra',
        ])
            ->getMockForAbstractClass();
        $root->expects($this->once())
            ->method('getExtra')
            ->willReturn([
            'drupal-core-vendor-hardening' => [
                'isa/string' => 'test_dir',
                'an/array' => [
                    'test_dir',
                    'doc_dir',
                ],
            ],
        ]);
        $config = new Config($root);
        $ref_plugin_config = new \ReflectionMethod($config, 'getAllCleanupPaths');
        $ref_plugin_config->setAccessible(TRUE);
        $plugin_config = $ref_plugin_config->invoke($config);
        $this->assertSame([
            'test_dir',
        ], $plugin_config['isa/string']);
        $this->assertSame([
            'test_dir',
            'doc_dir',
        ], $plugin_config['an/array']);
    }
    
    /**
     * @covers ::getAllCleanupPaths
     */
    public function testMixedCaseConfigCleanupPackages() {
        // Root package has configuration in extra.
        $root = $this->getMockBuilder(RootPackageInterface::class)
            ->onlyMethods([
            'getExtra',
        ])
            ->getMockForAbstractClass();
        $root->expects($this->once())
            ->method('getExtra')
            ->willReturn([
            'drupal-core-vendor-hardening' => [
                'NotMikey179/vfsStream' => [
                    'src/test',
                ],
            ],
        ]);
        $config = new Config($root);
        $ref_plugin_config = new \ReflectionMethod($config, 'getAllCleanupPaths');
        $ref_plugin_config->setAccessible(TRUE);
        // Put some mixed-case in the defaults.
        $ref_default = new \ReflectionProperty($config, 'defaultConfig');
        $ref_default->setAccessible(TRUE);
        $ref_default->setValue($config, [
            'BeHatted/Mank' => [
                'tests',
            ],
            'SymFunic/HTTPFoundational' => [
                'src',
            ],
        ]);
        $plugin_config = $ref_plugin_config->invoke($config);
        foreach (array_keys($plugin_config) as $package_name) {
            $this->assertDoesNotMatchRegularExpression('/[A-Z]/', $package_name);
        }
    }

}

Classes

Title Deprecated Summary
ConfigTest @coversDefaultClass Drupal\Composer\Plugin\VendorHardening\Config @group VendorHardening

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