public function CaptchaCronTest::testCron in CAPTCHA 8
Test CAPTCHA cron.
File
- tests/
src/ Functional/ CaptchaCronTest.php, line 87
Class
- CaptchaCronTest
- Tests CAPTCHA cron.
Namespace
Drupal\Tests\captcha\FunctionalCode
public function testCron() {
\Drupal::service('cron')
->run();
$connection = Database::getConnection();
$sids = $connection
->select('captcha_sessions')
->fields('captcha_sessions', [
'csid',
])
->condition('csid', array_values($this->captchaSessions), 'IN')
->execute()
->fetchCol('csid');
// Test if CAPTCHA cron appropriately removes sessions older than a day.
$this
->assertNotContains($this->captchaSessions['remove_sid'], $sids, 'CAPTCHA cron removes captcha session data older than 1 day.');
// Test if CAPTCHA cron appropriately keeps sessions younger than a day.
$this
->assertContains($this->captchaSessions['remain_sid'], $sids, 'CAPTCHA cron does not remove captcha session data younger than 1 day.');
}