View source
<?php
namespace Drupal\Tests\restrict_ip\Functional;
class RestrictIpAdminUiTest extends RestrictIpBrowserTestBase {
protected static $modules = [
'restrict_ip',
];
public function testRestrictIpAdminPage() {
$account = $this
->drupalCreateUser([
'administer restricted ip addresses',
'access administration pages',
'administer modules',
]);
$this
->drupalLogin($account);
$this
->drupalGet('admin/config');
$this
->assertStatusCodeEquals(200);
$this
->assertSession()
->pageTextContains('Administer whitelisted IP addresses and related settings');
$this
->clickLink('Restrict IP');
$this
->assertSession()
->addressMatches('/\\/admin\\/config\\/people\\/restrict_ip$/');
$this
->assertStatusCodeEquals(200);
$this
->assertSession()
->pageTextContains('Enter the list of allowed IP addresses below');
$this
->assertElementExists('#edit-enable');
$this
->assertElementAttributeExists('#edit-enable', 'type');
$this
->assertElementAttributeContains('#edit-enable', 'type', 'checkbox');
$this
->assertElementExists('#edit-address-list');
$this
->assertElementAttributeExists('#edit-address-list', 'class');
$this
->assertElementAttributeContains('#edit-address-list', 'class', 'form-textarea');
$this
->assertElementExists('#edit-mail-address');
$this
->assertElementAttributeExists('#edit-mail-address', 'type');
$this
->assertElementAttributeContains('#edit-mail-address', 'type', 'text');
$this
->assertSession()
->elementNotExists('css', '#edit-dblog');
$this
->drupalGet('admin/modules');
$this
->assertStatusCodeEquals(200);
$this
->checkCheckbox('edit-modules-core-dblog-enable');
$this
->click('#edit-submit');
$this
->drupalGet('admin/config/people/restrict_ip');
$this
->assertElementExists('#edit-dblog');
$this
->assertElementAttributeExists('#edit-dblog', 'type');
$this
->assertElementAttributeContains('#edit-dblog', 'type', 'checkbox');
$this
->assertElementExists('#edit-allow-role-bypass');
$this
->assertElementAttributeExists('#edit-allow-role-bypass', 'type');
$this
->assertElementAttributeContains('#edit-allow-role-bypass', 'type', 'checkbox');
$this
->assertElementExists('#edit-bypass-action-provide-link-login-page');
$this
->assertElementAttributeExists('#edit-bypass-action-provide-link-login-page', 'type');
$this
->assertElementAttributeContains('#edit-bypass-action-provide-link-login-page', 'type', 'radio');
$this
->assertElementExists('#edit-bypass-action-redirect-login-page');
$this
->assertElementAttributeExists('#edit-bypass-action-redirect-login-page', 'type');
$this
->assertElementAttributeContains('#edit-bypass-action-redirect-login-page', 'type', 'radio');
$this
->assertElementExists('#edit-white-black-list-0');
$this
->assertElementAttributeExists('#edit-white-black-list-0', 'type');
$this
->assertElementAttributeContains('#edit-white-black-list-0', 'type', 'radio');
$this
->assertElementExists('#edit-white-black-list-1');
$this
->assertElementAttributeExists('#edit-white-black-list-1', 'type');
$this
->assertElementAttributeContains('#edit-white-black-list-1', 'type', 'radio');
$this
->assertElementExists('#edit-white-black-list-2');
$this
->assertElementAttributeExists('#edit-white-black-list-2', 'type');
$this
->assertElementAttributeContains('#edit-white-black-list-2', 'type', 'radio');
$this
->assertElementExists('textarea#edit-page-whitelist');
$this
->assertElementExists('textarea#edit-page-blacklist');
$this
->fillTextValue('edit-address-list', '// Address 1' . PHP_EOL . '1.1.1.1' . PHP_EOL . '# Address 2' . PHP_EOL . '2.2.2.2' . PHP_EOL . '/**' . PHP_EOL . ' * Address 3' . PHP_EOL . ' */' . PHP_EOL . '3.3.3.3');
$this
->fillTextValue('edit-mail-address', 'dave@example.com');
$this
->checkCheckbox('edit-dblog');
$this
->checkCheckbox('edit-allow-role-bypass');
$this
->selectRadio('edit-bypass-action-redirect-login-page');
$this
->selectRadio('edit-white-black-list-1');
$this
->fillTextValue('edit-page-whitelist', 'page/1' . PHP_EOL . '/page/2');
$this
->fillTextValue('edit-page-blacklist', 'page/3' . PHP_EOL . '/page/4');
$this
->click('#edit-submit');
$this
->assertSession()
->elementExists('css', '#edit-address-list');
$this
->assertTextValue('edit-address-list', '1.1.1.1' . PHP_EOL . '2.2.2.2' . PHP_EOL . '3.3.3.3');
$this
->assertTextValue('edit-mail-address', 'dave@example.com');
$this
->assertCheckboxChecked('edit-dblog');
$this
->assertCheckboxChecked('edit-allow-role-bypass');
$this
->assertRadioSelected('edit-bypass-action-redirect-login-page');
}
}