function BanIpTest::testBanIp

Same name and namespace in other branches
  1. 11.x core/modules/ban/tests/src/Kernel/BanIpTest.php \Drupal\Tests\ban\Kernel\BanIpTest::testBanIp()

Test banning IPs.

File

core/modules/ban/tests/src/Kernel/BanIpTest.php, line 32

Class

BanIpTest
@group ban

Namespace

Drupal\Tests\ban\Kernel

Code

public function testBanIp() : void {
  $banIp = $this->container
    ->get(BanIpManagerInterface::class);
  // Test valid IP addresses.
  $ip = '1.2.3.3';
  $this->assertCount(0, $this->getIpBans($ip));
  $banIp->banIp($ip);
  $this->assertCount(1, $this->getIpBans($ip));
  // Test duplicate ip address are not present in the 'blocked_ips' table
  // when they are entered programmatically.
  $ip = '1.0.0.0';
  $banIp->banIp($ip);
  $banIp->banIp($ip);
  $banIp->banIp($ip);
  $this->assertCount(1, $this->getIpBans($ip));
  $ip = '';
  $banIp->banIp($ip);
  $banIp->banIp($ip);
  $this->assertCount(1, $this->getIpBans($ip));
}

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