Skip to content
Snippets Groups Projects
Commit 0361e19b authored by Adam G-H's avatar Adam G-H Committed by Ted Bowman
Browse files

Issue #3249983 by phenaproxima, tedbow: Create a test module in Package...

Issue #3249983 by phenaproxima, tedbow: Create a test module in Package Manager for testing stage validation
parent e4e46d43
No related branches found
No related tags found
1 merge request!120Issue #3249983: Create a test module in Package Manager for testing stage validation
name: 'Package Manager Validation Test'
description: 'Provides an event subscriber to test Package Manager validation.'
type: module
package: Testing
dependencies:
- automatic_updates:package_manager
services:
package_manager_test_validation.subscriber:
class: Drupal\package_manager_test_validation\TestSubscriber
arguments:
- '@state'
tags:
- { name: event_subscriber }
<?php
namespace Drupal\package_manager_test_validation;
use Drupal\Core\State\StateInterface;
use Drupal\package_manager\Event\PostApplyEvent;
use Drupal\package_manager\Event\PostCreateEvent;
use Drupal\package_manager\Event\PostDestroyEvent;
use Drupal\package_manager\Event\PostRequireEvent;
use Drupal\package_manager\Event\PreApplyEvent;
use Drupal\package_manager\Event\PreCreateEvent;
use Drupal\package_manager\Event\PreDestroyEvent;
use Drupal\package_manager\Event\PreRequireEvent;
use Drupal\package_manager\Event\StageEvent;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
/**
* Defines an event subscriber for testing validation of Package Manager events.
*/
class TestSubscriber implements EventSubscriberInterface {
/**
* The key to use store the test results.
*
* @var string
*/
protected const STATE_KEY = 'package_manager_test_validation';
/**
* The state service.
*
* @var \Drupal\Core\State\StateInterface
*/
protected $state;
/**
* Creates a TestSubscriber object.
*
* @param \Drupal\Core\State\StateInterface $state
* The state service.
*/
public function __construct(StateInterface $state) {
$this->state = $state;
}
/**
* Sets validation results for a specific event.
*
* This method is static to enable setting the expected results before this
* module is enabled.
*
* @param \Drupal\package_manager\ValidationResult[]|null $results
* The validation results, or NULL to delete stored results.
* @param string $event
* The event class.
*/
public static function setTestResult(?array $results, string $event): void {
$key = static::STATE_KEY . '.' . $event;
$state = \Drupal::state();
if (isset($results)) {
$state->set($key, $results);
}
else {
$state->delete($key);
}
}
/**
* Sets an exception to throw for a specific event.
*
* This method is static to enable setting the expected results before this
* module is enabled.
*
* @param \Throwable|null $error
* The exception to throw, or NULL to delete a stored exception.
* @param string $event
* The event class.
*/
public static function setException(?\Throwable $error, string $event): void {
$key = static::STATE_KEY . '.' . $event;
$state = \Drupal::state();
if (isset($error)) {
$state->set($key, $error);
}
else {
$state->delete($key);
}
}
/**
* Adds validation results to a stage event.
*
* @param \Drupal\package_manager\Event\StageEvent $event
* The event object.
*/
public function addResults(StageEvent $event): void {
$results = $this->state->get(static::STATE_KEY . '.' . get_class($event), []);
if ($results instanceof \Throwable) {
throw $results;
}
foreach ($results as $result) {
$event->addValidationResult($result);
}
}
/**
* {@inheritdoc}
*/
public static function getSubscribedEvents() {
$priority = defined('PACKAGE_MANAGER_TEST_VALIDATOR_PRIORITY') ? PACKAGE_MANAGER_TEST_VALIDATOR_PRIORITY : 5;
return [
PreCreateEvent::class => ['addResults', $priority],
PostCreateEvent::class => ['addResults', $priority],
PreRequireEvent::class => ['addResults', $priority],
PostRequireEvent::class => ['addResults', $priority],
PreApplyEvent::class => ['addResults', $priority],
PostApplyEvent::class => ['addResults', $priority],
PreDestroyEvent::class => ['addResults', $priority],
PostDestroyEvent::class => ['addResults', $priority],
];
}
}
...@@ -4,3 +4,4 @@ description: 'Module for testing Automatic Updates.' ...@@ -4,3 +4,4 @@ description: 'Module for testing Automatic Updates.'
package: Testing package: Testing
dependencies: dependencies:
- drupal:automatic_updates - drupal:automatic_updates
- automatic_updates:package_manager_test_validation
...@@ -3,86 +3,19 @@ ...@@ -3,86 +3,19 @@
namespace Drupal\automatic_updates_test\ReadinessChecker; namespace Drupal\automatic_updates_test\ReadinessChecker;
use Drupal\automatic_updates\Event\ReadinessCheckEvent; use Drupal\automatic_updates\Event\ReadinessCheckEvent;
use Drupal\Core\State\StateInterface; use Drupal\package_manager_test_validation\TestSubscriber;
use Drupal\package_manager\Event\PreApplyEvent;
use Drupal\package_manager\Event\PreCreateEvent;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
/** /**
* A test readiness checker. * A test readiness checker.
*/ */
class TestChecker1 implements EventSubscriberInterface { class TestChecker1 extends TestSubscriber {
/**
* The key to use store the test results.
*/
protected const STATE_KEY = 'automatic_updates_test.checker_results';
/**
* The state service.
*
* @var \Drupal\Core\State\StateInterface
*/
protected $state;
/**
* Creates a TestChecker object.
*
* @param \Drupal\Core\State\StateInterface $state
* The state service.
*/
public function __construct(StateInterface $state) {
$this->state = $state;
}
/**
* Sets messages for this readiness checker.
*
* This method is static to enable setting the expected messages before the
* test module is enabled.
*
* @param \Drupal\package_manager\ValidationResult[]|\Throwable|null $checker_results
* The test validation results, or an exception to throw, or NULL to delete
* stored results.
* @param string $event_name
* (optional )The event name. Defaults to
* ReadinessCheckEvent::class.
*/
public static function setTestResult($checker_results, string $event_name = ReadinessCheckEvent::class): void {
$key = static::STATE_KEY . ".$event_name";
if (isset($checker_results)) {
\Drupal::state()->set($key, $checker_results);
}
else {
\Drupal::state()->delete($key);
}
}
/**
* Adds test result to an update event from a state setting.
*
* @param object $event
* The update event.
*/
public function addResults(object $event): void {
$results = $this->state->get(static::STATE_KEY . '.' . get_class($event), []);
if ($results instanceof \Throwable) {
throw $results;
}
foreach ($results as $result) {
$event->addValidationResult($result);
}
}
/** /**
* {@inheritdoc} * {@inheritdoc}
*/ */
public static function getSubscribedEvents() { public static function getSubscribedEvents() {
$priority = defined('AUTOMATIC_UPDATES_TEST_SET_PRIORITY') ? AUTOMATIC_UPDATES_TEST_SET_PRIORITY : 5; $events = parent::getSubscribedEvents();
$events[ReadinessCheckEvent::class][] = ['addResults', $priority]; $events[ReadinessCheckEvent::class] = reset($events);
$events[PreCreateEvent::class][] = ['addResults', $priority];
$events[PreApplyEvent::class][] = ['addResults', $priority];
return $events; return $events;
} }
......
...@@ -3,6 +3,7 @@ ...@@ -3,6 +3,7 @@
namespace Drupal\Tests\automatic_updates\Functional; namespace Drupal\Tests\automatic_updates\Functional;
use Behat\Mink\Element\NodeElement; use Behat\Mink\Element\NodeElement;
use Drupal\automatic_updates\Event\ReadinessCheckEvent;
use Drupal\automatic_updates_test\Datetime\TestTime; use Drupal\automatic_updates_test\Datetime\TestTime;
use Drupal\automatic_updates_test\ReadinessChecker\TestChecker1; use Drupal\automatic_updates_test\ReadinessChecker\TestChecker1;
use Drupal\automatic_updates_test2\ReadinessChecker\TestChecker2; use Drupal\automatic_updates_test2\ReadinessChecker\TestChecker2;
...@@ -115,7 +116,7 @@ class ReadinessValidationTest extends AutomaticUpdatesFunctionalTestBase { ...@@ -115,7 +116,7 @@ class ReadinessValidationTest extends AutomaticUpdatesFunctionalTestBase {
$this->assertNoErrors(TRUE); $this->assertNoErrors(TRUE);
/** @var \Drupal\package_manager\ValidationResult[] $expected_results */ /** @var \Drupal\package_manager\ValidationResult[] $expected_results */
$expected_results = $this->testResults['checker_1']['1 error']; $expected_results = $this->testResults['checker_1']['1 error'];
TestChecker1::setTestResult($expected_results); TestChecker1::setTestResult($expected_results, ReadinessCheckEvent::class);
// Run the readiness checks. // Run the readiness checks.
$this->clickLink('Run readiness checks'); $this->clickLink('Run readiness checks');
...@@ -136,7 +137,7 @@ class ReadinessValidationTest extends AutomaticUpdatesFunctionalTestBase { ...@@ -136,7 +137,7 @@ class ReadinessValidationTest extends AutomaticUpdatesFunctionalTestBase {
$this->assertErrors($expected_results); $this->assertErrors($expected_results);
$expected_results = $this->testResults['checker_1']['1 error 1 warning']; $expected_results = $this->testResults['checker_1']['1 error 1 warning'];
TestChecker1::setTestResult($expected_results); TestChecker1::setTestResult($expected_results, ReadinessCheckEvent::class);
$key_value->delete('readiness_validation_last_run'); $key_value->delete('readiness_validation_last_run');
// Confirm a new message is displayed if the stored messages are deleted. // Confirm a new message is displayed if the stored messages are deleted.
$this->drupalGet('admin/reports/status'); $this->drupalGet('admin/reports/status');
...@@ -149,7 +150,7 @@ class ReadinessValidationTest extends AutomaticUpdatesFunctionalTestBase { ...@@ -149,7 +150,7 @@ class ReadinessValidationTest extends AutomaticUpdatesFunctionalTestBase {
$key_value->delete('readiness_validation_last_run'); $key_value->delete('readiness_validation_last_run');
$expected_results = $this->testResults['checker_1']['2 errors 2 warnings']; $expected_results = $this->testResults['checker_1']['2 errors 2 warnings'];
TestChecker1::setTestResult($expected_results); TestChecker1::setTestResult($expected_results, ReadinessCheckEvent::class);
$this->drupalGet('admin/reports/status'); $this->drupalGet('admin/reports/status');
// Confirm that both messages and summaries will be displayed on status // Confirm that both messages and summaries will be displayed on status
// report when there multiple messages. // report when there multiple messages.
...@@ -158,7 +159,7 @@ class ReadinessValidationTest extends AutomaticUpdatesFunctionalTestBase { ...@@ -158,7 +159,7 @@ class ReadinessValidationTest extends AutomaticUpdatesFunctionalTestBase {
$key_value->delete('readiness_validation_last_run'); $key_value->delete('readiness_validation_last_run');
$expected_results = $this->testResults['checker_1']['2 warnings']; $expected_results = $this->testResults['checker_1']['2 warnings'];
TestChecker1::setTestResult($expected_results); TestChecker1::setTestResult($expected_results, ReadinessCheckEvent::class);
$this->drupalGet('admin/reports/status'); $this->drupalGet('admin/reports/status');
$assert->pageTextContainsOnce('Update readiness checks'); $assert->pageTextContainsOnce('Update readiness checks');
// Confirm that warnings will display on the status report if there are no // Confirm that warnings will display on the status report if there are no
...@@ -167,7 +168,7 @@ class ReadinessValidationTest extends AutomaticUpdatesFunctionalTestBase { ...@@ -167,7 +168,7 @@ class ReadinessValidationTest extends AutomaticUpdatesFunctionalTestBase {
$key_value->delete('readiness_validation_last_run'); $key_value->delete('readiness_validation_last_run');
$expected_results = $this->testResults['checker_1']['1 warning']; $expected_results = $this->testResults['checker_1']['1 warning'];
TestChecker1::setTestResult($expected_results); TestChecker1::setTestResult($expected_results, ReadinessCheckEvent::class);
$this->drupalGet('admin/reports/status'); $this->drupalGet('admin/reports/status');
$assert->pageTextContainsOnce('Update readiness checks'); $assert->pageTextContainsOnce('Update readiness checks');
$this->assertWarnings($expected_results); $this->assertWarnings($expected_results);
...@@ -196,7 +197,7 @@ class ReadinessValidationTest extends AutomaticUpdatesFunctionalTestBase { ...@@ -196,7 +197,7 @@ class ReadinessValidationTest extends AutomaticUpdatesFunctionalTestBase {
// Confirm a user without the permission to run readiness checks does not // Confirm a user without the permission to run readiness checks does not
// have a link to run the checks when the checks need to be run again. // have a link to run the checks when the checks need to be run again.
$expected_results = $this->testResults['checker_1']['1 error']; $expected_results = $this->testResults['checker_1']['1 error'];
TestChecker1::setTestResult($expected_results); TestChecker1::setTestResult($expected_results, ReadinessCheckEvent::class);
// @todo Change this to use ::delayRequestTime() to simulate running cron // @todo Change this to use ::delayRequestTime() to simulate running cron
// after a 24 wait instead of directly deleting 'readiness_validation_last_run' // after a 24 wait instead of directly deleting 'readiness_validation_last_run'
// https://www.drupal.org/node/3113971. // https://www.drupal.org/node/3113971.
...@@ -219,7 +220,7 @@ class ReadinessValidationTest extends AutomaticUpdatesFunctionalTestBase { ...@@ -219,7 +220,7 @@ class ReadinessValidationTest extends AutomaticUpdatesFunctionalTestBase {
$assert->pageTextContainsOnce($expected_results[0]->getMessages()[0]); $assert->pageTextContainsOnce($expected_results[0]->getMessages()[0]);
$expected_results = $this->testResults['checker_1']['1 error 1 warning']; $expected_results = $this->testResults['checker_1']['1 error 1 warning'];
TestChecker1::setTestResult($expected_results); TestChecker1::setTestResult($expected_results, ReadinessCheckEvent::class);
// Confirm a new message is displayed if the cron is run after an hour. // Confirm a new message is displayed if the cron is run after an hour.
$this->delayRequestTime(); $this->delayRequestTime();
$this->cronRun(); $this->cronRun();
...@@ -238,7 +239,7 @@ class ReadinessValidationTest extends AutomaticUpdatesFunctionalTestBase { ...@@ -238,7 +239,7 @@ class ReadinessValidationTest extends AutomaticUpdatesFunctionalTestBase {
// Confirm that if cron runs less than hour after it previously ran it will // Confirm that if cron runs less than hour after it previously ran it will
// not run the checkers again. // not run the checkers again.
$unexpected_results = $this->testResults['checker_1']['2 errors 2 warnings']; $unexpected_results = $this->testResults['checker_1']['2 errors 2 warnings'];
TestChecker1::setTestResult($unexpected_results); TestChecker1::setTestResult($unexpected_results, ReadinessCheckEvent::class);
$this->delayRequestTime(30); $this->delayRequestTime(30);
$this->cronRun(); $this->cronRun();
$this->drupalGet('admin/structure'); $this->drupalGet('admin/structure');
...@@ -267,7 +268,7 @@ class ReadinessValidationTest extends AutomaticUpdatesFunctionalTestBase { ...@@ -267,7 +268,7 @@ class ReadinessValidationTest extends AutomaticUpdatesFunctionalTestBase {
$assert->pageTextNotContains($expected_results['1:warnings']->getSummary()); $assert->pageTextNotContains($expected_results['1:warnings']->getSummary());
$expected_results = $this->testResults['checker_1']['2 warnings']; $expected_results = $this->testResults['checker_1']['2 warnings'];
TestChecker1::setTestResult($expected_results); TestChecker1::setTestResult($expected_results, ReadinessCheckEvent::class);
$this->delayRequestTime(); $this->delayRequestTime();
$this->cronRun(); $this->cronRun();
$this->drupalGet('admin/structure'); $this->drupalGet('admin/structure');
...@@ -281,7 +282,7 @@ class ReadinessValidationTest extends AutomaticUpdatesFunctionalTestBase { ...@@ -281,7 +282,7 @@ class ReadinessValidationTest extends AutomaticUpdatesFunctionalTestBase {
$assert->pageTextContainsOnce($expected_results[0]->getSummary()); $assert->pageTextContainsOnce($expected_results[0]->getSummary());
$expected_results = $this->testResults['checker_1']['1 warning']; $expected_results = $this->testResults['checker_1']['1 warning'];
TestChecker1::setTestResult($expected_results); TestChecker1::setTestResult($expected_results, ReadinessCheckEvent::class);
$this->delayRequestTime(); $this->delayRequestTime();
$this->cronRun(); $this->cronRun();
$this->drupalGet('admin/structure'); $this->drupalGet('admin/structure');
...@@ -311,7 +312,7 @@ class ReadinessValidationTest extends AutomaticUpdatesFunctionalTestBase { ...@@ -311,7 +312,7 @@ class ReadinessValidationTest extends AutomaticUpdatesFunctionalTestBase {
$this->assertNoErrors(TRUE); $this->assertNoErrors(TRUE);
$expected_results = $this->testResults['checker_1']['1 error']; $expected_results = $this->testResults['checker_1']['1 error'];
TestChecker2::setTestResult($expected_results); TestChecker2::setTestResult($expected_results, ReadinessCheckEvent::class);
$this->container->get('module_installer')->install(['automatic_updates_test2']); $this->container->get('module_installer')->install(['automatic_updates_test2']);
$this->drupalGet('admin/structure'); $this->drupalGet('admin/structure');
$assert->pageTextContainsOnce($expected_results[0]->getMessages()[0]); $assert->pageTextContainsOnce($expected_results[0]->getMessages()[0]);
...@@ -319,7 +320,7 @@ class ReadinessValidationTest extends AutomaticUpdatesFunctionalTestBase { ...@@ -319,7 +320,7 @@ class ReadinessValidationTest extends AutomaticUpdatesFunctionalTestBase {
// Confirm that installing a module that does not provide a new checker does // Confirm that installing a module that does not provide a new checker does
// not run the checkers on install. // not run the checkers on install.
$unexpected_results = $this->testResults['checker_1']['2 errors 2 warnings']; $unexpected_results = $this->testResults['checker_1']['2 errors 2 warnings'];
TestChecker2::setTestResult($unexpected_results); TestChecker2::setTestResult($unexpected_results, ReadinessCheckEvent::class);
$this->container->get('module_installer')->install(['help']); $this->container->get('module_installer')->install(['help']);
// Check for message on 'admin/structure' instead of the status report // Check for message on 'admin/structure' instead of the status report
// because checkers will be run if needed on the status report. // because checkers will be run if needed on the status report.
...@@ -339,9 +340,9 @@ class ReadinessValidationTest extends AutomaticUpdatesFunctionalTestBase { ...@@ -339,9 +340,9 @@ class ReadinessValidationTest extends AutomaticUpdatesFunctionalTestBase {
$this->drupalLogin($this->checkerRunnerUser); $this->drupalLogin($this->checkerRunnerUser);
$expected_results_1 = $this->testResults['checker_1']['1 error']; $expected_results_1 = $this->testResults['checker_1']['1 error'];
TestChecker1::setTestResult($expected_results_1); TestChecker1::setTestResult($expected_results_1, ReadinessCheckEvent::class);
$expected_results_2 = $this->testResults['checker_2']['1 error']; $expected_results_2 = $this->testResults['checker_2']['1 error'];
TestChecker2::setTestResult($expected_results_2); TestChecker2::setTestResult($expected_results_2, ReadinessCheckEvent::class);
$this->container->get('module_installer')->install([ $this->container->get('module_installer')->install([
'automatic_updates', 'automatic_updates',
'automatic_updates_test', 'automatic_updates_test',
......
...@@ -2,6 +2,7 @@ ...@@ -2,6 +2,7 @@
namespace Drupal\Tests\automatic_updates\Functional; namespace Drupal\Tests\automatic_updates\Functional;
use Drupal\automatic_updates\Event\ReadinessCheckEvent;
use Drupal\automatic_updates\Exception\UpdateException; use Drupal\automatic_updates\Exception\UpdateException;
use Drupal\package_manager\Event\PreCreateEvent; use Drupal\package_manager\Event\PreCreateEvent;
use Drupal\package_manager\ValidationResult; use Drupal\package_manager\ValidationResult;
...@@ -143,7 +144,7 @@ class UpdaterFormTest extends AutomaticUpdatesFunctionalTestBase { ...@@ -143,7 +144,7 @@ class UpdaterFormTest extends AutomaticUpdatesFunctionalTestBase {
// Store a fake readiness error, which will be cached. // Store a fake readiness error, which will be cached.
$message = t("You've not experienced Shakespeare until you have read him in the original Klingon."); $message = t("You've not experienced Shakespeare until you have read him in the original Klingon.");
$error = ValidationResult::createError([$message]); $error = ValidationResult::createError([$message]);
TestChecker1::setTestResult([$error]); TestChecker1::setTestResult([$error], ReadinessCheckEvent::class);
$this->drupalGet('/admin/reports/status'); $this->drupalGet('/admin/reports/status');
$page->clickLink('Run readiness checks'); $page->clickLink('Run readiness checks');
...@@ -158,7 +159,7 @@ class UpdaterFormTest extends AutomaticUpdatesFunctionalTestBase { ...@@ -158,7 +159,7 @@ class UpdaterFormTest extends AutomaticUpdatesFunctionalTestBase {
// Set up a new fake error. // Set up a new fake error.
$this->createTestValidationResults(); $this->createTestValidationResults();
$expected_results = $this->testResults['checker_1']['1 error']; $expected_results = $this->testResults['checker_1']['1 error'];
TestChecker1::setTestResult($expected_results); TestChecker1::setTestResult($expected_results, ReadinessCheckEvent::class);
// If a validator raises an error during readiness checking, the form should // If a validator raises an error during readiness checking, the form should
// not have a submit button. // not have a submit button.
...@@ -172,12 +173,12 @@ class UpdaterFormTest extends AutomaticUpdatesFunctionalTestBase { ...@@ -172,12 +173,12 @@ class UpdaterFormTest extends AutomaticUpdatesFunctionalTestBase {
$assert_session->pageTextContainsOnce(static::$errorsExplanation); $assert_session->pageTextContainsOnce(static::$errorsExplanation);
$assert_session->pageTextNotContains(static::$warningsExplanation); $assert_session->pageTextNotContains(static::$warningsExplanation);
$assert_session->pageTextNotContains((string) $message); $assert_session->pageTextNotContains((string) $message);
TestChecker1::setTestResult(NULL); TestChecker1::setTestResult(NULL, ReadinessCheckEvent::class);
// Repackage the validation error as an exception, so we can test what // Repackage the validation error as an exception, so we can test what
// happens if a validator throws once the update has started. // happens if a validator throws once the update has started.
$error = new UpdateException($expected_results, 'The update exploded.'); $error = new UpdateException($expected_results, 'The update exploded.');
TestChecker1::setTestResult($error, PreCreateEvent::class); TestChecker1::setException($error, PreCreateEvent::class);
$session->reload(); $session->reload();
$assert_session->pageTextNotContains(static::$errorsExplanation); $assert_session->pageTextNotContains(static::$errorsExplanation);
$assert_session->pageTextNotContains(static::$warningsExplanation); $assert_session->pageTextNotContains(static::$warningsExplanation);
......
...@@ -2,6 +2,7 @@ ...@@ -2,6 +2,7 @@
namespace Drupal\Tests\automatic_updates\Kernel\ReadinessValidation; namespace Drupal\Tests\automatic_updates\Kernel\ReadinessValidation;
use Drupal\automatic_updates\Event\ReadinessCheckEvent;
use Drupal\automatic_updates_test\ReadinessChecker\TestChecker1; use Drupal\automatic_updates_test\ReadinessChecker\TestChecker1;
use Drupal\automatic_updates_test2\ReadinessChecker\TestChecker2; use Drupal\automatic_updates_test2\ReadinessChecker\TestChecker2;
use Drupal\system\SystemManager; use Drupal\system\SystemManager;
...@@ -44,15 +45,14 @@ class ReadinessValidationManagerTest extends AutomaticUpdatesKernelTestBase { ...@@ -44,15 +45,14 @@ class ReadinessValidationManagerTest extends AutomaticUpdatesKernelTestBase {
array_pop($this->testResults['checker_1']), array_pop($this->testResults['checker_1']),
array_pop($this->testResults['checker_2']), array_pop($this->testResults['checker_2']),
]; ];
TestChecker1::setTestResult($expected_results[0]); TestChecker1::setTestResult($expected_results[0], ReadinessCheckEvent::class);
TestChecker2::setTestResult($expected_results[1]); TestChecker2::setTestResult($expected_results[1], ReadinessCheckEvent::class);
$expected_results_all = array_merge($expected_results[0], $expected_results[1]); $expected_results_all = array_merge($expected_results[0], $expected_results[1]);
$this->assertCheckerResultsFromManager($expected_results_all, TRUE); $this->assertCheckerResultsFromManager($expected_results_all, TRUE);
// Define a constant flag that will cause the readiness checker // Define a constant flag that will cause the readiness checker
// service priority to be altered. // service priority to be altered.
// @see \Drupal\automatic_updates_test\AutoUpdatesTestServiceProvider::alter(). define('PACKAGE_MANAGER_TEST_VALIDATOR_PRIORITY', 1);
define('AUTOMATIC_UPDATES_TEST_SET_PRIORITY', 1);
// Rebuild the container to trigger the service to be altered. // Rebuild the container to trigger the service to be altered.
$kernel = $this->container->get('kernel'); $kernel = $this->container->get('kernel');
$this->container = $kernel->rebuildContainer(); $this->container = $kernel->rebuildContainer();
...@@ -67,8 +67,8 @@ class ReadinessValidationManagerTest extends AutomaticUpdatesKernelTestBase { ...@@ -67,8 +67,8 @@ class ReadinessValidationManagerTest extends AutomaticUpdatesKernelTestBase {
$this->testResults['checker_1']['2 errors 2 warnings'], $this->testResults['checker_1']['2 errors 2 warnings'],
$this->testResults['checker_2']['2 errors 2 warnings'], $this->testResults['checker_2']['2 errors 2 warnings'],
]; ];
TestChecker1::setTestResult($expected_results[0]); TestChecker1::setTestResult($expected_results[0], ReadinessCheckEvent::class);
TestChecker2::setTestResult($expected_results[1]); TestChecker2::setTestResult($expected_results[1], ReadinessCheckEvent::class);
$expected_results_all = array_merge($expected_results[1], $expected_results[0]); $expected_results_all = array_merge($expected_results[1], $expected_results[0]);
$this->assertCheckerResultsFromManager($expected_results_all, TRUE); $this->assertCheckerResultsFromManager($expected_results_all, TRUE);
...@@ -91,7 +91,7 @@ class ReadinessValidationManagerTest extends AutomaticUpdatesKernelTestBase { ...@@ -91,7 +91,7 @@ class ReadinessValidationManagerTest extends AutomaticUpdatesKernelTestBase {
*/ */
public function testRunOnInstall(): void { public function testRunOnInstall(): void {
$expected_results = [array_pop($this->testResults['checker_1'])]; $expected_results = [array_pop($this->testResults['checker_1'])];
TestChecker1::setTestResult($expected_results[0]); TestChecker1::setTestResult($expected_results[0], ReadinessCheckEvent::class);
// Confirm that messages from an existing module are displayed when // Confirm that messages from an existing module are displayed when
// 'automatic_updates' is installed. // 'automatic_updates' is installed.
$this->container->get('module_installer')->install(['automatic_updates']); $this->container->get('module_installer')->install(['automatic_updates']);
...@@ -103,8 +103,8 @@ class ReadinessValidationManagerTest extends AutomaticUpdatesKernelTestBase { ...@@ -103,8 +103,8 @@ class ReadinessValidationManagerTest extends AutomaticUpdatesKernelTestBase {
array_pop($this->testResults['checker_1']), array_pop($this->testResults['checker_1']),
array_pop($this->testResults['checker_2']), array_pop($this->testResults['checker_2']),
]; ];
TestChecker1::setTestResult($expected_results[0]); TestChecker1::setTestResult($expected_results[0], ReadinessCheckEvent::class);
TestChecker2::setTestResult($expected_results[1]); TestChecker2::setTestResult($expected_results[1], ReadinessCheckEvent::class);
$this->container->get('module_installer')->install(['automatic_updates_test2']); $this->container->get('module_installer')->install(['automatic_updates_test2']);
$expected_results_all = array_merge($expected_results[0], $expected_results[1]); $expected_results_all = array_merge($expected_results[0], $expected_results[1]);
$this->assertCheckerResultsFromManager($expected_results_all); $this->assertCheckerResultsFromManager($expected_results_all);
...@@ -115,8 +115,8 @@ class ReadinessValidationManagerTest extends AutomaticUpdatesKernelTestBase { ...@@ -115,8 +115,8 @@ class ReadinessValidationManagerTest extends AutomaticUpdatesKernelTestBase {
array_pop($this->testResults['checker_1']), array_pop($this->testResults['checker_1']),
array_pop($this->testResults['checker_2']), array_pop($this->testResults['checker_2']),
]; ];
TestChecker1::setTestResult($unexpected_results[0]); TestChecker1::setTestResult($unexpected_results[0], ReadinessCheckEvent::class);
TestChecker2::setTestResult($unexpected_results[1]); TestChecker2::setTestResult($unexpected_results[1], ReadinessCheckEvent::class);
$this->container->get('module_installer')->install(['help']); $this->container->get('module_installer')->install(['help']);
$this->assertCheckerResultsFromManager($expected_results_all); $this->assertCheckerResultsFromManager($expected_results_all);
} }
...@@ -129,8 +129,8 @@ class ReadinessValidationManagerTest extends AutomaticUpdatesKernelTestBase { ...@@ -129,8 +129,8 @@ class ReadinessValidationManagerTest extends AutomaticUpdatesKernelTestBase {
array_pop($this->testResults['checker_1']), array_pop($this->testResults['checker_1']),
array_pop($this->testResults['checker_2']), array_pop($this->testResults['checker_2']),
]; ];
TestChecker1::setTestResult($expected_results[0]); TestChecker1::setTestResult($expected_results[0], ReadinessCheckEvent::class);
TestChecker2::setTestResult($expected_results[1]); TestChecker2::setTestResult($expected_results[1], ReadinessCheckEvent::class);
// Confirm that messages from existing modules are displayed when // Confirm that messages from existing modules are displayed when
// 'automatic_updates' is installed. // 'automatic_updates' is installed.
$this->container->get('module_installer')->install(['automatic_updates', 'automatic_updates_test2', 'help']); $this->container->get('module_installer')->install(['automatic_updates', 'automatic_updates_test2', 'help']);
...@@ -142,8 +142,8 @@ class ReadinessValidationManagerTest extends AutomaticUpdatesKernelTestBase { ...@@ -142,8 +142,8 @@ class ReadinessValidationManagerTest extends AutomaticUpdatesKernelTestBase {
$expected_results = [ $expected_results = [
array_pop($this->testResults['checker_1']), array_pop($this->testResults['checker_1']),
]; ];
TestChecker1::setTestResult($expected_results[0]); TestChecker1::setTestResult($expected_results[0], ReadinessCheckEvent::class);
TestChecker2::setTestResult(array_pop($this->testResults['checker_2'])); TestChecker2::setTestResult(array_pop($this->testResults['checker_2']), ReadinessCheckEvent::class);
$this->container->get('module_installer')->uninstall(['automatic_updates_test2']); $this->container->get('module_installer')->uninstall(['automatic_updates_test2']);
$this->assertCheckerResultsFromManager($expected_results[0]); $this->assertCheckerResultsFromManager($expected_results[0]);
...@@ -152,7 +152,7 @@ class ReadinessValidationManagerTest extends AutomaticUpdatesKernelTestBase { ...@@ -152,7 +152,7 @@ class ReadinessValidationManagerTest extends AutomaticUpdatesKernelTestBase {
$unexpected_results = [ $unexpected_results = [
array_pop($this->testResults['checker_1']), array_pop($this->testResults['checker_1']),
]; ];
TestChecker1::setTestResult($unexpected_results[0]); TestChecker1::setTestResult($unexpected_results[0], ReadinessCheckEvent::class);
$this->container->get('module_installer')->uninstall(['help']); $this->container->get('module_installer')->uninstall(['help']);
$this->assertCheckerResultsFromManager($expected_results[0]); $this->assertCheckerResultsFromManager($expected_results[0]);
} }
...@@ -162,12 +162,12 @@ class ReadinessValidationManagerTest extends AutomaticUpdatesKernelTestBase { ...@@ -162,12 +162,12 @@ class ReadinessValidationManagerTest extends AutomaticUpdatesKernelTestBase {
*/ */
public function testRunIfNeeded(): void { public function testRunIfNeeded(): void {
$expected_results = array_pop($this->testResults['checker_1']); $expected_results = array_pop($this->testResults['checker_1']);
TestChecker1::setTestResult($expected_results); TestChecker1::setTestResult($expected_results, ReadinessCheckEvent::class);
$this->container->get('module_installer')->install(['automatic_updates', 'automatic_updates_test2']); $this->container->get('module_installer')->install(['automatic_updates', 'automatic_updates_test2']);
$this->assertCheckerResultsFromManager($expected_results); $this->assertCheckerResultsFromManager($expected_results);
$unexpected_results = array_pop($this->testResults['checker_1']); $unexpected_results = array_pop($this->testResults['checker_1']);
TestChecker1::setTestResult($unexpected_results); TestChecker1::setTestResult($unexpected_results, ReadinessCheckEvent::class);
$manager = $this->container->get('automatic_updates.readiness_validation_manager'); $manager = $this->container->get('automatic_updates.readiness_validation_manager');
// Confirm that the new results will not be returned because the checkers // Confirm that the new results will not be returned because the checkers
// will not be run. // will not be run.
...@@ -185,7 +185,7 @@ class ReadinessValidationManagerTest extends AutomaticUpdatesKernelTestBase { ...@@ -185,7 +185,7 @@ class ReadinessValidationManagerTest extends AutomaticUpdatesKernelTestBase {
// Confirm that the results are the same after rebuilding the container. // Confirm that the results are the same after rebuilding the container.
$unexpected_results = array_pop($this->testResults['checker_1']); $unexpected_results = array_pop($this->testResults['checker_1']);
TestChecker1::setTestResult($unexpected_results); TestChecker1::setTestResult($unexpected_results, ReadinessCheckEvent::class);
/** @var \Drupal\Core\DrupalKernel $kernel */ /** @var \Drupal\Core\DrupalKernel $kernel */
$kernel = $this->container->get('kernel'); $kernel = $this->container->get('kernel');
$this->container = $kernel->rebuildContainer(); $this->container = $kernel->rebuildContainer();
...@@ -197,8 +197,7 @@ class ReadinessValidationManagerTest extends AutomaticUpdatesKernelTestBase { ...@@ -197,8 +197,7 @@ class ReadinessValidationManagerTest extends AutomaticUpdatesKernelTestBase {
// higher than 'automatic_updates_test2.checker' which has a priority of 3. // higher than 'automatic_updates_test2.checker' which has a priority of 3.
// Because the list of checker IDs is not identical to the previous checker // Because the list of checker IDs is not identical to the previous checker
// run runIfNoStoredValidResults() will run the checkers again. // run runIfNoStoredValidResults() will run the checkers again.
// @see \Drupal\automatic_updates_test\AutoUpdatesTestServiceProvider::alter(). define('PACKAGE_MANAGER_TEST_VALIDATOR_PRIORITY', 1);
define('AUTOMATIC_UPDATES_TEST_SET_PRIORITY', 1);
// Rebuild the container to trigger the readiness checker services to be // Rebuild the container to trigger the readiness checker services to be
// reordered. // reordered.
......
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