function AutomatedCronTest::testRunsCronOnHttpRequest

Same name and namespace in other branches
  1. main core/modules/automated_cron/tests/src/Kernel/AutomatedCronTest.php \Drupal\Tests\automated_cron\Kernel\AutomatedCronTest::testRunsCronOnHttpRequest()

Tests that automated cron runs cron on an HTTP request.

@legacy-covers \Drupal\automated_cron\EventSubscriber\AutomatedCron::onTerminate

File

core/modules/automated_cron/tests/src/Functional/AutomatedCronTest.php, line 36

Class

AutomatedCronTest
Tests for automated_cron.

Namespace

Drupal\Tests\automated_cron\Functional

Code

public function testRunsCronOnHttpRequest() : void {
  // Set automated_cron interval and times.
  // Any interval > 0 should work.
  $this->config('automated_cron.settings')
    ->set('interval', 10800)
    ->save();
  \Drupal::state()->delete('system.cron_last');
  $this->assertNull(\Drupal::state()->get('system.cron_last'));
  $this->assertNotNull($_SERVER['REQUEST_TIME']);
  $this->setWaitForTerminate();
  $this->drupalGet('/user/login');
  $this->assertGreaterThanOrEqual($_SERVER['REQUEST_TIME'], \Drupal::state()->get('system.cron_last'));
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.