From ec06368f417242a08bedf7b0395ec884d524fcb5 Mon Sep 17 00:00:00 2001 From: Hari Bhandari Date: Wed, 8 May 2019 13:23:50 +0545 Subject: [PATCH 1/3] feature test for public link share expiration date deletion --- .../updateShare.feature | 2 +- .../acceptance/features/bootstrap/Sharing.php | 9 ++--- .../bootstrap/WebUISharingContext.php | 21 +++++++++++- .../EditPublicLinkPopup.php | 22 +++++++++++- .../SharingDialogElement/PublicLinkTab.php | 1 + .../shareByPublicLink.feature | 34 +++++++++++++++++-- 6 files changed, 79 insertions(+), 10 deletions(-) diff --git a/tests/acceptance/features/apiShareManagementBasic/updateShare.feature b/tests/acceptance/features/apiShareManagementBasic/updateShare.feature index c37597cf0ea7..d6bf0b022542 100644 --- a/tests/acceptance/features/apiShareManagementBasic/updateShare.feature +++ b/tests/acceptance/features/apiShareManagementBasic/updateShare.feature @@ -35,7 +35,7 @@ Feature: sharing And the user gets the info of the last share using the sharing API Then the OCS status code should be "" And the HTTP status code should be "200" - And the fields of the last response should include + And the fields of the last share response should include | id | A_NUMBER | | item_type | folder | | item_source | A_NUMBER | diff --git a/tests/acceptance/features/bootstrap/Sharing.php b/tests/acceptance/features/bootstrap/Sharing.php index 7a7e77a0d5a4..2673c0b2a481 100644 --- a/tests/acceptance/features/bootstrap/Sharing.php +++ b/tests/acceptance/features/bootstrap/Sharing.php @@ -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 | @@ -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', @@ -673,7 +674,6 @@ public function isFieldInResponse($field, $contentExpected, $data = null) { print($element->$field); } } - return false; } else { if ($contentExpected == "A_TOKEN") { @@ -1299,6 +1299,7 @@ public function checkingTheResponseEntriesCount($count) { } /** + * @Then the fields of the last response should include * * @param TableNode|null $body @@ -1311,7 +1312,7 @@ public function checkFields($body) { foreach ($fd as $field => $value) { $value = $this->replaceValuesFromTable($field, $value); - if (!$this->isFieldInResponse($field, $value)) { + if (!$this->isFieldInShareResponse($field, $value)) { PHPUnit\Framework\Assert::fail( "$field doesn't have value $value" ); diff --git a/tests/acceptance/features/bootstrap/WebUISharingContext.php b/tests/acceptance/features/bootstrap/WebUISharingContext.php index b23731cada47..96eedde593a9 100644 --- a/tests/acceptance/features/bootstrap/WebUISharingContext.php +++ b/tests/acceptance/features/bootstrap/WebUISharingContext.php @@ -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); } @@ -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 * diff --git a/tests/acceptance/features/lib/FilesPageElement/SharingDialogElement/EditPublicLinkPopup.php b/tests/acceptance/features/lib/FilesPageElement/SharingDialogElement/EditPublicLinkPopup.php index 4cf0a29a6020..dabdfb04f5ed 100644 --- a/tests/acceptance/features/lib/FilesPageElement/SharingDialogElement/EditPublicLinkPopup.php +++ b/tests/acceptance/features/lib/FilesPageElement/SharingDialogElement/EditPublicLinkPopup.php @@ -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 @@ -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 @@ -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(); + } } diff --git a/tests/acceptance/features/lib/FilesPageElement/SharingDialogElement/PublicLinkTab.php b/tests/acceptance/features/lib/FilesPageElement/SharingDialogElement/PublicLinkTab.php index 89a8e6880442..d2bf1ec0932a 100644 --- a/tests/acceptance/features/lib/FilesPageElement/SharingDialogElement/PublicLinkTab.php +++ b/tests/acceptance/features/lib/FilesPageElement/SharingDialogElement/PublicLinkTab.php @@ -233,6 +233,7 @@ public function editLink( } else { $this->editPublicLinkPopupPageObject->cancel(); } + return $this->editPublicLinkPopupPageObject; } /** diff --git a/tests/acceptance/features/webUISharingPublic/shareByPublicLink.feature b/tests/acceptance/features/webUISharingPublic/shareByPublicLink.feature index 6d3f2f17acc2..90258f72d8c5 100644 --- a/tests/acceptance/features/webUISharingPublic/shareByPublicLink.feature +++ b/tests/acceptance/features/webUISharingPublic/shareByPublicLink.feature @@ -299,7 +299,7 @@ Feature: Share by public link | shareType | 3 | When the user changes the expiration of the public link named "Public link" of file "lorem.txt" to "21-07-2038" And the user gets the info of the last share using the sharing API - Then the fields of the last response should include + Then the share fields of the last share should include | expiration | 21-07-2038 | Scenario: user tries to change the expiration date of the public link to past date using webUI @@ -311,7 +311,7 @@ Feature: Share by public link When the user changes the expiration of the public link named "Public link" of file "lorem.txt" to "14-09-2017" And the user gets the info of the last share using the sharing API Then the user should see an error message on the public link share dialog saying "Expiration date is in the past" - And the fields of the last response should include + And the share fields of the last share should include | expiration | 14-10-2038 | Scenario: share two file with same name but different paths by public link @@ -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 \ No newline at end of file + 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 share fields of the last share 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 share fields of the last share should include + | expiration | | \ No newline at end of file From ce6ccdf868f556c75e9ba135e60e54a7126cd442 Mon Sep 17 00:00:00 2001 From: Hari Bhandari Date: Wed, 22 May 2019 15:27:02 +0545 Subject: [PATCH 2/3] fix1 --- tests/acceptance/features/bootstrap/Sharing.php | 6 ++++-- .../webUISharingPublic/shareByPublicLink.feature | 10 +++++----- 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/tests/acceptance/features/bootstrap/Sharing.php b/tests/acceptance/features/bootstrap/Sharing.php index 2673c0b2a481..3d422123e032 100644 --- a/tests/acceptance/features/bootstrap/Sharing.php +++ b/tests/acceptance/features/bootstrap/Sharing.php @@ -660,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") { @@ -1299,7 +1302,6 @@ public function checkingTheResponseEntriesCount($count) { } /** - * @Then the fields of the last response should include * * @param TableNode|null $body @@ -1312,7 +1314,7 @@ public function checkFields($body) { foreach ($fd as $field => $value) { $value = $this->replaceValuesFromTable($field, $value); - if (!$this->isFieldInShareResponse($field, $value)) { + if (!$this->isFieldInResponse($field, $value)) { PHPUnit\Framework\Assert::fail( "$field doesn't have value $value" ); diff --git a/tests/acceptance/features/webUISharingPublic/shareByPublicLink.feature b/tests/acceptance/features/webUISharingPublic/shareByPublicLink.feature index 90258f72d8c5..e39e154bd957 100644 --- a/tests/acceptance/features/webUISharingPublic/shareByPublicLink.feature +++ b/tests/acceptance/features/webUISharingPublic/shareByPublicLink.feature @@ -299,7 +299,7 @@ Feature: Share by public link | shareType | 3 | When the user changes the expiration of the public link named "Public link" of file "lorem.txt" to "21-07-2038" And the user gets the info of the last share using the sharing API - Then the share fields of the last share should include + Then the fields of the last response should include | expiration | 21-07-2038 | Scenario: user tries to change the expiration date of the public link to past date using webUI @@ -311,7 +311,7 @@ Feature: Share by public link When the user changes the expiration of the public link named "Public link" of file "lorem.txt" to "14-09-2017" And the user gets the info of the last share using the sharing API Then the user should see an error message on the public link share dialog saying "Expiration date is in the past" - And the share fields of the last share should include + And the fields of the last response should include | expiration | 14-10-2038 | Scenario: share two file with same name but different paths by public link @@ -494,7 +494,7 @@ Feature: Share by public link 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 share fields of the last share should include + 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 @@ -507,5 +507,5 @@ Feature: Share by public link 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 share fields of the last share should include - | expiration | | \ No newline at end of file + And the fields of the last response should include + | expiration | | \ No newline at end of file From 40631d84e8639b1ca91818328df326e6479b401c Mon Sep 17 00:00:00 2001 From: Hari Bhandari Date: Thu, 23 May 2019 12:39:09 +0545 Subject: [PATCH 3/3] fix2 --- .../features/apiShareManagementBasic/updateShare.feature | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/acceptance/features/apiShareManagementBasic/updateShare.feature b/tests/acceptance/features/apiShareManagementBasic/updateShare.feature index d6bf0b022542..c37597cf0ea7 100644 --- a/tests/acceptance/features/apiShareManagementBasic/updateShare.feature +++ b/tests/acceptance/features/apiShareManagementBasic/updateShare.feature @@ -35,7 +35,7 @@ Feature: sharing And the user gets the info of the last share using the sharing API Then the OCS status code should be "" And the HTTP status code should be "200" - And the fields of the last share response should include + And the fields of the last response should include | id | A_NUMBER | | item_type | folder | | item_source | A_NUMBER |