function BanMiddlewareTest::testBannedIp
Same name in other branches
- 9 core/modules/ban/tests/src/Unit/BanMiddlewareTest.php \Drupal\Tests\ban\Unit\BanMiddlewareTest::testBannedIp()
- 10 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 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());
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.