You are here

public function BlockedIpsExpireHelpers::testGetUnassigned in Blocked IPs Expire 7

Tests that the helper function to get all IPs without expiry dates works.

@covers _blocked_ips_expire_get_unassigned()

File

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

Class

BlockedIpsExpireHelpers
Tests that helper functions are operating correctly.

Code

public function testGetUnassigned() {

  // Simulate core before this module was installed by adding an IP address
  // without an expiry time.
  $iid = BlockedIpsExpireHelpers::addIpWithoutExpiryTime($this->anyOldIp);

  // Verify _blocked_ips_expire_get_unassigned()'s count query works.
  $num_unassigned_ips = _blocked_ips_expire_get_unassigned(TRUE);
  $this
    ->assertEqual($num_unassigned_ips, 1, 'One unassigned IP address in database.');

  // Verify _blocked_ips_expire_get_unassigned() query returns the IP we
  // added.
  $unassigned_ips = _blocked_ips_expire_get_unassigned();
  $this
    ->assertTrue(array_key_exists($iid, $unassigned_ips), 'The IID we got when adding the IP is a key in the result set.');
  $ip_info = $unassigned_ips[$iid];
  $this
    ->assertEqual($ip_info->ip, $this->anyOldIp, 'IP returned matches what we put in.');
  $this
    ->assertNull($ip_info->expiry_date, 'Expiry date of unassigned IP address is null.');
}