function FloodTest::testCleanUp
Same name in other branches
- 9 core/modules/system/tests/src/Kernel/System/FloodTest.php \Drupal\Tests\system\Kernel\System\FloodTest::testCleanUp()
- 8.9.x core/modules/system/tests/src/Kernel/System/FloodTest.php \Drupal\Tests\system\Kernel\System\FloodTest::testCleanUp()
- 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 27
Class
- FloodTest
- Functional tests for the flood control mechanism.
Namespace
Drupal\Tests\system\Kernel\SystemCode
public function testCleanUp() : void {
$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.