You are here

public function BanMiddlewareTest::testBannedIp in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 core/modules/ban/tests/src/Unit/BanMiddlewareTest.php \Drupal\Tests\ban\Unit\BanMiddlewareTest::testBannedIp()

Tests a banned IP.

File

core/modules/ban/tests/src/Unit/BanMiddlewareTest.php, line 57
Contains \Drupal\Tests\ban\Unit\BanMiddlewareTest.

Class

BanMiddlewareTest
@coversDefaultClass \Drupal\ban\BanMiddleware @group ban

Namespace

Drupal\Tests\ban\Unit

Code

public function testBannedIp() {
  $banned_ip = '17.0.0.2';
  $this->banManager
    ->expects($this
    ->once())
    ->method('isBanned')
    ->with($banned_ip)
    ->willReturn(TRUE);
  $this->kernel
    ->expects($this
    ->never())
    ->method('handle');
  $request = Request::create('/test-path');
  $request->server
    ->set('REMOTE_ADDR', $banned_ip);
  $response = $this->banMiddleware
    ->handle($request);
  $this
    ->assertEquals(403, $response
    ->getStatusCode());
}