function MemoryBackendTest::testExpiring

Same name and namespace in other branches
  1. 9 core/tests/Drupal/Tests/Core/Flood/MemoryBackendTest.php \Drupal\Tests\Core\Flood\MemoryBackendTest::testExpiring()
  2. 11.x core/tests/Drupal/Tests/Core/Flood/MemoryBackendTest.php \Drupal\Tests\Core\Flood\MemoryBackendTest::testExpiring()

Tests a flood event with expiring, so cron will allow to proceed.

@medium

File

core/tests/Drupal/Tests/Core/Flood/MemoryBackendTest.php, line 68

Class

MemoryBackendTest
Tests the memory flood implementation.

Namespace

Drupal\Tests\Core\Flood

Code

public function testExpiring() : void {
  $threshold = 1;
  $window_expired = -1;
  $this->flood
    ->register('test_event', $window_expired);
  usleep(2);
  $this->flood
    ->register('test_event', $window_expired);
  $this->assertFalse($this->flood
    ->isAllowed('test_event', $threshold));
  // "Run cron", which clears the flood data and verify event is now allowed.
  $this->flood
    ->garbageCollection();
  $this->assertTrue($this->flood
    ->isAllowed('test_event', $threshold));
}

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