You are here

public function BlockedIpsExpireCron::testCronRemovesExpiredIpAddresses in Blocked IPs Expire 7

Test that running cron removes expired IP addresses.

File

tests/blocked_ips_expire.cron.test, line 103
Contains \BlockedIpsExpireCron.

Class

BlockedIpsExpireCron
Tests that expired IPs will be unblocked on cron run.

Code

public function testCronRemovesExpiredIpAddresses() {

  // Create an IP address that expired in the past and an IP address that will
  // expire in the future.
  _blocked_ips_expire_add_ip($this->expiredIpAddress, $this->expiredDate);
  _blocked_ips_expire_add_ip($this->notYetExpiredIpAddress, $this->notYetExpiredDate);

  // Check that the IP addresses exist beforehand.
  $in_db = BlockedIpsExpireCron::isIpInDatabase($this->expiredIpAddress);
  $this
    ->assertTrue($in_db, 'Expired IP in database before cron run.');
  $in_db = BlockedIpsExpireCron::isIpInDatabase($this->notYetExpiredIpAddress);
  $this
    ->assertTrue($in_db, 'Not-yet-expired IP in database before cron run.');

  // Run cron.
  $this
    ->cronRun();

  // Test that the IP addresses that expired before cron was run have been
  // deleted.
  $in_db = BlockedIpsExpireCron::isIpInDatabase($this->expiredIpAddress);
  $this
    ->assertFalse($in_db, 'Expired IP not in database after cron run.');

  // Test that the IP addresses that expire after cron was run are still
  // there.
  $in_db = BlockedIpsExpireCron::isIpInDatabase($this->notYetExpiredIpAddress);
  $this
    ->assertTrue($in_db, 'Not-yet-expired IP in database after cron run.');
}