public function BanMiddlewareTest::testBannedIp in Drupal 8
Same name and namespace in other branches
- 9 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 52
Class
- BanMiddlewareTest
- @coversDefaultClass \Drupal\ban\BanMiddleware @group ban
Namespace
Drupal\Tests\ban\UnitCode
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());
}