By mondrake on
Change record status:
Published (View all published change records)
Project:
Introduced in branch:
9.1.x
Introduced in version:
9.1.0
Issue links:
Description:
Using UiHelperTrait::drupalPostForm() in functional tests is deprecated. Use a combination of ::drupalGet and ::submitForm instead.
::drupalPostForm() used to visit the URL specified in the first argument before posting the form with ::submitForm(). Please note that:
::submitFormdoes not allow a NULL$editargument. If you do not need to fill in any field before submitting, pass an empty array.- differently from
::drupalPostForm(),::submitFormdoes not have a returned value. In case you were inspecting the output of::drupalPostForm(), useWebAssertmethods instead.
If you have a $path specified, first call ::drupalGet, then ::submitForm:
BEFORE:
$this->drupalPostForm('admin/structure/block/add/test_settings_validation/classy', ['region' => 'content', 'settings[digits]' => 'abc'], 'Save block');
AFTER:
$this->drupalGet('admin/structure/block/add/test_settings_validation/classy');
$this->submitForm(['region' => 'content', 'settings[digits]' => 'abc'], 'Save block');
If you have a NULL $path, then your current page is already the one with the form to be submitted, so call ::submitForm directly:
BEFORE:
$block = [];
$block['id'] = strtolower($this->randomMachineName());
$block['theme'] = 'classy';
$block['region'] = 'content';
$this->drupalPostForm('admin/structure/block/add/system_powered_by_block', $block, 'Save block');
$this->drupalPostForm(NULL, [], 'Save blocks');
AFTER:
$this->drupalGet('admin/structure/block/add/system_powered_by_block');
$block = [];
$block['id'] = strtolower($this->randomMachineName());
$block['theme'] = 'classy';
$block['region'] = 'content';
$this->submitForm($block, 'Save block');
$this->submitForm([], 'Save blocks');
Impacts:
Module developers
Comments
How to manage Ajax fields in
How to manage Ajax fields in browsertest?
Backward compatibility
Note that because the replacement functions (::submitForm and ::drupalGet) have existed since Drupal 8.1 (in BrowserTestBase 8.1-8.6, and UiHelperTrait in 8.7-9.1), this deprecation can be fixed without losing compatibility with older Drupal core versions.