function CronRunTest::testCronRun

Same name and namespace in other branches
  1. 9 core/modules/system/tests/src/Functional/System/CronRunTest.php \Drupal\Tests\system\Functional\System\CronRunTest::testCronRun()
  2. 8.9.x core/modules/system/tests/src/Functional/System/CronRunTest.php \Drupal\Tests\system\Functional\System\CronRunTest::testCronRun()
  3. 10 core/modules/system/tests/src/Functional/System/CronRunTest.php \Drupal\Tests\system\Functional\System\CronRunTest::testCronRun()

Tests cron runs.

File

core/modules/system/tests/src/Functional/System/CronRunTest.php, line 40

Class

CronRunTest
Tests cron runs.

Namespace

Drupal\Tests\system\Functional\System

Code

public function testCronRun() : void {
    // Run cron anonymously without any cron key.
    $this->drupalGet('cron');
    $this->assertSession()
        ->statusCodeEquals(404);
    // Run cron anonymously with a random cron key.
    $key = $this->randomMachineName(16);
    $this->drupalGet('cron/' . $key);
    $this->assertSession()
        ->statusCodeEquals(403);
    // Run cron anonymously with the valid cron key.
    $key = \Drupal::state()->get('system.cron_key');
    $this->drupalGet('cron/' . $key);
    $this->assertSession()
        ->statusCodeEquals(204);
}

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