Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
5 changes: 5 additions & 0 deletions features/test.feature
Original file line number Diff line number Diff line change
Expand Up @@ -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:
"""
Expand Down
13 changes: 12 additions & 1 deletion src/NextcloudApiContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -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[]
Expand Down Expand Up @@ -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) {
Expand All @@ -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);
Expand Down
Loading