class ComposerValidatorTest
@covers \Drupal\package_manager\Validator\ComposerValidator @group package_manager @internal
Hierarchy
- class \Drupal\KernelTests\KernelTestBase extends \PHPUnit\Framework\TestCase implements \Drupal\Core\DependencyInjection\ServiceProviderInterface uses \Drupal\KernelTests\AssertContentTrait, \Drupal\Tests\RandomGeneratorTrait, \Drupal\Tests\ConfigTestTrait, \Drupal\Tests\ExtensionListTestTrait, \Drupal\Tests\TestRequirementsTrait, \Drupal\Tests\PhpUnitCompatibilityTrait, \Prophecy\PhpUnit\ProphecyTrait, \Drupal\TestTools\Extension\DeprecationBridge\ExpectDeprecationTrait
- class \Drupal\Tests\package_manager\Kernel\PackageManagerKernelTestBase extends \Drupal\KernelTests\KernelTestBase uses \Drupal\Tests\package_manager\Traits\AssertPreconditionsTrait, \Drupal\Tests\package_manager\Traits\ComposerStagerTestTrait, \Drupal\Tests\package_manager\Traits\FixtureManipulatorTrait, \Drupal\Tests\package_manager\Traits\FixtureUtilityTrait, \Drupal\package_manager\StatusCheckTrait, \Drupal\Tests\package_manager\Traits\ValidationTestTrait
- class \Drupal\Tests\package_manager\Kernel\ComposerValidatorTest extends \Drupal\Tests\package_manager\Kernel\PackageManagerKernelTestBase
- class \Drupal\Tests\package_manager\Kernel\PackageManagerKernelTestBase extends \Drupal\KernelTests\KernelTestBase uses \Drupal\Tests\package_manager\Traits\AssertPreconditionsTrait, \Drupal\Tests\package_manager\Traits\ComposerStagerTestTrait, \Drupal\Tests\package_manager\Traits\FixtureManipulatorTrait, \Drupal\Tests\package_manager\Traits\FixtureUtilityTrait, \Drupal\package_manager\StatusCheckTrait, \Drupal\Tests\package_manager\Traits\ValidationTestTrait
Expanded class hierarchy of ComposerValidatorTest
File
-
core/
modules/ package_manager/ tests/ src/ Kernel/ ComposerValidatorTest.php, line 17
Namespace
Drupal\Tests\package_manager\KernelView source
class ComposerValidatorTest extends PackageManagerKernelTestBase {
/**
* Data provider for testComposerSettingsValidation().
*
* @return mixed[][]
* The test cases.
*/
public static function providerComposerSettingsValidation() : array {
$summary = t("Composer settings don't satisfy Package Manager's requirements.");
$secure_http_error = ValidationResult::createError([
t('HTTPS must be enabled for Composer downloads. See <a href="https://getcomposer.org/doc/06-config.md#secure-http">the Composer documentation</a> for more information.'),
], $summary);
$tls_error = ValidationResult::createError([
t('TLS must be enabled for HTTPS Composer downloads. See <a href="https://getcomposer.org/doc/06-config.md#disable-tls">the Composer documentation</a> for more information.'),
t('You should also check the value of <code>secure-http</code> and make sure that it is set to <code>true</code> or not set at all.'),
], $summary);
return [
'secure-http set to FALSE' => [
[
'secure-http' => FALSE,
],
[
$secure_http_error,
],
],
'secure-http explicitly set to TRUE' => [
[
'secure-http' => TRUE,
],
[],
],
'secure-http implicitly set to TRUE' => [
[
'extra.unrelated' => TRUE,
],
[],
],
'disable-tls set to TRUE' => [
[
'disable-tls' => TRUE,
],
[
$tls_error,
],
],
'disable-tls implicitly set to FALSE' => [
[
'extra.unrelated' => TRUE,
],
[],
],
'explicitly set disable-tls to FALSE' => [
[
'disable-tls' => FALSE,
],
[],
],
'disable-tls set to TRUE + secure-http set to TRUE, message only for TLS, secure-http overridden' => [
[
'disable-tls' => TRUE,
'secure-http' => TRUE,
],
[
$tls_error,
],
],
'disable-tls set to TRUE + secure-http set to FALSE, message only for TLS' => [
[
'disable-tls' => TRUE,
'secure-http' => FALSE,
],
[
$tls_error,
],
],
];
}
/**
* Tests that Composer's settings are validated.
*
* @param array $config
* The config to set.
* @param \Drupal\package_manager\ValidationResult[] $expected_results
* The expected validation results, if any.
*
* @dataProvider providerComposerSettingsValidation
*/
public function testComposerSettingsValidation(array $config, array $expected_results) : void {
(new ActiveFixtureManipulator())->addConfig($config)
->commitChanges();
$this->assertStatusCheckResults($expected_results);
$this->assertResults($expected_results, PreCreateEvent::class);
}
/**
* Tests that Composer's settings are validated during pre-apply.
*
* @param array $config
* The config to set.
* @param \Drupal\package_manager\ValidationResult[] $expected_results
* The expected validation results, if any.
*
* @dataProvider providerComposerSettingsValidation
*/
public function testComposerSettingsValidationDuringPreApply(array $config, array $expected_results) : void {
$this->getStageFixtureManipulator()
->addConfig($config);
$this->assertResults($expected_results, PreApplyEvent::class);
}
/**
* Data provider for ::testLinkToOnlineHelp().
*
* @return array[]
* The test cases.
*/
public static function providerLinkToOnlineHelp() : array {
return [
'TLS disabled' => [
[
'disable-tls' => TRUE,
],
[
t('TLS must be enabled for HTTPS Composer downloads. See <a href="/admin/help/package_manager#package-manager-requirements">the help page</a> for more information on how to configure Composer to download packages securely.'),
t('You should also check the value of <code>secure-http</code> and make sure that it is set to <code>true</code> or not set at all.'),
],
],
'secure-http is off' => [
[
'secure-http' => FALSE,
],
[
t('HTTPS must be enabled for Composer downloads. See <a href="/admin/help/package_manager#package-manager-requirements">the help page</a> for more information on how to configure Composer to download packages securely.'),
],
],
];
}
/**
* Tests that invalid configuration links to online help, if available.
*
* @param array $config
* The Composer configuration to set.
* @param \Drupal\Core\StringTranslation\TranslatableMarkup[] $expected_messages
* The expected validation error messages.
*
* @dataProvider providerLinkToOnlineHelp
*/
public function testLinkToOnlineHelp(array $config, array $expected_messages) : void {
$this->enableModules([
'help',
]);
(new ActiveFixtureManipulator())->addConfig($config)
->commitChanges();
$result = ValidationResult::createError($expected_messages, t("Composer settings don't satisfy Package Manager's requirements."));
$this->assertStatusCheckResults([
$result,
]);
}
/**
* {@inheritdoc}
*/
protected function tearDown() : void {
// Ensure that any warnings arising from Composer settings (which we expect
// in this test) will not fail the test during tear-down.
$this->failureLogger
->reset();
parent::tearDown();
}
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.