Skip to content
Snippets Groups Projects
Commit 3cb9eeba authored by Adam G-H's avatar Adam G-H
Browse files

Issue #3293381 by phenaproxima, tedbow: If cweagans/composer-patches is...

Issue #3293381 by phenaproxima, tedbow: If cweagans/composer-patches is installed, require composer-exit-on-patch-failure
parent cfd7b366
No related branches found
No related tags found
1 merge request!361Issue #3293381: If cweagans/composer-patches is installed, require composer-exit-on-patch-failure
......@@ -101,6 +101,12 @@ services:
- '@package_manager.validator.symlink'
tags:
- { name: event_subscriber }
automatic_updates.validator.patches:
class: Drupal\automatic_updates\Validator\PackageManagerReadinessCheck
arguments:
- '@package_manager.validator.patches'
tags:
- { name: event_subscriber }
automatic_updates.cron_frequency_validator:
class: Drupal\automatic_updates\Validator\CronFrequencyValidator
arguments:
......
......@@ -6,6 +6,7 @@ use Drupal\automatic_updates\Event\ReadinessCheckEvent;
use Drupal\automatic_updates_test\EventSubscriber\TestSubscriber1;
use Drupal\package_manager\Event\PreApplyEvent;
use Drupal\package_manager\ValidationResult;
use Drupal\package_manager_bypass\Beginner;
use Drupal\Tests\automatic_updates\Functional\AutomaticUpdatesFunctionalTestBase;
use Drupal\Tests\automatic_updates\Traits\ValidationTestTrait;
use Drupal\Tests\automatic_updates_extensions\Traits\FormTestTrait;
......@@ -140,14 +141,6 @@ class UpdaterFormTest extends AutomaticUpdatesFunctionalTestBase {
* @dataProvider providerSuccessfulUpdate
*/
public function testSuccessfulUpdate(bool $maintenance_mode_on, string $project_name, string $installed_version, string $target_version): void {
// Disable the scaffold file permissions and target release validators
// because they will try to read composer.json from the staging area,
// which won't exist because Package Manager is bypassed.
$this->disableValidators([
'automatic_updates.validator.scaffold_file_permissions',
'automatic_updates_extensions.validator.target_release',
]);
$this->container->get('theme_installer')->install(['automatic_updates_theme_with_updates']);
$this->updateProject = $project_name;
$this->setReleaseMetadata(__DIR__ . '/../../../../tests/fixtures/release-history/drupal.9.8.2.xml');
......@@ -157,6 +150,8 @@ class UpdaterFormTest extends AutomaticUpdatesFunctionalTestBase {
$state = $this->container->get('state');
$state->set('system.maintenance_mode', $maintenance_mode_on);
Beginner::setFixturePath(__DIR__ . '/../../fixtures/fake-site');
$page = $this->getSession()->getPage();
// Navigate to the automatic updates form.
$this->drupalGet('/admin/reports/updates');
......
......@@ -156,3 +156,7 @@ services:
- '@string_translation'
tags:
- { name: event_subscriber }
package_manager.validator.patches:
class: Drupal\package_manager\Validator\ComposerPatchesValidator
tags:
- { name: event_subscriber }
<?php
namespace Drupal\package_manager\Validator;
use Drupal\Core\StringTranslation\StringTranslationTrait;
use Drupal\package_manager\Event\PreCreateEvent;
use Drupal\package_manager\Event\PreOperationStageEvent;
/**
* Validates the configuration of the cweagans/composer-patches plugin.
*/
class ComposerPatchesValidator implements PreOperationStageValidatorInterface {
use StringTranslationTrait;
/**
* {@inheritdoc}
*/
public function validateStagePreOperation(PreOperationStageEvent $event): void {
$stage = $event->getStage();
$composer = $stage->getActiveComposer();
if (array_key_exists('cweagans/composer-patches', $composer->getInstalledPackages())) {
$composer = $composer->getComposer();
$extra = $composer->getPackage()->getExtra();
if (empty($extra['composer-exit-on-patch-failure'])) {
$event->addError([
$this->t('The <code>cweagans/composer-patches</code> plugin is installed, but the <code>composer-exit-on-patch-failure</code> key is not set to <code>true</code> in the <code>extra</code> section of @file.', [
// If composer.json is in a virtual file system, Composer will not
// be able to resolve a real path for it.
'@file' => $composer->getConfig()->getConfigSource()->getName() ?: 'composer.json',
]),
]);
}
}
}
/**
* {@inheritdoc}
*/
public static function getSubscribedEvents() {
return [
PreCreateEvent::class => 'validateStagePreOperation',
];
}
}
<?php
namespace Drupal\Tests\package_manager\Kernel;
use Composer\Json\JsonFile;
use Drupal\package_manager\Exception\StageValidationException;
use Drupal\package_manager\ValidationResult;
/**
* @covers \Drupal\package_manager\Validator\ComposerPatchesValidator
*
* @group package_manager
*/
class ComposerPatchesValidatorTest extends PackageManagerKernelTestBase {
/**
* Tests that the patcher configuration is validated during pre-create.
*/
public function testPreCreate(): void {
// Simulate an active directory where the patcher is installed, but there's
// no composer-exit-on-patch-failure flag.
$dir = $this->container->get('package_manager.path_locator')
->getProjectRoot();
// Simulate that the patcher is installed in the active directory.
$file = new JsonFile($dir . '/vendor/composer/installed.json');
$this->assertTrue($file->exists());
$data = $file->read();
$data['packages'][] = [
'name' => 'cweagans/composer-patches',
'version' => '1.0.0',
];
$file->write($data);
$error = ValidationResult::createError([
'The <code>cweagans/composer-patches</code> plugin is installed, but the <code>composer-exit-on-patch-failure</code> key is not set to <code>true</code> in the <code>extra</code> section of composer.json.',
]);
try {
$this->createStage()->create();
$this->fail('Expected a validation error.');
}
catch (StageValidationException $e) {
$this->assertValidationResultsEqual([$error], $e->getResults());
}
}
}
......@@ -3,7 +3,12 @@
{
"name": "drupal/core",
"version": "9.8.1",
"type": "drupal-core"
"type": "drupal-core",
"extra": {
"drupal-scaffold": {
"file-mapping": {}
}
}
}
]
}
......@@ -8,7 +8,7 @@ use Drupal\automatic_updates_test\Datetime\TestTime;
use Drupal\automatic_updates_test\EventSubscriber\TestSubscriber1;
use Drupal\automatic_updates_test2\EventSubscriber\TestSubscriber2;
use Drupal\Core\Url;
use Drupal\package_manager_bypass\Stager;
use Drupal\package_manager_bypass\Beginner;
use Drupal\system\SystemManager;
use Drupal\Tests\automatic_updates\Traits\ValidationTestTrait;
use Drupal\Tests\Traits\Core\CronRunTrait;
......@@ -422,7 +422,7 @@ class ReadinessValidationTest extends AutomaticUpdatesFunctionalTestBase {
// readiness check (without storing the results), and the checker is no
// longer raising an error.
$this->drupalGet('/admin/modules/automatic-update');
Stager::setFixturePath(__DIR__ . '/../../fixtures/staged/9.8.1');
Beginner::setFixturePath(__DIR__ . '/../../fixtures/staged/9.8.1');
$assert_session->buttonExists('Update');
// Ensure that the previous results are still displayed on another admin
// page, to confirm that the updater form is not discarding the previous
......
......@@ -2,6 +2,7 @@
namespace Drupal\Tests\automatic_updates\Functional;
use Drupal\package_manager_bypass\Beginner;
use Drupal\package_manager_bypass\Stager;
/**
......@@ -52,6 +53,7 @@ class UpdateLockTest extends AutomaticUpdatesFunctionalTestBase {
// We should be able to get partway through an update without issue.
$this->drupalLogin($user_1);
$this->drupalGet('/admin/modules/automatic-update');
Beginner::setFixturePath(__DIR__ . '/../../fixtures/fake-site');
Stager::setFixturePath(__DIR__ . '/../../fixtures/staged/9.8.1');
$page->pressButton('Update');
$this->checkForMetaRefresh();
......
......@@ -9,6 +9,7 @@ use Drupal\package_manager\Event\PreApplyEvent;
use Drupal\package_manager\Event\PreCreateEvent;
use Drupal\package_manager\ValidationResult;
use Drupal\automatic_updates_test\EventSubscriber\TestSubscriber1;
use Drupal\package_manager_bypass\Beginner;
use Drupal\package_manager_bypass\Stager;
use Drupal\Tests\automatic_updates\Traits\ValidationTestTrait;
use Drupal\Tests\package_manager\Traits\PackageManagerBypassTestTrait;
......@@ -335,6 +336,7 @@ class UpdaterFormTest extends AutomaticUpdatesFunctionalTestBase {
$this->checkForUpdates();
$this->drupalGet('/admin/modules/automatic-update');
Beginner::setFixturePath(__DIR__ . '/../../fixtures/fake-site');
Stager::setFixturePath(__DIR__ . '/../../fixtures/staged/9.8.1');
$page->pressButton('Update to 9.8.1');
$this->checkForMetaRefresh();
......@@ -470,6 +472,7 @@ class UpdaterFormTest extends AutomaticUpdatesFunctionalTestBase {
$page = $this->getSession()->getPage();
$this->drupalGet('/admin/modules/automatic-update');
Beginner::setFixturePath(__DIR__ . '/../../fixtures/fake-site');
Stager::setFixturePath(__DIR__ . '/../../fixtures/staged/9.8.1');
// The warning should be visible.
$assert_session = $this->assertSession();
......@@ -571,6 +574,7 @@ class UpdaterFormTest extends AutomaticUpdatesFunctionalTestBase {
$cached_message = $this->setAndAssertCachedMessage();
$this->drupalGet($update_form_url);
Beginner::setFixturePath(__DIR__ . '/../../fixtures/fake-site');
Stager::setFixturePath(__DIR__ . '/../../fixtures/staged/9.8.1');
$assert_session->pageTextNotContains($cached_message);
$page->pressButton('Update to 9.8.1');
......@@ -600,6 +604,7 @@ class UpdaterFormTest extends AutomaticUpdatesFunctionalTestBase {
$page = $this->getSession()->getPage();
$this->drupalGet('/admin/modules/automatic-update');
Beginner::setFixturePath(__DIR__ . '/../../fixtures/fake-site');
Stager::setFixturePath(__DIR__ . '/../../fixtures/staged/9.8.1');
$page->pressButton('Update to 9.8.1');
$this->checkForMetaRefresh();
......@@ -636,6 +641,8 @@ class UpdaterFormTest extends AutomaticUpdatesFunctionalTestBase {
$this->setCoreVersion('9.8.0');
$this->checkForUpdates();
Beginner::setFixturePath(__DIR__ . '/../../fixtures/fake-site');
$this->drupalGet('/admin/modules/automatic-update');
$error = new \Exception('Some Exception');
TestSubscriber1::setException($error, PostRequireEvent::class);
......
......@@ -53,6 +53,7 @@ class PackageManagerReadinessChecksTest extends AutomaticUpdatesKernelTestBase {
'Multisite validator' => ['package_manager.validator.multisite'],
'Symlink validator' => ['package_manager.validator.symlink'],
'Settings validator' => ['package_manager.validator.settings'],
'Patches validator' => ['package_manager.validator.patches'],
];
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment