You are here

public function FloodTest::testFlood in Service Container 7

Same name and namespace in other branches
  1. 7.2 lib/Drupal/service_container/Tests/FloodTest.php \Drupal\service_container\Tests\FloodTest::testFlood()

The the flood mechanisms.

File

lib/Drupal/service_container/Tests/FloodTest.php, line 33
Contains \Drupal\service_container\Tests\FloodTest.

Class

FloodTest

Namespace

Drupal\service_container\Tests

Code

public function testFlood() {
  $threshold = 1;
  $window_expired = -1;
  $name = 'flood_test';

  // Register expired event.
  \Drupal::service('flood')
    ->register($name, $window_expired);
  $this
    ->assertFalse(\Drupal::service('flood')
    ->isAllowed($name, $threshold));
  $this
    ->cronRun();
  $this
    ->assertTrue(\Drupal::service('flood')
    ->isAllowed($name, $threshold));

  // Register unexpired event.
  \Drupal::service('flood')
    ->register($name);
  $this
    ->assertFalse(\Drupal::service('flood')
    ->isAllowed($name, $threshold));
  $this
    ->cronRun();
  $this
    ->assertFalse(\Drupal::service('flood')
    ->isAllowed($name, $threshold));
}