You are here

public function IPBanFormTest::testBanPaths in IP Ban 8

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

Various tests for paths entered in the the admin form.

File

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

Class

IPBanFormTest
Tests the IP Ban admin page form.

Code

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();
  $edit['ip_ban_readonly_path'] = 'node/1';
  $this
    ->drupalPost(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
    ->randomName(16);
  $this
    ->drupalPost(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'] = 'completeban_path_' . $this
    ->randomName(16);
  $this
    ->drupalPost(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.'));
}