Commit 612c1947 authored by Ted Bowman's avatar Ted Bowman
Browse files

Issue #3307369 by kunal.sachdev, tedbow, phenaproxima: Validate all changed or...

Issue #3307369 by kunal.sachdev, tedbow, phenaproxima: Validate all changed or updated Drupal projects with Update XML
parent c2790b06
Loading
Loading
Loading
Loading
+0 −39
Changes for automatic_updates_extensions/src/Validator/UpdateReleaseValidator.php: 0 added lines, 39 removed lines.
Original line number Diff line number Diff line
@@ -6,7 +6,6 @@ use Drupal\package_manager\ProjectInfo;
use Drupal\automatic_updates_extensions\ExtensionUpdater;
use Drupal\package_manager\LegacyVersionUtility;
use Drupal\Core\StringTranslation\StringTranslationTrait;
use Drupal\package_manager\Event\PreApplyEvent;
use Drupal\package_manager\Event\PreCreateEvent;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;

@@ -63,43 +62,6 @@ final class UpdateReleaseValidator implements EventSubscriberInterface {
    return FALSE;
  }

  /**
   * Checks that the packages are secure and supported.
   *
   * @param \Drupal\package_manager\Event\PreApplyEvent $event
   *   The event object.
   */
  public function checkStagedReleases(PreApplyEvent $event): void {
    $messages = [];

    // Get packages that were installed and also updated in the staging area.
    $active = $event->getStage()->getActiveComposer();
    $staged = $event->getStage()->getStageComposer();
    $updated_packages = $staged->getPackagesWithDifferentVersionsIn($active);
    foreach ($updated_packages as $staged_package) {
      if (!in_array($staged_package->getType(),
        ['drupal-module', 'drupal-theme'], TRUE)) {
        continue;
      }
      $project_name = $staged->getProjectForPackage($staged_package->getName());
      $semantic_version = $staged_package->getPrettyVersion();
      if (!$this->isSupportedRelease($project_name, $semantic_version)) {
        $messages[] = $this->t('Project @project_name to version @version', [
          '@project_name' => $project_name,
          '@version' => $semantic_version,
        ]);
      }
    }
    if ($messages) {
      $summary = $this->formatPlural(
        count($messages),
        'Cannot update because the following project version is not in the list of installable releases.',
        'Cannot update because the following project versions are not in the list of installable releases.'
      );
      $event->addError($messages, $summary);
    }
  }

  /**
   * Checks that the update projects are secure and supported.
   *
@@ -144,7 +106,6 @@ final class UpdateReleaseValidator implements EventSubscriberInterface {
  public static function getSubscribedEvents() {
    return [
      PreCreateEvent::class => 'checkRelease',
      PreApplyEvent::class => 'checkStagedReleases',
    ];
  }

+1 −1
Changes for automatic_updates_extensions/tests/src/Kernel/AutomaticUpdatesExtensionsKernelTestBase.php: 1 added line, 1 removed line.
Original line number Diff line number Diff line
@@ -19,7 +19,7 @@ abstract class AutomaticUpdatesExtensionsKernelTestBase extends AutomaticUpdates
   */
  protected static $modules = [
    'automatic_updates_extensions',
    'automatic_updates_test_release_history',
    'package_manager_test_release_history',
  ];

  /**
+1 −0
Changes for automatic_updates_extensions/tests/src/Kernel/Validator/PackagesInstalledWithComposerValidatorTest.php: 1 added line, 0 removed lines.
Original line number Diff line number Diff line
@@ -22,6 +22,7 @@ class PackagesInstalledWithComposerValidatorTest extends AutomaticUpdatesExtensi
    // In this test, we don't care whether the updated projects are secure and
    // supported.
    $this->disableValidators[] = 'automatic_updates_extensions.validator.target_release';
    $this->disableValidators[] = 'package_manager.validator.supported_releases';
    // @todo The validator being tested covers the same cases as the following
    //   validator. PackagesInstalledWithComposerValidatorTest will be removed
    //   in https://drupal.org/i/3303900.
+0 −77
Changes for automatic_updates_extensions/tests/src/Kernel/Validator/UpdateReleaseValidatorTest.php: 0 added lines, 77 removed lines.
Original line number Diff line number Diff line
@@ -3,7 +3,6 @@
namespace Drupal\Tests\automatic_updates_extensions\Kernel\Validator;

use Drupal\package_manager\LegacyVersionUtility;
use Drupal\package_manager\Event\PreApplyEvent;
use Drupal\package_manager\Event\PreCreateEvent;
use Drupal\package_manager\ValidationResult;
use Drupal\Tests\automatic_updates_extensions\Kernel\AutomaticUpdatesExtensionsKernelTestBase;
@@ -80,80 +79,4 @@ class UpdateReleaseValidatorTest extends AutomaticUpdatesExtensionsKernelTestBas
    $this->assertUpdateResults([$project => $target_version], $expected_results, PreCreateEvent::class);
  }

  /**
   * Data provider for testPreApplyException().
   *
   * @return mixed[][]
   *   The test cases.
   */
  public function providerTestPreApplyException(): array {
    $fixtures_folder = __DIR__ . '/../../../fixtures/update_release_validator';
    return [
      'semver, supported update' => ['semver_test', '8.1.0', '8.1.1', "$fixtures_folder/semver_supported_update_stage", FALSE],
      'semver, update to unsupported branch' => ['semver_test', '8.1.0', '8.2.0', "$fixtures_folder/semver_unsupported_update_stage", TRUE],
      'legacy, supported update' => ['aaa_update_test', '8.x-2.0', '8.x-2.1', "$fixtures_folder/legacy_supported_update_stage", FALSE],
      'legacy, update to unsupported branch' => ['aaa_update_test', '8.x-2.0', '8.x-3.0', "$fixtures_folder/legacy_unsupported_update_stage", TRUE],
    ];
  }

  /**
   * Tests updating to a release during pre-apply.
   *
   * @param string $project
   *   The project to update.
   * @param string $installed_version
   *   The installed version of the project.
   * @param string $target_version
   *   The target version.
   * @param string $stage_dir
   *   Path of fixture stage directory. It will be used as the virtual project's
   *   stage directory.
   * @param bool $error_expected
   *   Whether an error is expected in the update.
   *
   * @dataProvider providerTestPreApplyException
   */
  public function testPreApplyException(string $project, string $installed_version, string $target_version, string $stage_dir, bool $error_expected): void {
    $this->enableModules(['aaa_automatic_updates_test', $project]);

    $module_info = ['version' => $installed_version, 'project' => $project];
    $aaa_automatic_updates_test_info = ['version' => '7.0.0', 'project' => 'aaa_automatic_updates_test'];
    $this->config('update_test.settings')
      ->set("system_info.$project", $module_info)
      ->set("system_info.aaa_automatic_updates_test", $aaa_automatic_updates_test_info)
      ->save();

    // Path of `active.installed.json` file. It will be used as the virtual
    // project's active `vendor/composer/installed.json` file.
    $this->setReleaseMetadata([
      'aaa_automatic_updates_test' => __DIR__ . "/../../../../../package_manager/tests/fixtures/release-history/aaa_automatic_updates_test.9.8.2.xml",
      $project => __DIR__ . "/../../../fixtures/release-history/$project.1.1.xml",
      'drupal' => __DIR__ . '/../../../../../package_manager/tests/fixtures/release-history/drupal.9.8.2.xml',
    ]);
    $active_dir = __DIR__ . '/../../../fixtures/update_release_validator/active';
    $this->copyFixtureFolderToActiveDirectory($active_dir);
    $this->copyFixtureFolderToStageDirectoryOnApply($stage_dir);
    if ($error_expected) {
      $expected_results = [
        ValidationResult::createError(
          ["Project $project to version " . LegacyVersionUtility::convertToSemanticVersion($target_version)],
          t('Cannot update because the following project version is not in the list of installable releases.')
        ),
      ];
    }
    else {
      $expected_results = [];
    }

    // Always updating aaa_automatic_updates_test to 7.0.1(valid release) along
    // with the project provided for test.
    $this->assertUpdateResults(
      [
        'aaa_automatic_updates_test' => '7.0.1',
      ],
      $expected_results,
      PreApplyEvent::class
    );
  }

}
+4 −0
Changes for package_manager/package_manager.services.yml: 4 added lines, 0 removed lines.
Original line number Diff line number Diff line
@@ -179,6 +179,10 @@ services:
    class: Drupal\package_manager\Validator\ComposerPatchesValidator
    tags:
      - { name: event_subscriber }
  package_manager.validator.supported_releases:
    class: Drupal\package_manager\Validator\SupportedReleaseValidator
    tags:
      - { name: event_subscriber }
  package_manager.update_processor:
    class: Drupal\package_manager\PackageManagerUpdateProcessor
    arguments: [ '@config.factory', '@queue', '@update.fetcher', '@state', '@private_key', '@keyvalue', '@keyvalue.expirable' ]
Loading