diff --git a/README.md b/README.md index 8db39b1..bbd04d3 100644 --- a/README.md +++ b/README.md @@ -55,6 +55,7 @@ Given the response should be a JSON array with the following mandatory values Given /^set the display name of user "([^"]*)" to "([^"]*)"$/ Given /^set the email of user "([^"]*)" to "([^"]*)"$/ Given sending :verb to ocs :url +Given /^set the custom http header "([^"]*)" with "([^"]*)" as value to next request$/ Given the response should have a status code :code Given fetch field :path from previous JSON response Given the response should contain the initial state :name with the following values: diff --git a/features/test.feature b/features/test.feature index 2ad2032..0b86897 100644 --- a/features/test.feature +++ b/features/test.feature @@ -7,6 +7,11 @@ Feature: Test this extension Given sending "POST" to "/" | status | 1 | + Scenario: Test POST with success + Given set the custom http header "GUSTOM_HEADER" with "custom-value" as value to next request + Then sending "POST" to "/" + | status | 1 | + Scenario: Test response of POST is numeric When set the response to: """ diff --git a/src/NextcloudApiContext.php b/src/NextcloudApiContext.php index 1ac1c61..9c8fea9 100644 --- a/src/NextcloudApiContext.php +++ b/src/NextcloudApiContext.php @@ -33,6 +33,7 @@ class NextcloudApiContext implements Context { protected static array $environments = []; protected static string $commandOutput = ''; protected int $startWaitFor = 0; + protected array $customHeaders = []; /** * @var string[] @@ -189,7 +190,8 @@ public function sendRequest(string $verb, string $url, $body = null, array $head $options['headers'] = array_merge($headers, [ 'Accept' => 'application/json', - ]); + ], $this->customHeaders); + if ($this->currentUser === 'admin') { $options['auth'] = ['admin', $this->adminPassword]; } elseif ($this->currentUser) { @@ -207,6 +209,15 @@ public function sendRequest(string $verb, string $url, $body = null, array $head } } + #[Given('/^set the custom http header "([^"]*)" with "([^"]*)" as value to next request$/')] + public function setTheCustomHttpHeaderAsValueToNextRequest(string $header, string $value):void { + if (empty($value)) { + unset($this->customHeaders[$header]); + return; + } + $this->customHeaders[$header] = $this->parseText($value); + } + protected function beforeRequest(string $fullUrl, array $options): array { $options = $this->parseFormParams($options); $fullUrl = $this->parseText($fullUrl);