You are here

class ConfigTest in Drupal 9

Same name in this branch
  1. 9 core/tests/Drupal/Tests/Core/Config/ConfigTest.php \Drupal\Tests\Core\Config\ConfigTest
  2. 9 core/tests/Drupal/Tests/Composer/Plugin/VendorHardening/ConfigTest.php \Drupal\Tests\Composer\Plugin\VendorHardening\ConfigTest
  3. 9 core/tests/Drupal/Tests/Composer/Plugin/ProjectMessage/ConfigTest.php \Drupal\Tests\Composer\Plugin\ProjectMessage\ConfigTest
  4. 9 core/modules/system/tests/src/Functional/File/ConfigTest.php \Drupal\Tests\system\Functional\File\ConfigTest
  5. 9 core/modules/config/tests/config_test/src/Entity/ConfigTest.php \Drupal\config_test\Entity\ConfigTest
  6. 9 core/modules/migrate/tests/src/Unit/destination/ConfigTest.php \Drupal\Tests\migrate\Unit\destination\ConfigTest
  7. 9 core/modules/migrate_drupal/tests/src/Kernel/Plugin/migrate/source/d8/ConfigTest.php \Drupal\Tests\migrate_drupal\Kernel\Plugin\migrate\source\d8\ConfigTest
Same name and namespace in other branches
  1. 8 core/tests/Drupal/Tests/Composer/Plugin/VendorHardening/ConfigTest.php \Drupal\Tests\Composer\Plugin\VendorHardening\ConfigTest

@coversDefaultClass Drupal\Composer\Plugin\VendorHardening\Config @group VendorHardening

Hierarchy

Expanded class hierarchy of ConfigTest

File

core/tests/Drupal/Tests/Composer/Plugin/VendorHardening/ConfigTest.php, line 14

Namespace

Drupal\Tests\Composer\Plugin\VendorHardening
View source
class ConfigTest extends TestCase {
  use PhpUnitWarnings;

  /**
   * @covers ::getPathsForPackage
   */
  public function testGetPathsForPackageMixedCase() {
    $config = $this
      ->getMockBuilder(Config::class)
      ->setMethods([
      '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)
      ->setMethods([
      '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)
      ->setMethods([
      '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)
      ->setMethods([
      '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);
    }
  }

}

Members

Namesort descending Modifiers Type Description Overrides
ConfigTest::testGetPathsForPackageMixedCase public function @covers ::getPathsForPackage
ConfigTest::testMixedCaseConfigCleanupPackages public function @covers ::getAllCleanupPaths
ConfigTest::testNoRootMergeConfig public function @covers ::getAllCleanupPaths
ConfigTest::testRootMergeConfig public function @covers ::getAllCleanupPaths
PhpUnitWarnings::$deprecationWarnings private static property Deprecation warnings from PHPUnit to raise with @trigger_error().
PhpUnitWarnings::addWarning public function Converts PHPUnit deprecation warnings to E_USER_DEPRECATED.