Skip to content
Snippets Groups Projects

Issue #3374753: Run status whenever cron is run

Files
2
@@ -7,7 +7,6 @@ namespace Drupal\Tests\automatic_updates\Functional;
@@ -7,7 +7,6 @@ namespace Drupal\Tests\automatic_updates\Functional;
use Behat\Mink\Element\NodeElement;
use Behat\Mink\Element\NodeElement;
use Drupal\automatic_updates\CronUpdateStage;
use Drupal\automatic_updates\CronUpdateStage;
use Drupal\automatic_updates\StatusCheckMailer;
use Drupal\automatic_updates\StatusCheckMailer;
use Drupal\automatic_updates_test\Datetime\TestTime;
use Drupal\automatic_updates_test\EventSubscriber\TestSubscriber1;
use Drupal\automatic_updates_test\EventSubscriber\TestSubscriber1;
use Drupal\automatic_updates_test_status_checker\EventSubscriber\TestSubscriber2;
use Drupal\automatic_updates_test_status_checker\EventSubscriber\TestSubscriber2;
use Drupal\Core\Url;
use Drupal\Core\Url;
@@ -142,8 +141,6 @@ class StatusCheckTest extends AutomaticUpdatesFunctionalTestBase {
@@ -142,8 +141,6 @@ class StatusCheckTest extends AutomaticUpdatesFunctionalTestBase {
// Confirm a user without the permission to run status checks does not
// Confirm a user without the permission to run status 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.
// @todo Change this to fake the request time in
// https://www.drupal.org/node/3113971.
/** @var \Drupal\Core\KeyValueStore\KeyValueStoreInterface $key_value */
/** @var \Drupal\Core\KeyValueStore\KeyValueStoreInterface $key_value */
$key_value = $this->container->get('keyvalue.expirable')->get('automatic_updates');
$key_value = $this->container->get('keyvalue.expirable')->get('automatic_updates');
$key_value->delete('status_check_last_run');
$key_value->delete('status_check_last_run');
@@ -247,7 +244,7 @@ class StatusCheckTest extends AutomaticUpdatesFunctionalTestBase {
@@ -247,7 +244,7 @@ class StatusCheckTest extends AutomaticUpdatesFunctionalTestBase {
}
}
/**
/**
* Tests status check results on admin pages..
* Tests status check results on admin pages.
*
*
* @param string $admin_route
* @param string $admin_route
* The admin route to check.
* The admin route to check.
@@ -271,9 +268,6 @@ class StatusCheckTest extends AutomaticUpdatesFunctionalTestBase {
@@ -271,9 +268,6 @@ class StatusCheckTest extends AutomaticUpdatesFunctionalTestBase {
// a link to run the checks when the checks need to be run again.
// a link to run the checks when the checks need to be run again.
$expected_results = [$this->createValidationResult(SystemManager::REQUIREMENT_ERROR)];
$expected_results = [$this->createValidationResult(SystemManager::REQUIREMENT_ERROR)];
TestSubscriber1::setTestResult($expected_results, StatusCheckEvent::class);
TestSubscriber1::setTestResult($expected_results, StatusCheckEvent::class);
// @todo Change this to use ::delayRequestTime() to simulate running cron
// after a 24 wait instead of directly deleting 'status_check_last_run'
// https://www.drupal.org/node/3113971.
/** @var \Drupal\Core\KeyValueStore\KeyValueStoreInterface $key_value */
/** @var \Drupal\Core\KeyValueStore\KeyValueStoreInterface $key_value */
$key_value = $this->container->get('keyvalue.expirable')->get('automatic_updates');
$key_value = $this->container->get('keyvalue.expirable')->get('automatic_updates');
$key_value->delete('status_check_last_run');
$key_value->delete('status_check_last_run');
@@ -297,9 +291,7 @@ class StatusCheckTest extends AutomaticUpdatesFunctionalTestBase {
@@ -297,9 +291,7 @@ class StatusCheckTest extends AutomaticUpdatesFunctionalTestBase {
'1 warning' => $this->createValidationResult(SystemManager::REQUIREMENT_WARNING),
'1 warning' => $this->createValidationResult(SystemManager::REQUIREMENT_WARNING),
];
];
TestSubscriber1::setTestResult($expected_results, StatusCheckEvent::class);
TestSubscriber1::setTestResult($expected_results, StatusCheckEvent::class);
// Confirm a new message is displayed if the cron is run after an hour.
$this->runStatusChecks();
$this->delayRequestTime();
$this->cronRun();
$this->drupalGet(Url::fromRoute($admin_route));
$this->drupalGet(Url::fromRoute($admin_route));
$assert->pageTextContainsOnce(static::$errorsExplanation);
$assert->pageTextContainsOnce(static::$errorsExplanation);
// Confirm on admin pages that the summary will be displayed.
// Confirm on admin pages that the summary will be displayed.
@@ -311,25 +303,22 @@ class StatusCheckTest extends AutomaticUpdatesFunctionalTestBase {
@@ -311,25 +303,22 @@ class StatusCheckTest extends AutomaticUpdatesFunctionalTestBase {
$assert->pageTextNotContains($expected_results['1 warning']->messages[0]);
$assert->pageTextNotContains($expected_results['1 warning']->messages[0]);
$assert->pageTextNotContains($expected_results['1 warning']->summary);
$assert->pageTextNotContains($expected_results['1 warning']->summary);
// Confirm that if cron runs less than hour after it previously ran it will
// Confirm the status check event is not dispatched on every admin page
// not run the checkers again.
// load.
$unexpected_results = [
$unexpected_results = [
'2 errors' => $this->createValidationResult(SystemManager::REQUIREMENT_ERROR, 2),
'2 errors' => $this->createValidationResult(SystemManager::REQUIREMENT_ERROR, 2),
'2 warnings' => $this->createValidationResult(SystemManager::REQUIREMENT_WARNING, 2),
'2 warnings' => $this->createValidationResult(SystemManager::REQUIREMENT_WARNING, 2),
];
];
TestSubscriber1::setTestResult($unexpected_results, StatusCheckEvent::class);
TestSubscriber1::setTestResult($unexpected_results, StatusCheckEvent::class);
$this->delayRequestTime(30);
$this->cronRun();
$this->drupalGet(Url::fromRoute($admin_route));
$this->drupalGet(Url::fromRoute($admin_route));
$assert->pageTextNotContains($unexpected_results['2 errors']->summary);
$assert->pageTextNotContains($unexpected_results['2 errors']->summary);
$assert->pageTextContainsOnce((string) $expected_results['1 error']->summary);
$assert->pageTextContainsOnce((string) $expected_results['1 error']->summary);
$assert->pageTextNotContains($unexpected_results['2 warnings']->summary);
$assert->pageTextNotContains($unexpected_results['2 warnings']->summary);
$assert->pageTextNotContains($expected_results['1 warning']->messages[0]);
$assert->pageTextNotContains($expected_results['1 warning']->messages[0]);
// Confirm that is if cron is run over an hour after the checkers were
// Confirm the updated results will be shown when status checks are run
// previously run the checkers will be run again.
// again.
$this->delayRequestTime(31);
$this->runStatusChecks();
$this->cronRun();
$expected_results = $unexpected_results;
$expected_results = $unexpected_results;
$this->drupalGet(Url::fromRoute($admin_route));
$this->drupalGet(Url::fromRoute($admin_route));
// Confirm on admin pages only the error summary will be displayed if there
// Confirm on admin pages only the error summary will be displayed if there
@@ -347,8 +336,7 @@ class StatusCheckTest extends AutomaticUpdatesFunctionalTestBase {
@@ -347,8 +336,7 @@ class StatusCheckTest extends AutomaticUpdatesFunctionalTestBase {
$expected_results = [$this->createValidationResult(SystemManager::REQUIREMENT_WARNING, 2)];
$expected_results = [$this->createValidationResult(SystemManager::REQUIREMENT_WARNING, 2)];
TestSubscriber1::setTestResult($expected_results, StatusCheckEvent::class);
TestSubscriber1::setTestResult($expected_results, StatusCheckEvent::class);
$this->delayRequestTime();
$this->runStatusChecks();
$this->cronRun();
$this->drupalGet(Url::fromRoute($admin_route));
$this->drupalGet(Url::fromRoute($admin_route));
// Confirm that the warnings summary is displayed on admin pages if there
// Confirm that the warnings summary is displayed on admin pages if there
// are no errors.
// are no errors.
@@ -361,8 +349,7 @@ class StatusCheckTest extends AutomaticUpdatesFunctionalTestBase {
@@ -361,8 +349,7 @@ class StatusCheckTest extends AutomaticUpdatesFunctionalTestBase {
$expected_results = [$this->createValidationResult(SystemManager::REQUIREMENT_WARNING)];
$expected_results = [$this->createValidationResult(SystemManager::REQUIREMENT_WARNING)];
TestSubscriber1::setTestResult($expected_results, StatusCheckEvent::class);
TestSubscriber1::setTestResult($expected_results, StatusCheckEvent::class);
$this->delayRequestTime();
$this->runStatusChecks();
$this->cronRun();
$this->drupalGet(Url::fromRoute($admin_route));
$this->drupalGet(Url::fromRoute($admin_route));
$assert->pageTextNotContains(static::$errorsExplanation);
$assert->pageTextNotContains(static::$errorsExplanation);
// Confirm that a single warning is displayed and not the summary on admin
// Confirm that a single warning is displayed and not the summary on admin
@@ -761,15 +748,11 @@ class StatusCheckTest extends AutomaticUpdatesFunctionalTestBase {
@@ -761,15 +748,11 @@ class StatusCheckTest extends AutomaticUpdatesFunctionalTestBase {
}
}
/**
/**
* Delays the request for the test.
* Runs status checks.
*
* @param int $minutes
* The number of minutes to delay request time. Defaults to 61 minutes.
*/
*/
private function delayRequestTime(int $minutes = 61): void {
private function runStatusChecks(): void {
static $total_delay = 0;
$this->drupalGet('/admin/reports/status');
$total_delay += $minutes;
$this->clickLink('Rerun readiness checks');
TestTime::setFakeTimeByOffset("+$total_delay minutes");
}
}
}
}
Loading