You are here

public function IPBanFormTest::testIpAddressEntry in IP Ban 8

Same name in this branch
  1. 8 ip_ban.test \IPBanFormTest::testIpAddressEntry()
  2. 8 src/Tests/IPBanFormTest.php \Drupal\ip_ban\Tests\IPBanFormTest::testIpAddressEntry()
Same name and namespace in other branches
  1. 7 ip_ban.test \IPBanFormTest::testIpAddressEntry()

Test adding IP address in various fields (correct and incorrect).

File

./ip_ban.test, line 137
Tests for ip_ban.module.

Class

IPBanFormTest
Tests the IP Ban admin page form.

Code

public function testIpAddressEntry() {

  // Add multiple valid IP addresses.
  $this
    ->drupalGet(IP_BAN_ADMIN_FORM_PATH);
  $edit = array();
  $edit['ip_ban_readonly_ips'] = ' 192.168.32.60' . PHP_EOL . '156.228.60.110 ';
  $this
    ->drupalPost(IP_BAN_ADMIN_FORM_PATH, $edit, t('Save configuration'));
  $this
    ->assertText(t('The configuration options have been saved.'));

  // Try to add an invalid IP address.
  $this
    ->drupalGet(IP_BAN_ADMIN_FORM_PATH);
  $edit = array();
  $edit['ip_ban_additional_ips'] = '666.666.666.666';
  $this
    ->drupalPost(IP_BAN_ADMIN_FORM_PATH, $edit, t('Save configuration'));
  $this
    ->assertText(t('You have entered one or more incorrect IPV4 addresses.'));

  // Add multiple IP addresses on the same line (error)
  $this
    ->drupalGet(IP_BAN_ADMIN_FORM_PATH);
  $edit = array();
  $edit['ip_ban_additional_ips'] = '192.168.32.60, 156.228.60.110';
  $this
    ->drupalPost(IP_BAN_ADMIN_FORM_PATH, $edit, t('Save configuration'));
  $this
    ->assertText(t('You have entered one or more incorrect IPV4 addresses.'));
}