Skip to content

Commit e6902ce

Browse files
authored
Merge pull request #10205 from owncloud/tests/fix-shares-propfind
[tests-only][full-ci] fix shares propfind tests
2 parents 7da4086 + ca82ac0 commit e6902ce

File tree

15 files changed

+328
-302
lines changed

15 files changed

+328
-302
lines changed

tests/acceptance/TestHelpers/CollaborationHelper.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@
2929
* A helper class for managing wopi requests
3030
*/
3131
class CollaborationHelper {
32-
3332
/**
3433
* @param string $fileId
3534
* @param string $app

tests/acceptance/TestHelpers/GraphHelper.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,7 @@ public static function getShareIdRegex(): string {
116116
public static function getEtagRegex(): string {
117117
return "^\\\"[a-f0-9:.]{1,32}\\\"$";
118118
}
119+
119120
/**
120121
* Federated users have a base64 encoded string of {remoteid}@{provider} as their id
121122
* This regex matches only non empty base64 encoded strings
@@ -126,6 +127,19 @@ public static function getFederatedUserRegex(): string {
126127
return '^(?:[A-Za-z0-9+/]{4})*(?:[A-Za-z0-9+/]{2}==|[A-Za-z0-9+/]{3}=|[A-Za-z0-9+/]{4})$';
127128
}
128129

130+
/**
131+
* @param string $pattern
132+
*
133+
* @return string regex pattern
134+
*/
135+
public static function jsonSchemaRegexToPureRegex(string $pattern): string {
136+
$pattern = \str_replace("\\\\", "\\", $pattern);
137+
$pattern = \str_replace("/", "\/", $pattern);
138+
$pattern = \preg_replace('/^\^/', '', $pattern);
139+
$pattern = \preg_replace('/\$$/', '', $pattern);
140+
return "/^$pattern$/";
141+
}
142+
129143
/**
130144
* Key name can consist of @@@
131145
* This function separate such key and return its actual value from actual drive response which can be used for assertion

tests/acceptance/TestHelpers/HttpRequestHelper.php

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -665,4 +665,22 @@ public static function getRequestTimeout(): int {
665665
public static function getJsonDecodedResponseBodyContent(ResponseInterface $response): mixed {
666666
return json_decode($response->getBody()->getContents(), null, 512, JSON_THROW_ON_ERROR);
667667
}
668+
669+
/**
670+
* @return bool
671+
*/
672+
public static function sendScenarioLineReferencesInXRequestId(): bool {
673+
return (\getenv("SEND_SCENARIO_LINE_REFERENCES") === "true");
674+
}
675+
676+
/**
677+
* @return string
678+
*/
679+
public static function getXRequestIdRegex(): string {
680+
if (self::sendScenarioLineReferencesInXRequestId()) {
681+
return '/^[a-zA-Z]+\/[a-zA-Z]+\.feature:\d+(-\d+)?$/';
682+
}
683+
$host = gethostname();
684+
return "/^$host\/.*$/";
685+
}
668686
}

tests/acceptance/bootstrap/FeatureContext.php

Lines changed: 20 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -145,8 +145,6 @@ class FeatureContext extends BehatVariablesContext {
145145
* in the apiComments suite.
146146
*/
147147
private string $stepLineRef = '';
148-
private bool $sendStepLineRef = false;
149-
private bool $sendStepLineRefHasBeenChecked = false;
150148

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

419-
/**
420-
* @return bool
421-
*/
422-
public function sendScenarioLineReferencesInXRequestId(): ?bool {
423-
if ($this->sendStepLineRefHasBeenChecked === false) {
424-
$this->sendStepLineRef = (\getenv("SEND_SCENARIO_LINE_REFERENCES") === "true");
425-
$this->sendStepLineRefHasBeenChecked = true;
426-
}
427-
return $this->sendStepLineRef;
428-
}
429-
430417
/**
431418
* @return bool
432419
*/
@@ -880,7 +867,7 @@ public function getRemoteBaseUrlWithoutScheme(): string {
880867
* @return string
881868
*/
882869
public function getStepLineRef(): string {
883-
if (!$this->sendStepLineRef) {
870+
if (!HttpRequestHelper::sendScenarioLineReferencesInXRequestId()) {
884871
return '';
885872
}
886873

@@ -2435,6 +2422,14 @@ public function substituteInLineCodes(
24352422
"getUUIDv4Regex"
24362423
],
24372424
"parameter" => []
2425+
],
2426+
[
2427+
"code" => "%request_id_pattern%",
2428+
"function" => [
2429+
__NAMESPACE__ . '\TestHelpers\HttpRequestHelper',
2430+
"getXRequestIdRegex"
2431+
],
2432+
"parameter" => []
24382433
]
24392434
];
24402435
if ($user !== null) {
@@ -2522,11 +2517,15 @@ public function substituteInLineCodes(
25222517
$substitution["function"],
25232518
$substitution["parameter"]
25242519
);
2525-
foreach ($functions as $function => $parameters) {
2526-
$replacement = \call_user_func_array(
2527-
$function,
2528-
\array_merge([$replacement], $parameters)
2529-
);
2520+
2521+
// do not run functions on regex patterns
2522+
if (!\str_ends_with($value, "_pattern%")) {
2523+
foreach ($functions as $function => $parameters) {
2524+
$replacement = \call_user_func_array(
2525+
$function,
2526+
\array_merge([$replacement], $parameters)
2527+
);
2528+
}
25302529
}
25312530
$value = \str_replace(
25322531
$substitution["code"],
@@ -2644,7 +2643,7 @@ public function before(BeforeScenarioScope $scope): void {
26442643
$environment->registerContext($this->spacesContext);
26452644
}
26462645

2647-
if ($this->sendScenarioLineReferencesInXRequestId()) {
2646+
if (HttpRequestHelper::sendScenarioLineReferencesInXRequestId()) {
26482647
$this->scenarioString = $suiteName . '/' . $featureFileName . ':' . $scenarioLine;
26492648
} else {
26502649
$this->scenarioString = '';
@@ -2678,7 +2677,7 @@ public function before(BeforeScenarioScope $scope): void {
26782677
* @return void
26792678
*/
26802679
public function beforeEachStep(BeforeStepScope $scope): void {
2681-
if ($this->sendScenarioLineReferencesInXRequestId()) {
2680+
if (HttpRequestHelper::sendScenarioLineReferencesInXRequestId()) {
26822681
$this->stepLineRef = $this->scenarioString . '-' . $scope->getStep()->getLine();
26832682
} else {
26842683
$this->stepLineRef = '';

0 commit comments

Comments
 (0)