You are here

public function RestrictIpServiceTest::testWhitelistedIpAddresses 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::testWhitelistedIpAddresses()
  2. 3.x tests/src/Unit/Service/RestrictIpServiceTest.php \Drupal\Tests\restrict_ip\Unit\Service\RestrictIpServiceTest::testWhitelistedIpAddresses()

* @covers ::testForBlock * @dataProvider whitelistedIpAddressesTestDataProvider

File

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

Class

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

Namespace

Drupal\Tests\restrict_ip\Unit\Service

Code

public function testWhitelistedIpAddresses($ipAddressToCheck, $expectedResult, $message) {
  $this->currentPathStack
    ->expects($this
    ->at(0))
    ->method('getPath')
    ->willReturn('/some/path');
  $this->request
    ->expects($this
    ->at(0))
    ->method('getClientIp')
    ->willReturn($ipAddressToCheck);
  $this->requestStack
    ->expects($this
    ->at(0))
    ->method('getCurrentRequest')
    ->willReturn($this->request);
  $configFactory = $this
    ->getConfigFactory([
    'enable' => TRUE,
    'white_black_list' => 0,
  ]);
  $mapper = $this
    ->getMockBuilder('Drupal\\restrict_ip\\Mapper\\RestrictIpMapper')
    ->disableOriginalConstructor()
    ->getMock();
  $mapper
    ->expects($this
    ->any())
    ->method('getWhitelistedIpAddresses')
    ->willReturn([
    '::1',
  ]);
  $restrictIpService = new RestrictIpService($this->currentUser, $this->currentPathStack, $configFactory, $this->requestStack, $mapper, $this->pathMatcher);
  $restrictIpService
    ->testForBlock(TRUE);
  $this
    ->assertSame($expectedResult, $restrictIpService
    ->userIsBlocked(), $message);
}