1
0
mirror of https://github.com/flarum/core.git synced 2025-08-10 18:35:56 +02:00

Replace authenticatedRequest() by request() option

I feel this makes the parameters a bit more clear, does not rely on
inheritance (you can only inherit from one class, but we might want more
of these helpers in the future), and has less side effects (e.g. no
creation and, more importantly, deletion of users in the database).

Refs #2052.
This commit is contained in:
Franz Liedke
2020-03-20 18:22:52 +01:00
parent a13c0bb612
commit 25f772c1ea
3 changed files with 19 additions and 72 deletions

View File

@@ -143,6 +143,9 @@ abstract class TestCase extends \PHPUnit\Framework\TestCase
* - "json" should point to a JSON-serializable object that will be
* serialized and used as request body. The corresponding Content-Type
* header will be set automatically.
* - "authenticatedAs" should identify an *existing* user by ID. This will
* cause an access token to be created for this user, which will be used
* to authenticate the request via the "Authorization" header.
* - "cookiesFrom" should hold a response object from a previous HTTP
* interaction. All cookies returned from the server in that response
* (via the "Set-Cookie" header) will be copied to the cookie params of
@@ -160,6 +163,13 @@ abstract class TestCase extends \PHPUnit\Framework\TestCase
);
}
// Authenticate as a given user
if (isset($options['authenticatedAs'])) {
$request = $this->requestAsUser(
$request, $options['authenticatedAs']
);
}
// Let's copy the cookies from a previous response
if (isset($options['cookiesFrom'])) {
$request = $this->requestWithCookiesFrom(