You are here

public function FloodTest::testCleanUp in Drupal 10

Same name and namespace in other branches
  1. 8 core/modules/system/tests/src/Kernel/System/FloodTest.php \Drupal\Tests\system\Kernel\System\FloodTest::testCleanUp()
  2. 9 core/modules/system/tests/src/Kernel/System/FloodTest.php \Drupal\Tests\system\Kernel\System\FloodTest::testCleanUp()

Tests flood control mechanism clean-up.

File

core/modules/system/tests/src/Kernel/System/FloodTest.php, line 24

Class

FloodTest
Functional tests for the flood control mechanism.

Namespace

Drupal\Tests\system\Kernel\System

Code

public function testCleanUp() {
  $threshold = 1;
  $window_expired = -1;
  $name = 'flood_test_cleanup';
  $cron = $this->container
    ->get('cron');
  $flood = \Drupal::flood();
  $this
    ->assertTrue($flood
    ->isAllowed($name, $threshold));

  // Register expired event.
  $flood
    ->register($name, $window_expired);

  // Verify event is not allowed.
  $this
    ->assertFalse($flood
    ->isAllowed($name, $threshold));

  // Run cron and verify event is now allowed.
  $cron
    ->run();
  $this
    ->assertTrue($flood
    ->isAllowed($name, $threshold));

  // Register unexpired event.
  $flood
    ->register($name);

  // Verify event is not allowed.
  $this
    ->assertFalse($flood
    ->isAllowed($name, $threshold));

  // Run cron and verify event is still not allowed.
  $cron
    ->run();
  $this
    ->assertFalse($flood
    ->isAllowed($name, $threshold));
}