BrowserTestBase: howto do a POST request, without a form

Created on 13 September 2017, over 7 years ago
Updated 15 May 2025, 7 days ago

For a Commerce payment implementation I have a hard time to do a Post request in my automated test.

The test extends CommerceBrowserTestBase which extends BrowserTestBase.
The BrowserTestBase has a post method submitForm(), but in this case there is no form.
The post request must be done on a Drupal route.

Now I try to bypass the BrowserTestBase and use Mink directly. This does not work.

    $notify_url = $this->getUrl() . '/payment/notify/mollie_test_gateway';
    $postdata = ['json' => ['id' => 'test_id']];
    $session = $this->getSession();
    $session->setCookie('SIMPLETEST_USER_AGENT', drupal_generate_test_ua($this->databasePrefix));
    $response = $session->getDriver()->getClient()->request('POST', $notify_url, $postdata);

The $response object contains the 'site install' page.
The method that is behind te route is therefore not called.

Does someone know why and can give me a hint how to do this?

💬 Support request
Status

Fixed

Version

8.3 ⚰️

Component

simpletest.module

Created by

🇳🇱Netherlands ndf Amsterdam

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

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

Production build 0.71.5 2024