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()

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

File

src/Tests/IPBanFormTest.php, line 77

Class

IPBanFormTest
Tests the IP Ban admin page form.

Namespace

Drupal\ip_ban\Tests

Code

public function testIpAddressEntry() {

  // We need to have one test page on the site.
  $this
    ->addBanNode("Test page");

  // Add multiple valid IP addresses.
  $this
    ->drupalGet(IP_BAN_ADMIN_FORM_PATH);
  $edit = array(
    'ip_ban_readonly_path' => '/node/1',
    'ip_ban_readonly_ips' => '192.168.32.60' . PHP_EOL . '156.228.60.110 ',
  );
  $this
    ->drupalPostForm(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
    ->drupalPostForm(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
    ->drupalPostForm(IP_BAN_ADMIN_FORM_PATH, $edit, t('Save configuration'));
  $this
    ->assertText(t('You have entered one or more incorrect IPV4 addresses.'));
}