Skip to content

Commit

Permalink
Merge pull request #32079 from owncloud/stable10-acceptancetestsOCSv2
Browse files Browse the repository at this point in the history
[stable10] make sharing tests work correctly with ocs api v2
  • Loading branch information
DeepDiver1975 authored Jul 18, 2018
2 parents 8de80e8 + d1f026a commit 31cecde
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 36 deletions.
32 changes: 23 additions & 9 deletions tests/acceptance/features/bootstrap/BasicStructure.php
Original file line number Diff line number Diff line change
Expand Up @@ -551,30 +551,44 @@ public function isAPublicLinkUrl($url) {
/**
* @Then /^the OCS status code should be "([^"]*)"$/
*
* @param int $statusCode
* @param int|int[] $statusCode
* @param string $message
*
* @return void
*/
public function theOCSStatusCodeShouldBe($statusCode, $message = "") {
PHPUnit_Framework_Assert::assertEquals(
$statusCode, $this->getOCSResponseStatusCode($this->response),
$message
);
if (\is_array($statusCode)) {
PHPUnit_Framework_Assert::assertContains(
$this->getOCSResponseStatusCode($this->response), $statusCode,
$message
);
} else {
PHPUnit_Framework_Assert::assertEquals(
$statusCode, $this->getOCSResponseStatusCode($this->response),
$message
);
}
}

/**
* @Then /^the HTTP status code should be "([^"]*)"$/
*
* @param int $statusCode
* @param int|int[] $statusCode
* @param string $message
*
* @return void
*/
public function theHTTPStatusCodeShouldBe($statusCode, $message = "") {
PHPUnit_Framework_Assert::assertEquals(
$statusCode, $this->response->getStatusCode(), $message
);
if (\is_array($statusCode)) {
PHPUnit_Framework_Assert::assertContains(
$this->response->getStatusCode(), $statusCode,
$message
);
} else {
PHPUnit_Framework_Assert::assertEquals(
$statusCode, $this->response->getStatusCode(), $message
);
}
}

/**
Expand Down
56 changes: 29 additions & 27 deletions tests/acceptance/features/bootstrap/Sharing.php
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ public function theUserCreatesAShareWithSettings($body) {
*/
public function theUserHasCreatedAShareWithSettings($body) {
$this->userCreatesAShareWithSettings($this->currentUser, $body);
$this->theOCSStatusCodeShouldBe(100);
$this->theOCSStatusCodeShouldBe([100, 200]);
$this->theHTTPStatusCodeShouldBe(200);
}

Expand All @@ -151,22 +151,27 @@ public function createAPublicShare(
$sharePassword = null,
$permissions = null
) {
$this->response = SharingHelper::createShare(
$this->getBaseUrl(),
$user,
$this->getPasswordForUser($user),
$path,
'public',
null, // shareWith
$publicUpload,
$sharePassword,
$permissions,
null, // linkName
null, // expireDate
$this->apiVersion,
$this->sharingApiVersion
);

try {
$this->response = SharingHelper::createShare(
$this->getBaseUrl(),
$user,
$this->getPasswordForUser($user),
$path,
'public',
null, // shareWith
$publicUpload,
$sharePassword,
$permissions,
null, // linkName
null, // expireDate
$this->apiVersion,
$this->sharingApiVersion
);
} catch (BadResponseException $e) {
//in v2.php error HTTP codes are returned
//we need to be able to be able to check for them
$this->response = $e->getResponse();
}
$this->lastShareData = $this->response->xml();
}

Expand Down Expand Up @@ -570,11 +575,6 @@ public function userUpdatesTheLastShareWith($user, $body) {
} catch (BadResponseException $ex) {
$this->response = $ex->getResponse();
}

PHPUnit_Framework_Assert::assertEquals(
200,
$this->response->getStatusCode()
);
}

/**
Expand Down Expand Up @@ -905,7 +905,9 @@ public function userTriesToShareFileUsingTheApi($sharer, $filepath, $userOrGroup
*
* @return void
*/
public function userShouldBeAbleToShareUsingTheApi($sharer, $filepath, $userOrGroup, $sharee, $permissions = null) {
public function userShouldBeAbleToShareUsingTheApi(
$sharer, $filepath, $userOrGroup, $sharee, $permissions = null
) {
$shareType = ($userOrGroup === "user" ? 0 : 1);
$time = \time();
if ($this->lastShareTime !== null && $time - $this->lastShareTime < 1) {
Expand All @@ -918,10 +920,10 @@ public function userShouldBeAbleToShareUsingTheApi($sharer, $filepath, $userOrGr
$this->createShare(
$sharer, $filepath, $shareType, $sharee, null, null, $permissions
);
PHPUnit_Framework_Assert::assertEquals(
100,
$this->getOCSResponseStatusCode($this->response)
);

//v1.php returns 100 as success code
//v2.php returns 200 in the same case
$this->theOCSStatusCodeShouldBe([100, 200]);
}

/**
Expand Down

0 comments on commit 31cecde

Please sign in to comment.