Skip to content

[Bug] system tests cannot use associative arrays as query parameter values #23212

@diosmosis

Description

@diosmosis

What happened?

This is an issue that affects plugin development, specifically writing system tests for API methods.

System tests construct test URLs and use them to invoke API methods. When using an associative array, eg:

['apiParameters' => ['param1' => 1, 'param2' => 2]]

for the 'otherRequestParameters' property of an API test configuration, it is transformed to this in the test URL:

apiParameters[]=1&apiParameters[]=2

This makes it impossible to test API.getMetadata/API.getProcessedReport with a custom apiParameters value.

What should happen?

Using apiParameters in the otherRequestParameters property should be correctly converted to a URL that respects associative array keys, like this:

apiParameters[param1]=1&apiParameters[param2]=2

How can this be reproduced?

This issue can be reproduced with the following code (based on SystemTestCase::runApiTests()):

$api = 'API.getMetadata';
$params = [
    'idSite' => $idSite,
    'date' => $date,
    'periods'    => ['day'],
    'apiModule'  => 'Goals',
    'apiAction'  => 'getItemsCategory',
    'otherRequestParameters' => [
        'apiParameters' => ['idGoal' => 5],
    ]
];

$testConfig = new ApiTestConfig($params);
$testRequests = new Collection($api, $testConfig, $api);

foreach ($testRequests->getRequestUrls() as $apiId => $requestUrl) {
    Assert::assertStringNotContainsString('apiParameters[]=', $requestUrl);
    Assert::assertStringContainsString('apiParameters[idGoal]=', $requestUrl);
}

Matomo version

5.3.0

PHP version

No response

Server operating system

No response

What browsers are you seeing the problem on?

No response

Computer operating system

No response

Relevant log output

Validations

Metadata

Metadata

Assignees

No one assigned

    Labels

    Potential BugSomething that might be a bug, but needs validation and confirmation it can be reproduced.triaged

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions