You are here

public function SchedulerLightweightCronTest::testLightweightCronRun in Scheduler 8

Same name and namespace in other branches
  1. 2.x tests/src/Functional/SchedulerLightweightCronTest.php \Drupal\Tests\scheduler\Functional\SchedulerLightweightCronTest::testLightweightCronRun()

Test scheduler lightweight cron runs.

File

tests/src/Functional/SchedulerLightweightCronTest.php, line 26

Class

SchedulerLightweightCronTest
Tests the Scheduler lightweight cron urls and admin form.

Namespace

Drupal\Tests\scheduler\Functional

Code

public function testLightweightCronRun() {

  // Run scheduler lightweight cron anonymously without any cron key.
  // The response with no key should be "404 Not Found".
  $this
    ->drupalGet('scheduler/cron');
  $this
    ->assertSession()
    ->statusCodeEquals(404);

  // Run scheduler lightweight cron anonymously with a random cron key.
  // The response for an incorrect key should be "403 Access Denied".
  $key = substr(md5(rand()), 0, 20);
  $this
    ->drupalGet('scheduler/cron/' . $key);
  $this
    ->assertSession()
    ->statusCodeEquals(403);

  // Run scheduler lightweight cron anonymously with the valid cron key which
  // is defined during install. It should run OK but no content will be
  // produced so the response should be "204 No Content".
  $config = $this
    ->config('scheduler.settings');
  $key = $config
    ->get('lightweight_cron_access_key');
  $this
    ->drupalGet('scheduler/cron/' . $key);
  $this
    ->assertSession()
    ->statusCodeEquals(204);
}