public function FormValidatorTest::testValidateValidFormToken in Drupal 10
Same name and namespace in other branches
- 8 core/tests/Drupal/Tests/Core/Form/FormValidatorTest.php \Drupal\Tests\Core\Form\FormValidatorTest::testValidateValidFormToken()
- 9 core/tests/Drupal/Tests/Core/Form/FormValidatorTest.php \Drupal\Tests\Core\Form\FormValidatorTest::testValidateValidFormToken()
@covers ::validateForm
File
- core/
tests/ Drupal/ Tests/ Core/ Form/ FormValidatorTest.php, line 141
Class
- FormValidatorTest
- @coversDefaultClass \Drupal\Core\Form\FormValidator @group Form
Namespace
Drupal\Tests\Core\FormCode
public function testValidateValidFormToken() {
$request_stack = new RequestStack();
$this->csrfToken
->expects($this
->once())
->method('validate')
->will($this
->returnValue(TRUE));
$form_validator = $this
->getMockBuilder('Drupal\\Core\\Form\\FormValidator')
->setConstructorArgs([
$request_stack,
$this
->getStringTranslationStub(),
$this->csrfToken,
$this->logger,
$this->formErrorHandler,
])
->onlyMethods([
'doValidateForm',
])
->getMock();
$form_validator
->expects($this
->once())
->method('doValidateForm');
$form['#token'] = 'test_form_id';
$form_state = $this
->getMockBuilder('Drupal\\Core\\Form\\FormState')
->onlyMethods([
'setErrorByName',
])
->getMock();
$form_state
->expects($this
->never())
->method('setErrorByName');
$form_state
->setValue('form_token', 'some_random_token');
$form_validator
->validateForm('test_form_id', $form, $form_state);
$this
->assertTrue($form_state
->isValidationComplete());
}