public function IPBanFormTest::testBanPaths in IP Ban 8
Same name in this branch
- 8 ip_ban.test \IPBanFormTest::testBanPaths()
- 8 src/Tests/IPBanFormTest.php \Drupal\ip_ban\Tests\IPBanFormTest::testBanPaths()
Various tests for paths entered in the the admin form.
File
- src/
Tests/ IPBanFormTest.php, line 28
Class
- IPBanFormTest
- Tests the IP Ban admin page form.
Namespace
Drupal\ip_ban\TestsCode
public function testBanPaths() {
// Add node for testing path and making sure we land on the proper page
// for read-only and complete ban paths.
$this
->addBanNode("Test page");
// Test the read only path saves correctly for valid path.
$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'));
// @FIXME
// Could not extract the default value because it is either indeterminate, or
// not scalar. You'll need to provide a default value in
// config/install/ip_ban.settings.yml and config/schema/ip_ban.schema.yml.
$readOnlyPath = \Drupal::config('ip_ban.settings')
->get('ip_ban_readonly_path');
$this
->assertIdentical($readOnlyPath, '/node/1');
// // Test the read only path returns an error on invalid path.
$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.'));
// // Test the complete ban path returns an error on invalid path.
$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 (/).'));
}