You are here

public function RestrictIpServiceTest::testPathInAllowedPaths in Restrict IP 8

Same name and namespace in other branches
  1. 8.2 tests/src/Unit/Service/RestrictIpServiceTest.php \Drupal\Tests\restrict_ip\Unit\Service\RestrictIpServiceTest::testPathInAllowedPaths()
  2. 3.x tests/src/Unit/Service/RestrictIpServiceTest.php \Drupal\Tests\restrict_ip\Unit\Service\RestrictIpServiceTest::testPathInAllowedPaths()

* @covers ::userIsBlocked * @dataProvider pathInAllowedPathsDataProvider

File

tests/src/Unit/Service/RestrictIpServiceTest.php, line 94

Class

RestrictIpServiceTest
@coversDefaultClass \Drupal\restrict_ip\Service\RestrictIpService @group restrict_ip

Namespace

Drupal\Tests\restrict_ip\Unit\Service

Code

public function testPathInAllowedPaths($path, $expectedResult) {
  $this->currentUser
    ->expects($this
    ->at(0))
    ->method('hasPermission')
    ->willReturn(FALSE);
  $this->currentPathStack
    ->expects($this
    ->at(0))
    ->method('getPath')
    ->willReturn($path);
  $this->request
    ->expects($this
    ->at(0))
    ->method('getClientIp')
    ->willReturn('::1');
  $this->requestStack
    ->expects($this
    ->at(0))
    ->method('getCurrentRequest')
    ->willReturn($this->request);
  $configFactory = $this
    ->getConfigFactory([
    'allow_role_bypass' => TRUE,
  ]);
  $restrictIpService = new RestrictIpService($this->currentUser, $this->currentPathStack, $configFactory, $this->requestStack, $this->mapper, $this->pathMatcher);
  $user_is_blocked = $restrictIpService
    ->userIsBlocked();
  $this
    ->assertSame($expectedResult, $user_is_blocked, 'User is not blocked when they are on the allowed path: ' . $path);
}