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;
class ConfigTest extends TestCase {
use PhpUnitWarnings;
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'));
}
public function testNoRootMergeConfig() {
$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));
}
public function testRootMergeConfig() {
$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']);
}
public function testMixedCaseConfigCleanupPackages() {
$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);
$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);
}
}
}