// Submit your own IP address. This fails, although it works when testing
// manually.
// TODO: On some systems this test fails due to a bug/inconsistency in cURL.
// $edit = array();
// $edit['ip'] = \Drupal::request()->getClientIP();
// $this->drupalGet('admin/config/people/ban');
// $this->submitForm($edit, 'Save');
// $this->assertSession()->pageTextContains('You may not ban your own IP address.');
// Test duplicate ip address are not present in the 'blocked_ips' table.
// when they are entered programmatically.
$banIp =
new BanIpManager($connection);
$ip = '1.0.0.0';
$banIp->
banIp($ip);
$banIp->
banIp($ip);
$banIp->
banIp($ip);
$query =
$connection->
select('ban_ip', 'bip'
);
$query->
fields('bip',
['iid'
]);
$query->
condition('bip.ip',
$ip);
$ip_count =
$query->
execute()->
fetchAll();
$this->
assertCount(1,
$ip_count);
$ip = '';
$banIp->
banIp($ip);