Test failure using $this->postSubmissionTest($webform) in tests that extend WebformBrowserTestBase in Drupal 10.2

Created on 29 February 2024, 4 months ago
Updated 19 April 2024, 2 months ago

Problem/Motivation

I'm seeing the following functional test failures in custom modules tests that extend Drupal\Tests\webform\Functional\WebformBrowserTestBase.

1) Drupal\Tests\bhcc_case_management\Functional\Plugin\WebformHandler\CaseManagementDocumentHandlerTest::testDocumentUploadHandler
TypeError: Behat\Mink\Element\TraversableElement::findButton(): Argument #1 ($locator) must be of type string, Drupal\Core\StringTranslation\TranslatableMarkup given, called in /Sites/bhcclocalgov/docroot/core/tests/Drupal/Tests/WebAssert.php on line 143

This is happening after the upgrade to Drupal core 10.2 (core 10.2.3).
I traced it to this function call
$this->postSubmissionTest($webform);

I notice that further down in WebformBrowserTestTrait::getWebformSubmitButtonLabel that this returns a translated markup if no value for the submit button is passed. I managed to get my custom tests working by changing the call to:
$this->postSubmissionTest($webform, [], 'Submit');

Steps to reproduce

  1. Create a simple test that extends Drupal\Tests\webform\Functional\WebformBrowserTestBase
  2. Create a simple webform with a single element, eg.
        $elements = [
          'document' => [
            '#type' => 'webform_document_file',
            '#title' => 'Documents',
          ],
        ];
    
        $settings = Webform::getDefaultSettings();
    
        // Create a webform.
        $webform = Webform::create([
          'id' => 'test_document_uploader_basic',
          'title' => 'Test document uploader basic',
          'elements' => Yaml::encode($elements),
          'settings' => $settings,
        ]);
    
        $webform->save();
    
        $this->postSubmissionTest($webform);
    
  3. Run the test with PHP Unit

Proposed resolution

Should WebformBrowserTestTrait::getWebformSubmitButtonLabel return t('Submit'); if no value is passed for the submit button?
This ends up being sent to BrowserTestBase submitForm method, which sends to Mink which is where it expects a string.

πŸ› Bug report
Status

Fixed

Version

6.2

Component

Code

Created by

πŸ‡¬πŸ‡§United Kingdom andybroomfield

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Merge Requests

Comments & Activities

Production build 0.69.0 2024