]> source.dussan.org Git - nextcloud-server.git/commitdiff
Make possible to set body in requesttoken requests in integration tests
authorDaniel Calviño Sánchez <danxuliu@gmail.com>
Thu, 3 Dec 2020 12:11:19 +0000 (13:11 +0100)
committerDaniel Calviño Sánchez <danxuliu@gmail.com>
Fri, 23 Apr 2021 14:53:57 +0000 (16:53 +0200)
"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>
build/integration/features/bootstrap/BasicStructure.php

index eed0f173ced465d00e1ae8186ea2da99e5f00983..b92b85cf4d35097ba11d2b3314de687685fa741a 100644 (file)
@@ -307,21 +307,31 @@ trait BasicStructure {
         * @When Sending a :method to :url with requesttoken
         * @param string $method
         * @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);
 
+               $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();
                try {
                        $this->response = $client->request(
                                $method,
                                $baseUrl . $url,
-                               [
-                                       'cookies' => $this->cookieJar,
-                                       'headers' => [
-                                               'requesttoken' => $this->requestToken
-                                       ]
-                               ]
+                               $options
                        );
                } catch (ClientException $e) {
                        $this->response = $e->getResponse();