function BanMiddlewareTest::testBannedIp
Same name in other branches
- 9 core/modules/ban/tests/src/Unit/BanMiddlewareTest.php \Drupal\Tests\ban\Unit\BanMiddlewareTest::testBannedIp()
- 8.9.x core/modules/ban/tests/src/Unit/BanMiddlewareTest.php \Drupal\Tests\ban\Unit\BanMiddlewareTest::testBannedIp()
- 11.x 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 54
Class
- BanMiddlewareTest
- @coversDefaultClass \Drupal\ban\BanMiddleware @group ban
Namespace
Drupal\Tests\ban\UnitCode
public function testBannedIp() : void {
$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());
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.