// Setting this error will cause the form to fail validation.
$form_state->setErrorByName('form_token',$this->t('The form has become outdated. Copy any unsaved work in the form below and then <a href=":link">reload this page</a>.',[':link'=>$url]));
$form_state->setErrorByName('form_token',$this->t('The form has become outdated. Press the back button, copy any unsaved work in the form, and then reload the page.'));
@@ -251,21 +251,27 @@ public function testInputWithInvalidToken() {
$this->assertSession()
->elementExists('css','input[name="form_token"]')
->setValue('invalid token');
$random_string=$this->randomString();
$edit=[
'textfield'=>$this->randomString(),
'textfield'=>$random_string,
'checkboxes[bar]'=>TRUE,
'select'=>'bar',
'radios'=>'foo',
];
$this->drupalPostForm(NULL,$edit,'Submit');
$this->assertFieldByXpath('//div[contains(@class, "error")]',NULL,'Error message is displayed with invalid token even when required fields are filled.');
$this->assertText('The form has become outdated. Copy any unsaved work in the form below');
// Verify that input elements retained the posted values.
@@ -278,9 +284,9 @@ public function testInputWithInvalidToken() {
];
$this->drupalPostForm(NULL,$edit,'Submit');
$this->assertFieldByXpath('//div[contains(@class, "error")]',NULL,'Error message is displayed with invalid token even when required fields are filled.');
$this->assertText('The form has become outdated. Copy any unsaved work in the form below');
@@ -288,12 +294,14 @@ public function testInputWithInvalidToken() {
->elementExists('css','input[name="form_token"]')
->setValue('invalid token');
$edit=[
'integer_step'=>mt_rand(1,100),
// We choose a random value which is higher than the default value,
// so we don't accidentally generate the default value.
'integer_step'=>mt_rand(6,100),
];
$this->drupalPostForm(NULL,$edit,'Submit');
$this->assertFieldByXpath('//div[contains(@class, "error")]',NULL,'Error message is displayed with invalid token even when required fields are filled.');
$this->assertText('The form has become outdated. Copy any unsaved work in the form below');
@@ -305,8 +313,8 @@ public function testInputWithInvalidToken() {
];
$this->drupalPostForm(NULL,$edit,'Submit');
$this->assertFieldByXpath('//div[contains(@class, "error")]',NULL,'Error message is displayed with invalid token even when required fields are filled.');
$this->assertText('The form has become outdated. Copy any unsaved work in the form below');
$this->assertFieldByName('url',$edit['url']);
$this->assertText('The form has become outdated.');
@@ -131,7 +131,7 @@ public function testValidateInvalidFormToken() {
->getMock();
$form_state->expects($this->once())
->method('setErrorByName')
->with('form_token','The form has become outdated. Copy any unsaved work in the form below and then <a href="/test/example?foo=bar">reload this page</a>.');
->with('form_token','The form has become outdated. Press the back button, copy any unsaved work in the form, and then reload the page.');