Skip to content

Commit

Permalink
Merge pull request #35369 from HariBhandari07/stable10-expiration-date
Browse files Browse the repository at this point in the history
[Stable10] feature test for public link share expiration date deletion
  • Loading branch information
phil-davis authored May 30, 2019
2 parents 7be91da + 40631d8 commit 478cb6d
Show file tree
Hide file tree
Showing 5 changed files with 77 additions and 6 deletions.
9 changes: 6 additions & 3 deletions tests/acceptance/features/bootstrap/Sharing.php
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ private function waitToCreateShare() {
* | password | The password to protect the public link share with. |
* | expireDate | An expire date for public link shares. |
* | | This argument expects a date string. |
* | | in the format 'YYYY-MM-DD'. |
* | | in the format 'YYYY-MM-DD' or '+ x days'. |
* | permissions | The permissions to set on the share. |
* | | 1 = read; 2 = update; 4 = create; |
* | | 8 = delete; 16 = share; 31 = all |
Expand Down Expand Up @@ -647,7 +647,8 @@ public function isFieldInResponse($field, $contentExpected, $data = null) {
if ($data === null) {
$data = $this->getResponseXml()->data[0];
}
if ((string) $field === 'expiration') {
//do not try to convert empty date
if ((string) $field === 'expiration' && !empty($contentExpected)) {
$contentExpected
= \date(
'Y-m-d',
Expand All @@ -659,6 +660,9 @@ public function isFieldInResponse($field, $contentExpected, $data = null) {
}
if (\count($data->element) > 0) {
foreach ($data as $element) {
if (!isset($element->$field)) {
continue;
}
if ($contentExpected == "A_TOKEN") {
return (\strlen((string)$element->$field) == 15);
} elseif ($contentExpected == "A_NUMBER") {
Expand All @@ -673,7 +677,6 @@ public function isFieldInResponse($field, $contentExpected, $data = null) {
print($element->$field);
}
}

return false;
} else {
if ($contentExpected == "A_TOKEN") {
Expand Down
21 changes: 20 additions & 1 deletion tests/acceptance/features/bootstrap/WebUISharingContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -352,7 +352,14 @@ public function theUserChangeTheExpirationOfThePublicLinkNamedForTo($linkName, $
$session = $this->getSession();
$this->theUserOpensTheShareDialogForFileFolder($name);
$this->theUserHasOpenedThePublicLinkShareTab();
$this->publicShareTab->editLink($session, $linkName, null, null, null, $date);
$this->publicSharingPopup = $this->publicShareTab->editLink(
$session,
$linkName,
null,
null,
null,
$date
);
$this->publicShareTab->waitForAjaxCallsToStartAndFinish($session);
}

Expand Down Expand Up @@ -479,6 +486,18 @@ public function theUserShouldSeeAnErrorMessageOnThePublicLinkShareDialogSaying(
PHPUnit\Framework\Assert::assertEquals($expectedWarningMessage, $warningMessage);
}

/**
* @Then the user should see an error message on the public link popup saying :message
*
* @param string $message
*
* @return void
*/
public function theUserShouldSeeAnErrorMessageOnThPublicLinkPopupSaying($message) {
$errormessage = $this->publicSharingPopup->getErrorMessage();
PHPUnit\Framework\Assert::assertEquals($message, $errormessage);
}

/**
* @Then the public link should not have been generated
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ class EditPublicLinkPopup extends OwncloudPage {
'upload' => ".//label[contains(@for, 'sharingDialogAllowPublicUpload')]"
];
private $popupCloseButton = "//a[@class='oc-dialog-close']";
private $expirationDateRequiredErrorMessageXpath = './/*[@id="shareDialogExpirationView"]//span[@class="error-message"]';

/**
* sets the NodeElement for the current popup
Expand Down Expand Up @@ -171,7 +172,7 @@ public function setLinkExpirationDate($date) {
" could not find input field for the expiration date of the public link"
);
$expirationDateInput->setValue($date);

//try to close the date picker by clicking the label
//because that date picker might overlap the email field
//but do not panic if the label is not found, maybe we still can
Expand Down Expand Up @@ -334,4 +335,23 @@ public function waitTillPageIsLoaded(
$popupElement = $this->waitTillXpathIsVisible($xpath, $timeout_msec);
$this->setElement($popupElement);
}

/**
*
* @return $errorMessage
* @throws ElementNotFoundException
*/
public function getErrorMessage() {
$errorMessageElement = $this->popupElement->find(
"xpath",
$this->expirationDateRequiredErrorMessageXpath
);
$this->assertElementNotNull(
$errorMessageElement,
__METHOD__ .
" xpath $this->expirationDateRequiredErrorMessageXpath" .
" could not find expiration date required error message"
);
return $errorMessageElement->getText();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,7 @@ public function editLink(
} else {
$this->editPublicLinkPopupPageObject->cancel();
}
return $this->editPublicLinkPopupPageObject;
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -480,4 +480,32 @@ Feature: Share by public link
And the user opens the public link share tab
And the user changes the permission of the public link named "Public link" to "read-write"
And the public accesses the last created public link using the webUI
Then it should be possible to delete file "lorem-big.txt" using the webUI
Then it should be possible to delete file "lorem-big.txt" using the webUI

Scenario: user tries to deletes the expiration date of already existing public link using webUI when expiration date is enforced
Given parameter "shareapi_default_expire_date" of app "core" has been set to "yes"
And parameter "shareapi_enforce_expire_date" of app "core" has been set to "yes"
And user "user1" has created a share with settings
| path | lorem.txt |
| name | Public link |
| expireDate | + 5 days |
| shareType | 3 |
When the user reloads the current page of the webUI
And the user changes the expiration of the public link named "Public link" of file "lorem.txt" to " "
Then the user should see an error message on the public link popup saying "Expiration date is required"
And the user gets the info of the last share using the sharing API
And the fields of the last response should include
| expiration | + 5 days |

Scenario: user deletes the expiration date of already existing public link using webUI when expiration date is set but not enforced
Given parameter "shareapi_default_expire_date" of app "core" has been set to "yes"
And user "user1" has created a share with settings
| path | lorem.txt |
| name | Public link |
| expireDate | + 5 days |
| shareType | 3 |
When the user reloads the current page of the webUI
And the user changes the expiration of the public link named "Public link" of file "lorem.txt" to " "
And the user gets the info of the last share using the sharing API
And the fields of the last response should include
| expiration | |

0 comments on commit 478cb6d

Please sign in to comment.