You are here

public function BlockedIpsExpireHelpers::testGetExpired in Blocked IPs Expire 7

Tests that the helper function to get expired IPs works.

@covers _blocked_ips_expire_get_expired()

File

tests/blocked_ips_expire.helpers.test, line 106
Contains \BlockedIpsExpireHelpers.

Class

BlockedIpsExpireHelpers
Tests that helper functions are operating correctly.

Code

public function testGetExpired() {

  // Add the IP addresses to the database.
  $stale_iid = _blocked_ips_expire_add_ip($this->staleIp, $this->staleDate);
  $fresh_iid = _blocked_ips_expire_add_ip($this->freshIp, $this->freshDate);

  // Test that the count function works.
  $num_stale_ips = _blocked_ips_expire_get_expired(TRUE);
  $this
    ->assertEqual($num_stale_ips, 1, 'One stale IP in database.');

  // Get the list of expired IPs.
  $stale_ips = _blocked_ips_expire_get_expired();

  // Test that the fresh IP is not in the resultset and that the stale IP is.
  $this
    ->assertTrue(array_key_exists($stale_iid, $stale_ips), 'Stale IP in list of expired IPs.');
  $this
    ->assertFalse(array_key_exists($fresh_iid, $stale_ips), 'Fresh IP not in list of expired IPs.');

  // Test that the stale IP has the values we put in.
  $ip_info = $stale_ips[$stale_iid];
  $this
    ->assertEqual($ip_info->ip, $this->staleIp, 'Stale IP address matches what we put in.');
  $this
    ->assertEqual($ip_info->expiry_date, $this->staleDate, 'Stale expiry date matches what we put in.');
}