function FloodTest::testClearByPrefix
Tests clearByPrefix method on flood backends.
File
- 
              core/
modules/ system/ tests/ src/ Kernel/ System/ FloodTest.php, line 99  
Class
- FloodTest
 - Functional tests for the flood control mechanism.
 
Namespace
Drupal\Tests\system\Kernel\SystemCode
public function testClearByPrefix() : void {
  $threshold = 1;
  $window_expired = 3600;
  $identifier = 'prefix-127.0.0.1';
  $name = 'flood_test_cleanup';
  // We can't use an PHPUnit data provider because we need access to the
  // container.
  $backends = $this->floodBackendProvider();
  foreach ($backends as $backend) {
    // Register unexpired event.
    $backend->register($name, $window_expired, $identifier);
    // Verify event is not allowed.
    $this->assertFalse($backend->isAllowed($name, $threshold, $window_expired, $identifier));
    // Clear by prefix and verify event is now allowed.
    $backend->clearByPrefix($name, 'prefix');
    $this->assertTrue($backend->isAllowed($name, $threshold));
  }
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.