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: 0 additions & 1 deletion tests/acceptance/TestHelpers/CollaborationHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@
* A helper class for managing wopi requests
*/
class CollaborationHelper {

/**
* @param string $fileId
* @param string $app
Expand Down
14 changes: 14 additions & 0 deletions tests/acceptance/TestHelpers/GraphHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@ public static function getShareIdRegex(): string {
public static function getEtagRegex(): string {
return "^\\\"[a-f0-9:.]{1,32}\\\"$";
}

/**
* Federated users have a base64 encoded string of {remoteid}@{provider} as their id
* This regex matches only non empty base64 encoded strings
Expand All @@ -126,6 +127,19 @@ public static function getFederatedUserRegex(): string {
return '^(?:[A-Za-z0-9+/]{4})*(?:[A-Za-z0-9+/]{2}==|[A-Za-z0-9+/]{3}=|[A-Za-z0-9+/]{4})$';
}

/**
* @param string $pattern
*
* @return string regex pattern
*/
public static function jsonSchemaRegexToPureRegex(string $pattern): string {
$pattern = \str_replace("\\\\", "\\", $pattern);
$pattern = \str_replace("/", "\/", $pattern);
$pattern = \preg_replace('/^\^/', '', $pattern);
$pattern = \preg_replace('/\$$/', '', $pattern);
return "/^$pattern$/";
}

/**
* Key name can consist of @@@
* This function separate such key and return its actual value from actual drive response which can be used for assertion
Expand Down
18 changes: 18 additions & 0 deletions tests/acceptance/TestHelpers/HttpRequestHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -665,4 +665,22 @@ public static function getRequestTimeout(): int {
public static function getJsonDecodedResponseBodyContent(ResponseInterface $response): mixed {
return json_decode($response->getBody()->getContents(), null, 512, JSON_THROW_ON_ERROR);
}

/**
* @return bool
*/
public static function sendScenarioLineReferencesInXRequestId(): bool {
return (\getenv("SEND_SCENARIO_LINE_REFERENCES") === "true");
}

/**
* @return string
*/
public static function getXRequestIdRegex(): string {
if (self::sendScenarioLineReferencesInXRequestId()) {
return '/^[a-zA-Z]+\/[a-zA-Z]+\.feature:\d+(-\d+)?$/';
}
$host = gethostname();
return "/^$host\/.*$/";
}
}
41 changes: 20 additions & 21 deletions tests/acceptance/bootstrap/FeatureContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -145,8 +145,6 @@ class FeatureContext extends BehatVariablesContext {
* in the apiComments suite.
*/
private string $stepLineRef = '';
private bool $sendStepLineRef = false;
private bool $sendStepLineRefHasBeenChecked = false;

/**
* @var boolean true if TEST_SERVER_FED_URL is defined
Expand Down Expand Up @@ -416,17 +414,6 @@ public function isTestingWithLdap(): bool {
return (\getenv("TEST_WITH_LDAP") === "true");
}

/**
* @return bool
*/
public function sendScenarioLineReferencesInXRequestId(): ?bool {
if ($this->sendStepLineRefHasBeenChecked === false) {
$this->sendStepLineRef = (\getenv("SEND_SCENARIO_LINE_REFERENCES") === "true");
$this->sendStepLineRefHasBeenChecked = true;
}
return $this->sendStepLineRef;
}

/**
* @return bool
*/
Expand Down Expand Up @@ -880,7 +867,7 @@ public function getRemoteBaseUrlWithoutScheme(): string {
* @return string
*/
public function getStepLineRef(): string {
if (!$this->sendStepLineRef) {
if (!HttpRequestHelper::sendScenarioLineReferencesInXRequestId()) {
return '';
}

Expand Down Expand Up @@ -2435,6 +2422,14 @@ public function substituteInLineCodes(
"getUUIDv4Regex"
],
"parameter" => []
],
[
"code" => "%request_id_pattern%",
"function" => [
__NAMESPACE__ . '\TestHelpers\HttpRequestHelper',
"getXRequestIdRegex"
],
"parameter" => []
]
];
if ($user !== null) {
Expand Down Expand Up @@ -2522,11 +2517,15 @@ public function substituteInLineCodes(
$substitution["function"],
$substitution["parameter"]
);
foreach ($functions as $function => $parameters) {
$replacement = \call_user_func_array(
$function,
\array_merge([$replacement], $parameters)
);

// do not run functions on regex patterns
if (!\str_ends_with($value, "_pattern%")) {
foreach ($functions as $function => $parameters) {
$replacement = \call_user_func_array(
$function,
\array_merge([$replacement], $parameters)
);
}
}
$value = \str_replace(
$substitution["code"],
Expand Down Expand Up @@ -2644,7 +2643,7 @@ public function before(BeforeScenarioScope $scope): void {
$environment->registerContext($this->spacesContext);
}

if ($this->sendScenarioLineReferencesInXRequestId()) {
if (HttpRequestHelper::sendScenarioLineReferencesInXRequestId()) {
$this->scenarioString = $suiteName . '/' . $featureFileName . ':' . $scenarioLine;
} else {
$this->scenarioString = '';
Expand Down Expand Up @@ -2678,7 +2677,7 @@ public function before(BeforeScenarioScope $scope): void {
* @return void
*/
public function beforeEachStep(BeforeStepScope $scope): void {
if ($this->sendScenarioLineReferencesInXRequestId()) {
if (HttpRequestHelper::sendScenarioLineReferencesInXRequestId()) {
$this->stepLineRef = $this->scenarioString . '-' . $scope->getStep()->getLine();
} else {
$this->stepLineRef = '';
Expand Down
Loading