Skip to content

Commit

Permalink
set the version inside hroupfoldercontext file
Browse files Browse the repository at this point in the history
Signed-off-by: nabim777 <[email protected]>
  • Loading branch information
nabim777 committed Oct 3, 2024
1 parent 6c3dce9 commit f6e9eb5
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 42 deletions.
38 changes: 4 additions & 34 deletions tests/acceptance/features/bootstrap/FeatureContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ class FeatureContext implements Context {
public int $lastUpLoadTime;
private SharingContext $sharingContext;
private DirectUploadContext $directUploadContext;

/**
* @var array<string|null>
*/
Expand All @@ -47,11 +46,6 @@ class FeatureContext implements Context {

private CookieJar $cookieJar;
private string $requestToken;
private string $groupFolderDavPath;

public function getGroupfolderDavPath(): string {
return $this->groupFolderDavPath;
}

public function getAdminUsername(): string {
return $this->adminUsername;
Expand Down Expand Up @@ -516,7 +510,7 @@ public function theHTTPStatusCodeShouldBe(
if (\is_array($expectedStatusCode)) {
if ($message === "") {
$message = "HTTP status code $actualStatusCode is not one of the expected values " .
\implode(" or ", $expectedStatusCode);
\implode(" or ", $expectedStatusCode);
}

Assert::assertContainsEquals(
Expand Down Expand Up @@ -833,7 +827,7 @@ public function makeDavRequest(
?string $method,
?string $path,
?array $headers = null,
$body = null,
$body = null,
string $type = 'files'
): ResponseInterface {
$davPath = self::getDavPath($user, $type);
Expand Down Expand Up @@ -1092,8 +1086,8 @@ public function sendRequestsToAppEndpoint(
?string $password,
string $method,
string $endpoint,
$data = null,
$headers = null
$data = null,
$headers = null
) {
$fullUrl = $this->getBaseUrl();
$fullUrl .= "index.php/apps/integration_openproject/" . $endpoint;
Expand Down Expand Up @@ -1162,7 +1156,6 @@ public function verifyTableNodeRows(TableNode $table, array $requiredRows = [],
* @param BeforeScenarioScope $scope
*
* @return void
* @throws Exception
*/
public function before(BeforeScenarioScope $scope):void {
setlocale(LC_ALL, 'C.utf8');
Expand All @@ -1175,29 +1168,6 @@ public function before(BeforeScenarioScope $scope):void {
$this->sharingContext = $environment->getContext('SharingContext');
$this->directUploadContext = $environment->getContext('DirectUploadContext');
}
$this->setGroupfolderDavPath();
}

/**
* This will run before EVERY scenario.
* It will set the group folder DAV path
*
* @return void
* @throws Exception
*/
private function setGroupfolderDavPath(): void {
// groupfolder with version greater then 19.0.0 uses "ocs/v2.php/" endpoint
$capabilitiesResponse = $this->sendOCSRequest(
'/cloud/capabilities', 'GET', $this->getAdminUsername()
);
$this->theHTTPStatusCodeShouldBe(200, "", $capabilitiesResponse);
$responseAsJson = json_decode($capabilitiesResponse->getBody()->getContents());
$groupFolderVersion = $responseAsJson->ocs->data->capabilities->integration_openproject->groupfolder_version ?? null;
Assert::assertNotNull($groupFolderVersion, 'Group folder version not found in the response');
$this->groupFolderDavPath = "index.php/";
if (version_compare($groupFolderVersion, '19') >= 0) {
$this->groupFolderDavPath = "ocs/v2.php/";
}
}

/**
Expand Down
36 changes: 28 additions & 8 deletions tests/acceptance/features/bootstrap/GroupfoldersContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,14 @@ class GroupfoldersContext implements Context {

/** @var array<mixed> */
private array $createdGroupFolders = [];
private string $groupFolderDavPath;

/**
* @Given group folder :folderName has been created
*/
public function groupFolderHasBeenCreated(string $folderName): void {
$groupFolderDavPath = $this->featureContext->getGroupFolderDavPath();
$fullUrl = $this->featureContext->getBaseUrl() .
"$groupFolderDavPath" . "apps/groupfolders/folders";
"$this->groupFolderDavPath" . "apps/groupfolders/folders";
$headers['OCS-APIRequest'] = 'true';
$options = [
'multipart' => [
Expand Down Expand Up @@ -52,9 +52,8 @@ public function groupFolderHasBeenCreated(string $folderName): void {
*/
public function groupHasBeenAddedToGroupFolder(string $group, string $groupfolder):void {
$groupfolderId = $this->createdGroupFolders[$groupfolder];
$groupFolderDavPath = $this->featureContext->getGroupFolderDavPath();
$fullUrl = $this->featureContext->getBaseUrl() .
"$groupFolderDavPath". "apps/groupfolders/folders/".$groupfolderId. "/groups";
"$this->groupFolderDavPath". "apps/groupfolders/folders/".$groupfolderId. "/groups";
$headers['OCS-APIRequest'] = 'true';
$options = [
'multipart' => [
Expand Down Expand Up @@ -157,9 +156,8 @@ private function getGroupfolderByMountpoint(string $mountpoint): array {
* @throws GuzzleException
*/
private function getAllGroupfolders() {
$groupFolderDavPath = $this->featureContext->getGroupFolderDavPath();
$fullUrl = $this->featureContext->getBaseUrl() .
"$groupFolderDavPath". "apps/groupfolders/folders?format=json";
"$this->groupFolderDavPath". "apps/groupfolders/folders?format=json";

$headers['Content-Type'] = 'application/json';
$headers['OCS-APIRequest'] = 'true';
Expand All @@ -178,9 +176,8 @@ private function getAllGroupfolders() {
}

private function adminDeletesGroupfolder(int $id): void {
$groupFolderDavPath = $this->featureContext->getGroupFolderDavPath();
$fullUrl = $this->featureContext->getBaseUrl() .
"$groupFolderDavPath". "apps/groupfolders/folders/" . $id;
"$this->groupFolderDavPath". "apps/groupfolders/folders/" . $id;
$headers['OCS-APIRequest'] = 'true';
$this->featureContext->sendHttpRequest(
$fullUrl,
Expand Down Expand Up @@ -209,6 +206,29 @@ public function before(BeforeScenarioScope $scope):void {
if ($environment instanceof InitializedContextEnvironment) {
$this->featureContext = $environment->getContext('FeatureContext');
}
$this->setGroupfolderDavPath();
}

/**
* This will run before EVERY scenario.
* It will set the group folder DAV path
*
* @return void
* @throws Exception
*/
private function setGroupfolderDavPath(): void {
// groupfolder with version greater then 19.0.0 uses "ocs/v2.php/" endpoint
$capabilitiesResponse = $this->featureContext->sendOCSRequest(
'/cloud/capabilities', 'GET', $this->featureContext->getAdminUsername()
);
$this->featureContext->theHTTPStatusCodeShouldBe(200, "", $capabilitiesResponse);
$responseAsJson = json_decode($capabilitiesResponse->getBody()->getContents());
$groupFolderVersion = $responseAsJson->ocs->data->capabilities->integration_openproject->groupfolder_version ?? null;
Assert::assertNotNull($groupFolderVersion, 'Group folder version not found in the response');
$this->groupFolderDavPath = "index.php/";
if (version_compare($groupFolderVersion, '19') >= 0) {
$this->groupFolderDavPath = "ocs/v2.php/";
}
}

/**
Expand Down

0 comments on commit f6e9eb5

Please sign in to comment.