function BanMiddlewareTest::testUnbannedIp

Same name in other branches
  1. 9 core/modules/ban/tests/src/Unit/BanMiddlewareTest.php \Drupal\Tests\ban\Unit\BanMiddlewareTest::testUnbannedIp()
  2. 8.9.x core/modules/ban/tests/src/Unit/BanMiddlewareTest.php \Drupal\Tests\ban\Unit\BanMiddlewareTest::testUnbannedIp()
  3. 11.x core/modules/ban/tests/src/Unit/BanMiddlewareTest.php \Drupal\Tests\ban\Unit\BanMiddlewareTest::testUnbannedIp()

Tests an unbanned IP.

File

core/modules/ban/tests/src/Unit/BanMiddlewareTest.php, line 74

Class

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

Namespace

Drupal\Tests\ban\Unit

Code

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

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.