public function BlockedIpsExpireHelpers::testAddCurrentIp in Blocked IPs Expire 7
Tests that the current address is blocked if not specified.
@covers _blocked_ips_expire_add_ip()
File
- tests/
blocked_ips_expire.helpers.test, line 224 - Contains \BlockedIpsExpireHelpers.
Class
- BlockedIpsExpireHelpers
- Tests that helper functions are operating correctly.
Code
public function testAddCurrentIp() {
// Some variables we will use in this test case.
$current_ip = ip_address();
$expiry_date = BlockedIpsExpireHelpers::randomDatetimeInFuture();
// Ensure the current IP is not in the database to start with.
$num_times_in_db = BlockedIpsExpireHelpers::numberTimesIpInDatabase($current_ip);
$this
->assertTrue($num_times_in_db <= 0, 'Current IP is not in database yet.');
// Block the IP, with default IP address values so it uses the current IP.
$iid = _blocked_ips_expire_add_ip('', $expiry_date);
// Check that the block worked.
$num_times_in_db = BlockedIpsExpireHelpers::numberTimesIpInDatabase($current_ip);
$this
->assertEqual($num_times_in_db, 1, 'Current IP is now blocked.');
$ip_info = _blocked_ips_expire_get_one((int) $iid);
$this
->assertEqual($ip_info->expiry_date, $expiry_date, "Current IP's expiry time matches the expiry date we set.");
// Delete the IP afterwards in case we're using a test runner that doesn't
// clean up after itself properly.
_blocked_ips_expire_delete_ip((int) $iid);
// Check that the delete worked.
$num_times_in_db = BlockedIpsExpireHelpers::numberTimesIpInDatabase($current_ip);
$this
->assertTrue($num_times_in_db <= 0, 'Current IP is no longer in database.');
}