AutomatedCronTest.php
Same filename in this branch
Same filename and directory in other branches
Namespace
Drupal\Tests\automated_cron\FunctionalFile
-
core/
modules/ automated_cron/ tests/ src/ Functional/ AutomatedCronTest.php
View source
<?php
declare (strict_types=1);
namespace Drupal\Tests\automated_cron\Functional;
use Drupal\automated_cron\EventSubscriber\AutomatedCron;
use Drupal\Tests\BrowserTestBase;
use Drupal\Tests\WaitTerminateTestTrait;
use PHPUnit\Framework\Attributes\CoversClass;
use PHPUnit\Framework\Attributes\Group;
use PHPUnit\Framework\Attributes\RunTestsInSeparateProcesses;
/**
* Tests for automated_cron.
*/
class AutomatedCronTest extends BrowserTestBase {
use WaitTerminateTestTrait;
/**
* {@inheritdoc}
*/
protected $defaultTheme = 'stark';
/**
* Tests that automated cron runs cron on an HTTP request.
*/
public function testRunsCronOnHttpRequest() : void {
// Install cron manually to avoid test setup making an HTTP request which
// would trigger cron to run before the test starts.
\Drupal::service('module_installer')->install([
'automated_cron',
]);
// Set automated_cron interval and times.
// Any interval > 0 should work.
$this->config('automated_cron.settings')
->set('interval', 10800)
->save();
$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'));
}
}
Classes
| Title | Deprecated | Summary |
|---|---|---|
| AutomatedCronTest | Tests for automated_cron. |
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.