You are here

public function BlockedIpsExpireUi::testSystemBlockedIpFormHasExpiryDate in Blocked IPs Expire 7

Test that the module modified the blocked IPs entry form as expected.

File

tests/blocked_ips_expire.ui.test, line 93
Contains \BlockedIpsExpireUi.

Class

BlockedIpsExpireUi
Tests that the module correctly modifies the system module blocking UI.

Code

public function testSystemBlockedIpFormHasExpiryDate() {

  // Re-set the default expiry date to some obscure number.
  $blocked_ips_expire_default_time = '+3 weeks 5 days';
  variable_set('blocked_ips_expire_default_time', $blocked_ips_expire_default_time);

  // Ensure the form has the correct controls.
  $this
    ->drupalGet('admin/config/people/ip-blocking');
  $this
    ->assertRaw('Expiry date', 'System blocked IPs form displays an expiry date control.');
  $this
    ->assertText(variable_get('blocked_ips_expire_default_time', '+2 weeks'), 'Displays the default expire time.');
  $this
    ->assertText('The total number of blocked IPs is: 0', 'System blocked IPs page successfully displays the number of blocked IPs.');

  // Ensure submitting the form adds an IP address with an expiry date.
  $ip_to_block = $this
    ->generateIpAddress();
  $block_year = rand(1970, 2038);
  $block_month = rand(1, 12);
  $block_day = rand(1, 28);
  $expiry_date = new DateTime();
  $expiry_date
    ->setDate($block_year, $block_month, $block_day);
  $block_ip_form_data = array(
    'ip' => $ip_to_block,
    'expiry_date[month]' => $block_month,
    'expiry_date[day]' => $block_day,
    'expiry_date[year]' => $block_year,
  );
  $this
    ->drupalPost('admin/config/people/ip-blocking', $block_ip_form_data, t('Add'));
  $this
    ->assertText($ip_to_block, 'IP we just blocked is displayed on the page.');
  $this
    ->assertText(format_date($expiry_date
    ->format('U')), 'Expiry date we just set is displayed on the page.');
  $this
    ->assertText('The total number of blocked IPs is: 1', 'System blocked IPs page successfully displays the number of blocked IPs.');
}