function FloodTest::testCleanUp

Same name in other branches
  1. 8.9.x core/modules/system/tests/src/Kernel/System/FloodTest.php \Drupal\Tests\system\Kernel\System\FloodTest::testCleanUp()
  2. 10 core/modules/system/tests/src/Kernel/System/FloodTest.php \Drupal\Tests\system\Kernel\System\FloodTest::testCleanUp()
  3. 11.x 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 23

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

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