You are here

public function CronRunTest::testCronRun in Drupal 9

Same name and namespace in other branches
  1. 8 core/modules/system/tests/src/Functional/System/CronRunTest.php \Drupal\Tests\system\Functional\System\CronRunTest::testCronRun()
  2. 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 36

Class

CronRunTest
Tests cron runs.

Namespace

Drupal\Tests\system\Functional\System

Code

public function testCronRun() {

  // 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);
}