You are here

public function IPBanFunctionalTest::testReadOnlyWithDisabledBlock in IP Ban 8

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

Test the read-only and complete ban functionality.

File

src/Tests/IPBanFunctionalTest.php, line 58

Class

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

Namespace

Drupal\ip_ban\Tests

Code

public function testReadOnlyWithDisabledBlock() {

  // node/1.
  $this
    ->addBanNode("Read only 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' => 1,
    // Set the test IP address to a known Google US address.
    'ip_ban_test_ip' => '66.249.84.22',
    // Configure the path for read-only.
    'ip_ban_readonly_path' => '/node/1',
  );
  $this
    ->drupalPostForm(IP_BAN_ADMIN_FORM_PATH, $edit, t('Save configuration'));
  $this
    ->assertOptionSelected('edit-ip-ban-us', 1, 'Read only set correctly in country list table.');

  // Set block title to confirm that the interface is available.
  // No need to do the following on D7 sites since the user login and powered
  // by Drupal are enabled by default.
  // $edit = array(
  // 'title' => $this->randomMachineName(),
  // 'pages' => 'node/1',
  // );
  // $this->drupalPost('admin/structure/block/manage/search/form/configure', $edit, t('Save block'));
  // $this->assertText(t('The block configuration has been saved.'), 'Block configuration set.');
  // // Set the block to a region to confirm block is available.
  // $edit = array();
  // $edit['blocks[search_form][region]'] = 'footer';
  // $this->drupalPost('admin/structure/block', $edit, t('Save blocks'));
  // $this->assertText(t('The block settings have been updated.'), 'Block successfully move to footer region.');
  // Attempt to access user page after logging privileged user out.
  $this
    ->drupalGet('node/1');

  // $theme = \Drupal::theme()->getActiveTheme()->getName();
  // $all_regions = system_region_list($theme);
  // debug($all_regions);
  // $blocks = block_list('footer');
  // debug($blocks);
  $this
    ->drupalGet('user/logout');

  // \Drupal::service("router.builder")->rebuild();
  // $this->drupalGet('user/login');
  // Should be redirected to read only page.
  // $this->assertUrl('node/1');
  // Not sure how to actually test if a block is not visible as I would have
  // thought the following would work, but I only see an empty array (even
  // when run before the privileged user is logged out).
  // $blocks = block_list('footer');
  // debug($blocks);
  // Note: a simple visual inspection confirms both the user login and powered
  // by Drupal blocks are missing when viewing the test results.
}