IPBanFormTest.php in IP Ban 8
File
src/Tests/IPBanFormTest.php
View source
<?php
namespace Drupal\ip_ban\Tests;
class IPBanFormTest extends IPBanTestBase {
public function setUp() {
parent::setUp();
$this
->drupalLogin($this->adminSitesUser);
}
public function testBanPaths() {
$this
->addBanNode("Test page");
$this
->drupalGet(IP_BAN_ADMIN_FORM_PATH);
$edit = array();
$this
->assertResponse(200, 'IP Ban admin form exists.');
$this
->assertFieldById('edit-submit');
$edit['ip_ban_readonly_path'] = '/node/1';
$this
->drupalPostForm(IP_BAN_ADMIN_FORM_PATH, $edit, t('Save configuration'));
$readOnlyPath = \Drupal::config('ip_ban.settings')
->get('ip_ban_readonly_path');
$this
->assertIdentical($readOnlyPath, '/node/1');
$this
->drupalGet(IP_BAN_ADMIN_FORM_PATH);
$edit = array();
$edit['ip_ban_readonly_path'] = '/readonly_path_' . $this
->randomMachineName(16);
$this
->drupalPostForm(IP_BAN_ADMIN_FORM_PATH, $edit, t('Save configuration'));
$this
->assertText(t('The path entered does not exist or you do not have permission to access it.'));
$this
->drupalGet(IP_BAN_ADMIN_FORM_PATH);
$edit = array();
$edit['ip_ban_completeban_path'] = 'node/1';
$this
->drupalPostForm(IP_BAN_ADMIN_FORM_PATH, $edit, t('Save configuration'));
$this
->assertText(t('The path must start with a forward slash (/).'));
}
public function testSetCountry() {
$this
->drupalGet(IP_BAN_ADMIN_FORM_PATH);
$edit = array();
$edit['ip_ban_US'] = 2;
$this
->drupalPostForm(IP_BAN_ADMIN_FORM_PATH, $edit, t('Save configuration'));
$this
->assertOptionSelected('edit-ip-ban-us', 2, 'Complete ban set correctly in country list table.');
}
public function testIpAddressEntry() {
$this
->addBanNode("Test page");
$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.'));
$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.'));
$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.'));
}
}