You are here

public function AdvbanMiddlewareTest::testUnbannedIp in Advanced ban 8

Tests an unbanned IP.

File

tests/src/Unit/AdvbanMiddlewareTest.php, line 73

Class

AdvbanMiddlewareTest
@coversDefaultClass \Drupal\advban\AdvbanMiddleware @group Advban

Namespace

Drupal\Tests\advban\Unit

Code

public function testUnbannedIp() {
  $unbanned_ip = '18.0.0.2';
  $this->banManager
    ->expects($this
    ->once())
    ->method('isBanned')
    ->with($unbanned_ip)
    ->willReturn([
    'is_banned' => FALSE,
    'expiry_date' => 0,
  ]);
  $request = Request::create('/test-path');
  $request->server
    ->set('REMOTE_ADDR', $unbanned_ip);
  $expected_response = new Response(200);
  $this->kernel
    ->expects($this
    ->once())
    ->method('handle')
    ->with($request, HttpKernelInterface::MASTER_REQUEST, TRUE)
    ->willReturn($expected_response);
  $response = $this->banMiddleware
    ->handle($request);
  $this
    ->assertSame($expected_response, $response);
}