You are here

public function IPBanFunctionalTest::testCompleteBan in IP Ban 8

Same name in this branch
  1. 8 ip_ban.test \IPBanFunctionalTest::testCompleteBan()
  2. 8 src/Tests/IPBanFunctionalTest.php \Drupal\ip_ban\Tests\IPBanFunctionalTest::testCompleteBan()

Test the complete ban functionality.

File

src/Tests/IPBanFunctionalTest.php, line 30

Class

IPBanFunctionalTest
Tests the complete ban and read only functionality of the IP Ban module.

Namespace

Drupal\ip_ban\Tests

Code

public function testCompleteBan() {

  // node/1.
  $this
    ->addBanNode("Read only page");

  // node/2.
  $this
    ->addBanNode("Complete ban page");
  $this
    ->drupalGet(IP_BAN_ADMIN_FORM_PATH);
  $edit = array(
    // Set the United States to Read Only
    // 0 = no action / 1 = Read Only / 2 = Complete Ban.
    'ip_ban_US' => 2,
    // Set the test IP address to a known Google US address.
    'ip_ban_test_ip' => '66.249.84.22',
    // Configure the paths for read-only and complete ban.
    // Todo: use $node = $this->drupalGetNodeByTitle($node_title) to get nids.
    'ip_ban_readonly_path' => '/node/1',
    'ip_ban_completeban_path' => '/node/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.');

  // Should be redirected to complete ban page after logout.
  $this
    ->drupalGet('user/logout');

  // Todo: figure out why the logout is not being redirected in the test.
  // $this->assertUrl('/node/2');
}