function Fix404RedirectCronJobTest::testRedirect404CronJobKeepAllButOne in Redirect 8
Tests adding rows and deleting one row from redirect_404 table.
File
- modules/
redirect_404/ tests/ src/ Kernel/ Fix404RedirectCronJobTest.php, line 81
Class
- Fix404RedirectCronJobTest
- Tests the clean up cron job for redirect_404.
Namespace
Drupal\Tests\redirect_404\KernelCode
function testRedirect404CronJobKeepAllButOne() {
// Set the limit to 5 just for the test.
\Drupal::configFactory()
->getEditable('redirect_404.settings')
->set('row_limit', 5)
->save();
// Check that there are 6 rows in the redirect_404 table.
$result = Database::getConnection()
->query("SELECT COUNT(*) FROM {redirect_404}")
->fetchField();
$this
->assertEquals(6, $result);
// Run cron to drop just 1 row from the redirect_404 test table.
redirect_404_cron();
$result = Database::getConnection()
->query("SELECT COUNT(*) FROM {redirect_404}")
->fetchField();
$this
->assertEquals(5, $result);
// Check only the row with least count has been removed from the table.
if (\Drupal::database()
->driver() == 'mysql' || \Drupal::database()
->driver() == 'pgsql') {
$this
->assert404Row('/test1');
$this
->assert404Row('/test2');
$this
->assert404Row('/test3');
$this
->assert404Row('/test4');
$this
->assert404Row('/test5');
$this
->assertNo404Row('/test6');
}
else {
// In SQlite, only the oldest row is deleted.
$this
->assert404Row('/test1');
$this
->assert404Row('/test2');
$this
->assert404Row('/test3');
$this
->assertNo404Row('/test4');
$this
->assert404Row('/test5');
$this
->assert404Row('/test6');
}
}