Commit 1e1a38b7 authored by alexpott's avatar alexpott

Issue #1617918 by pfrenssen, tea.time: Test that no validation errors occur...

Issue #1617918 by pfrenssen, tea.time: Test that no validation errors occur for anonymous users when $form['#token'] == FALSE
parent 45ce1235
......@@ -75,6 +75,14 @@ function testValidate() {
$this->assertText('The form has become outdated. Copy any unsaved work in the form below');
}
/**
* Tests that a form with a disabled CSRF token can be validated.
*/
function testDisabledToken() {
$this->drupalPostForm('form-test/validate-no-token', [], 'Save');
$this->assertText('The form_test_validate_no_token form has been submitted successfully.');
}
/**
* Tests partial form validation through #limit_validation_errors.
*/
......
......@@ -100,6 +100,14 @@ form_test.validate_required_no_title:
requirements:
_access: 'TRUE'
form_test.validate_without_csrf_token:
path: '/form-test/validate-no-token'
defaults:
_form: '\Drupal\form_test\Form\FormTestValidateNoToken'
_title: 'Form validation on forms with a disabled CSRF token'
requirements:
_access: 'TRUE'
form_test.validate_with_error_suppresion:
path: '/form-test/limit-validation-errors'
defaults:
......
<?php
/**
* @file
* Contains \Drupal\form_test\Form\FormTestValidateNoToken.
*/
namespace Drupal\form_test\Form;
use Drupal\Core\Form\FormBase;
use Drupal\Core\Form\FormStateInterface;
/**
* Form to test the validation of forms with a disabled CSRF token.
*/
class FormTestValidateNoToken extends FormBase {
/**
* {@inheritdoc}
*/
public function getFormId() {
return 'form_test_validate_no_token';
}
/**
* {@inheritdoc}
*/
public function buildForm(array $form, FormStateInterface $form_state) {
$form['#token'] = FALSE;
$form['submit'] = [
'#type' => 'submit',
'#value' => 'Save',
];
return $form;
}
/**
* {@inheritdoc}
*/
public function submitForm(array &$form, FormStateInterface $form_state) {
drupal_set_message('The form_test_validate_no_token form has been submitted successfully.');
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment