You are here

public function RestrictIpAccessTest::testAccessBypassByRole in Restrict IP 8

Same name and namespace in other branches
  1. 8.2 tests/src/Functional/RestrictIpAccessTest.php \Drupal\Tests\restrict_ip\Functional\RestrictIpAccessTest::testAccessBypassByRole()
  2. 3.x tests/src/Functional/RestrictIpAccessTest.php \Drupal\Tests\restrict_ip\Functional\RestrictIpAccessTest::testAccessBypassByRole()

File

tests/src/Functional/RestrictIpAccessTest.php, line 64

Class

RestrictIpAccessTest
@group restrict_ip

Namespace

Drupal\Tests\restrict_ip\Functional

Code

public function testAccessBypassByRole() {
  $adminUser = $this
    ->drupalCreateUser([
    'administer restricted ip addresses',
    'access administration pages',
    'administer modules',
  ]);
  $this
    ->createArticleContentType();
  $this
    ->createArticle();
  $this
    ->drupalLogin($adminUser);
  $this
    ->drupalGet('admin/config/people/restrict_ip');
  $this
    ->assertStatusCodeEquals(200);
  $this
    ->checkCheckbox('#edit-allow-role-bypass');
  $this
    ->click('#edit-submit');
  $admin_role = $this
    ->createRole([
    'bypass ip restriction',
  ]);
  $adminUser
    ->addRole($admin_role);
  $this
    ->checkCheckbox('#edit-enable');
  $this
    ->click('#edit-submit');
  $this
    ->drupalLogout();
  $this
    ->drupalGet('node/1');
  $this
    ->assertSession()
    ->pageTextContains('The page you are trying to access cannot be accessed from your IP address.');
  $this
    ->assertSession()
    ->linkExists('Sign in');
  $this
    ->drupalGet('user');
  $this
    ->assertStatusCodeEquals(200);
  $this
    ->drupalGet('user/login');
  $this
    ->assertStatusCodeEquals(200);
  $this
    ->drupalGet('user/password');
  $this
    ->assertStatusCodeEquals(200);
  $this
    ->drupalGet('user/register');
  $this
    ->assertStatusCodeEquals(200);
  $this
    ->drupalGet('user/reset/1');
  $this
    ->assertStatusCodeEquals(403);
}