function BanAdminTest::testIpValidation
Same name in other branches
- 11.x core/modules/ban/tests/src/Unit/BanAdminTest.php \Drupal\Tests\ban\Unit\BanAdminTest::testIpValidation()
Tests various user input to confirm correct validation.
@covers ::validateForm @dataProvider providerIpValidation
File
-
core/
modules/ ban/ tests/ src/ Unit/ BanAdminTest.php, line 29
Class
- BanAdminTest
- Tests the BanAdmin form.
Namespace
Drupal\Tests\ban\UnitCode
public function testIpValidation(string $ip, bool $isBanned, ?string $error) : void {
$manager = $this->getIpManagerMock();
$manager->expects($this->once())
->method('isBanned')
->with($ip)
->willReturn($isBanned);
$formObject = new BanAdmin($manager);
$formObject->setStringTranslation($this->getStringTranslationStub());
$formObject->setRequestStack($this->getRequestStackMock());
$formState = $this->createMock(FormStateInterface::class);
$formState->expects($this->any())
->method('getValue')
->with('ip')
->willReturn($ip);
if ($error === NULL) {
$formState->expects($this->never())
->method('setErrorByName');
}
else {
$formState->expects($this->once())
->method('setErrorByName')
->with('ip', $error);
}
$form = [];
$formObject->validateForm($form, $formState);
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.