Make possible to set body in requesttoken requests in integration tests
"sendingAToWithRequesttoken" needs to be used to test some non OCS endpoints which require the request token to be sent in the request. Now it is possible to specify the body (or, rather, additional contents beside the cookies and the request token) for those requests, as it will be needed for example to update the user profile. Signed-off-by: Daniel Calviño Sánchez <danxuliu@gmail.com>
This commit is contained in:
parent
d2f1225b34
commit
bc9b213b7b
|
@ -307,21 +307,31 @@ trait BasicStructure {
|
||||||
* @When Sending a :method to :url with requesttoken
|
* @When Sending a :method to :url with requesttoken
|
||||||
* @param string $method
|
* @param string $method
|
||||||
* @param string $url
|
* @param string $url
|
||||||
|
* @param TableNode|array|null $body
|
||||||
*/
|
*/
|
||||||
public function sendingAToWithRequesttoken($method, $url) {
|
public function sendingAToWithRequesttoken($method, $url, $body = null) {
|
||||||
$baseUrl = substr($this->baseUrl, 0, -5);
|
$baseUrl = substr($this->baseUrl, 0, -5);
|
||||||
|
|
||||||
|
$options = [
|
||||||
|
'cookies' => $this->cookieJar,
|
||||||
|
'headers' => [
|
||||||
|
'requesttoken' => $this->requestToken
|
||||||
|
],
|
||||||
|
];
|
||||||
|
|
||||||
|
if ($body instanceof TableNode) {
|
||||||
|
$fd = $body->getRowsHash();
|
||||||
|
$options['form_params'] = $fd;
|
||||||
|
} elseif ($body) {
|
||||||
|
$options = array_merge($options, $body);
|
||||||
|
}
|
||||||
|
|
||||||
$client = new Client();
|
$client = new Client();
|
||||||
try {
|
try {
|
||||||
$this->response = $client->request(
|
$this->response = $client->request(
|
||||||
$method,
|
$method,
|
||||||
$baseUrl . $url,
|
$baseUrl . $url,
|
||||||
[
|
$options
|
||||||
'cookies' => $this->cookieJar,
|
|
||||||
'headers' => [
|
|
||||||
'requesttoken' => $this->requestToken
|
|
||||||
]
|
|
||||||
]
|
|
||||||
);
|
);
|
||||||
} catch (ClientException $e) {
|
} catch (ClientException $e) {
|
||||||
$this->response = $e->getResponse();
|
$this->response = $e->getResponse();
|
||||||
|
|
Loading…
Reference in New Issue