RestrictByIPWebTestBase.php in Restrict Login or Role Access by IP Address 8.4
File
src/Tests/RestrictByIPWebTestBase.php
View source
<?php
namespace Drupal\restrict_by_ip\Tests;
use Drupal\simpletest\WebTestBase;
class RestrictByIPWebTestBase extends WebTestBase {
public static $modules = [
'restrict_by_ip',
];
protected $conf;
protected $regularUser;
protected $currentIPCIDR;
protected $outOfRangeCIDR;
public function setUp() {
parent::setUp();
$this->conf = $this
->config('restrict_by_ip.settings');
$this->regularUser = $this
->drupalCreateUser();
$outOfRangeCIDRs = [
'10' => '10.0.0.0/8',
'172' => '172.16.0.0/12',
'192' => '192.168.0.0/16',
];
$adminUser = $this
->drupalCreateUser([
'administer restrict by ip',
]);
$this
->drupalLogin($adminUser);
$this
->drupalGet('admin/config/people/restrict_by_ip/login');
$pageContent = $this
->getTextContent();
preg_match('#is (.*?). If#', $pageContent, $matches);
$this
->drupalLogout();
$this->currentIPCIDR = $matches[1] . '/32';
unset($outOfRangeCIDRs[explode('.', $this->currentIPCIDR)[0]]);
$this->outOfRangeCIDR = array_shift($outOfRangeCIDRs);
}
}