function BanAdminTest::testSubmit

Same name in other branches
  1. 10 core/modules/ban/tests/src/Unit/BanAdminTest.php \Drupal\Tests\ban\Unit\BanAdminTest::testSubmit()

Test form submission.

File

core/modules/ban/tests/src/Unit/BanAdminTest.php, line 63

Class

BanAdminTest
Tests the BanAdmin form.

Namespace

Drupal\Tests\ban\Unit

Code

public function testSubmit() : void {
    $ip = '1.2.3.4';
    $manager = $this->getIpManagerMock();
    $manager->expects($this->once())
        ->method('banIp')
        ->with($ip);
    $messenger = $this->createMock(MessengerInterface::class);
    $messenger->expects($this->once())
        ->method('addStatus');
    $formObject = new BanAdmin($manager);
    $formObject->setStringTranslation($this->getStringTranslationStub());
    $formObject->setMessenger($messenger);
    $formState = $this->createMock(FormStateInterface::class);
    $formState->expects($this->any())
        ->method('getValue')
        ->with('ip')
        ->willReturn($ip);
    $form = [];
    $formObject->submitForm($form, $formState);
}

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