function FloodTest::testCleanUp in MongoDB 8
Test flood control mechanism clean-up.
File
- src/
Tests/ FloodTest.php, line 37 - Definition of rupal\mongodb\Tests\FloodTest.
Class
- FloodTest
- Functional tests for the flood control mechanism.
Namespace
Drupal\mongodb\TestsCode
function testCleanUp() {
$threshold = 1;
$window_expired = -1;
$name = 'flood_test_cleanup';
$flood = \Drupal::service('flood');
$collection = \Drupal::service('mongo')
->get('flood');
// Register expired event.
$flood
->register($name, $window_expired);
// Verify event is in Mongo..
$this
->assertTrue($collection
->count(array(
'event' => $name,
)));
// Run cron and verify event is now allowed.
$this
->assertTrue($flood
->isAllowed($name, $threshold));
$collection
->remove(array(
'event' => $name,
));
// Register unexpired event.
$flood
->register($name);
// Check expiration time of new item.
$item = $collection
->find(array(
'event' => $name,
))
->getNext();
$this
->assertTrue($item['expiration'] == REQUEST_TIME + 3600);
// Verify event is not allowed.
$this
->assertFalse($flood
->isAllowed($name, $threshold));
}