Skip to content

Commit

Permalink
Merge pull request #35930 from owncloud/stable10-publicshare-content
Browse files Browse the repository at this point in the history
[stable10] acceptance tests for checking the content of public link share
  • Loading branch information
phil-davis committed Jul 26, 2019
2 parents 3448a95 + 1553e6f commit f217552
Show file tree
Hide file tree
Showing 7 changed files with 141 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1326,3 +1326,26 @@ Feature: sharing
| ocs_api_version | ocs_status_code |
| 1 | 100 |
| 2 | 200 |

@public_link_share-feature-required
Scenario Outline: Creating a new public link share of a folder, and checking it's content
Given using OCS API version "<ocs_api_version>"
When user "user0" creates a public link share using the sharing API with settings
| path | PARENT |
Then the OCS status code should be "<ocs_status_code>"
And the HTTP status code should be "200"
And the fields of the last response should include
| item_type | folder |
| file_target | /PARENT |
| path | /PARENT |
| share_type | public_link |
| displayname_file_owner | User Zero |
| displayname_owner | User Zero |
| uid_file_owner | user0 |
| uid_owner | user0 |
When the public downloads file "/parent.txt" from inside the last public shared folder using the public WebDAV API
Then the downloaded content should be "ownCloud test text file parent" plus end-of-line
Examples:
| ocs_api_version | ocs_status_code |
| 1 | 100 |
| 2 | 200 |
4 changes: 2 additions & 2 deletions tests/acceptance/features/bootstrap/PublicWebDavContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ public function renameFileFromPublicShare($fileName, $toFileName) {
HttpRequestHelper::sendRequest($fullUrl, "MOVE", $token, "", $headers)
);
}

/**
* @When /^the public downloads file "([^"]*)" from inside the last public shared folder using the public WebDAV API$/
*
Expand Down Expand Up @@ -463,7 +463,7 @@ public function publicUploadContent(
$url .= \ltrim($filename, '/');
$token = $this->featureContext->getLastShareToken();
$headers = ['X-Requested-With' => 'XMLHttpRequest'];

if ($autorename) {
$headers['OC-Autorename'] = 1;
}
Expand Down
23 changes: 23 additions & 0 deletions tests/acceptance/features/bootstrap/WebUIFilesContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,11 @@
use Page\FilesPageElement\ConflictDialog;
use Page\FilesPageElement\FileActionsMenu;
use Page\GeneralExceptionPage;
use PHPUnit\Framework\Assert;
use SensioLabs\Behat\PageObjectExtension\PageObject\Exception\ElementNotFoundException;
use TestHelpers\DeleteHelper;
use TestHelpers\Asserts\WebDav as WebDavAssert;
use TestHelpers\HttpRequestHelper;

require_once 'bootstrap.php';

Expand Down Expand Up @@ -2043,6 +2045,27 @@ public function theUserOpensTheFileActionMenuOfFileFolderOnTheWebui($name) {
$this->openedFileActionMenu = $this->selectedFileRow->openFileActionsMenu($session);
}

/**
* @When the public/user downloads file/folder :fileName using the webUI
*
* @param string $fileName Name of the file/Folder
*
* @return ResponseInterface
*/
public function userDownloadsFile($fileName) {
$session = $this->getSession();
$this->selectedFileRow = $this->getCurrentPageObject()->findFileRowByName($fileName, $session);
$this->openedFileActionMenu = $this->selectedFileRow->openFileActionsMenu($session);
$url = $this->openedFileActionMenu->getDownloadUrlForFile();
$baseUrl = $this->featureContext->getBaseUrlWithoutPath();
$this->response = HttpRequestHelper::get($baseUrl . $url);
Assert::assertEquals(
200,
$this->response->getStatusCode()
);
$this->featureContext->setResponse($this->response);
}

/**
* @Then the user should see :action_label file action translated to :translated_label on the webUI
*
Expand Down
18 changes: 15 additions & 3 deletions tests/acceptance/features/bootstrap/WebUISharingContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -1448,7 +1448,7 @@ public function theTextPreviewOfThePublicLinkShouldContain($content) {
* @return void
*/
public function theContentOfTheFileSharedByLastPublicLinkShouldBeTheSameAs($originalFile) {
$response = $this->thePublicDownloadsTheLastCreatedFileUsingTheWebui();
$response = $this->thePublicDownloadsAllTheSharedDataUsingTheWebui();
PHPUnit\Framework\Assert::assertEquals(200, $response->getStatusCode());
$body = $response->getBody()->getContents();

Expand All @@ -1462,15 +1462,27 @@ public function theContentOfTheFileSharedByLastPublicLinkShouldBeTheSameAs($orig
}

/**
* @When the public downloads the last created file/folder using the webUI
* @When the public downloads all the shared data using the webUI
*
* @return ResponseInterface
*/
public function thePublicDownloadsTheLastCreatedFileUsingTheWebui() {
public function thePublicDownloadsAllTheSharedDataUsingTheWebui() {
$url = $this->publicLinkFilesPage->getDownloadUrl();
return HttpRequestHelper::get($url);
}

/**
* @Then all the links to download the public share should be the same
*
* @return void
* @throws \Exception
*/
public function allThePublicShareDownloadLinkShouldBeSame() {
$urls = $this->publicLinkFilesPage->getAllDownloadUrls();
$url = \array_unique($urls);
PHPUnit\Framework\Assert::assertCount(1, $url, "Download links are not the same");
}

/**
* @Then the email address :address should have received an email containing the last shared public link
*
Expand Down
19 changes: 19 additions & 0 deletions tests/acceptance/features/lib/FilesPageElement/FileActionsMenu.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ class FileActionsMenu extends OwncloudPage {
protected $deleteActionLabel = "Delete";
protected $detailsActionLabel = "Details";
protected $declineShareDataAction = "Reject";
protected $fileRowDownloadBtnXpath = "//td[@class='filename']//a[@class='name']";

/**
* sets the NodeElement for the current action menu
Expand Down Expand Up @@ -121,6 +122,24 @@ public function delete() {
$deleteBtn->click();
}

/**
* gets the url to download a file/folder
*
* @return null|string
*/
public function getDownloadUrlForFile() {
$downloadBtn = $this->find("xpath", $this->fileRowDownloadBtnXpath);
$this->assertElementNotNull(
$downloadBtn,
__METHOD__ . " xpath $this->fileRowDownloadBtnXpath " .
" could not find download button"
);
if ($downloadBtn->hasAttribute("href")) {
return $downloadBtn->getAttribute("href");
}
return null;
}

/**
* clicks the details button
*
Expand Down
43 changes: 38 additions & 5 deletions tests/acceptance/features/lib/PublicLinkFilesPage.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,14 +39,17 @@ class PublicLinkFilesPage extends FilesPageBasic {
protected $uploadFormXpath = "//div[@class='uploadForm']";
protected $emptyContentXpath = ".//div[@id='emptycontent']";
protected $addToYourOcBtnId = "save-button";
protected $singleFileDownloadBtnXpath = "//a[@id='download']";
protected $DownloadBtnXpath = "//a[@id='download']";
protected $directLinkXpath = "//input[@id='directLink']";
protected $downloadFileXpath = "//a[@id='downloadFile']";
protected $textPreviewContainerXpath = "//div[@class='text-preview']";
protected $remoteAddressInputId = "remote_address";
protected $confirmBtnId = "save-button-confirm";
protected $passwordFieldId = 'password';
protected $passwordSubmitButtonId = 'password-submit';
protected $warningMessageCss = '.warning';
protected $deleteAllSelectedBtnXpath = "//a[@class='delete-selected']";

/**
*
* @var FilesPageCRUD $filesPageCRUDFunctions
Expand Down Expand Up @@ -143,7 +146,7 @@ public function addToServer($server) {
);
$confirmBtn->click();
}

/**
* create a folder with the given name.
* If name is not given a random one is chosen
Expand Down Expand Up @@ -227,10 +230,10 @@ public function getPreviewText() {
* @throws ElementNotFoundException
*/
public function getDownloadUrl() {
$downloadBtn = $this->find("xpath", $this->singleFileDownloadBtnXpath);
$downloadBtn = $this->find("xpath", $this->DownloadBtnXpath);
$this->assertElementNotNull(
$downloadBtn,
__METHOD__ . " xpath $this->singleFileDownloadBtnXpath " .
__METHOD__ . " xpath $this->DownloadBtnXpath " .
" could not find download button"
);
if ($downloadBtn->hasAttribute("href")) {
Expand All @@ -239,6 +242,36 @@ public function getDownloadUrl() {
return null;
}

/**
* returns all the download url from single file download page
*
* @return array
* @throws ElementNotFoundException
*/
public function getAllDownloadUrls() {
$downloadBtn = $this->find("xpath", $this->DownloadBtnXpath);
$downloadFileBtn = $this->find("xpath", $this->downloadFileXpath);
$directLink = $this->find("xpath", $this->directLinkXpath);
$this->assertElementNotNull(
$downloadBtn,
__METHOD__ . " xpath $this->DownloadBtnXpath " .
" could not find download button"
);
$this->assertElementNotNull(
$downloadFileBtn,
__METHOD__ . " xpath $this->DownloadBtnXpath " .
" could not find download file button"
);
$this->assertElementNotNull(
$directLink,
__METHOD__ . " xpath $this->DownloadBtnXpath " .
" could not find direct link"
);
$url1 = $downloadBtn->getAttribute("href");
$url2 = $downloadFileBtn->getAttribute("href");
$url3 = $directLink->getAttribute("value");
return [$url1, $url2, $url3];
}
/**
* enter public link password
*
Expand Down Expand Up @@ -334,7 +367,7 @@ public function waitTillPageIsLoaded(
while ($currentTime <= $end) {
$fileList = $this->find('xpath', $this->getFileListXpath());
$downloadButton = $this->find(
"xpath", $this->singleFileDownloadBtnXpath
"xpath", $this->DownloadBtnXpath
);
$uploadForm = $this->find(
"xpath", $this->uploadFormXpath
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -643,4 +643,24 @@ Feature: Share by public link
When the user creates a new public link for file "lorem.txt" using the webUI
And user "user1" gets the info of the last share using the sharing API
Then the fields of the last response should include
| expiration | +7 days |
| expiration | +7 days |

Scenario: user creates a new public link and the public checks its content
Given user "user1" has created folder "/simple-folder"
And user "user1" has uploaded file with content "original content" to "/simple-folder/lorem.txt"
And user "user1" has logged in using the webUI
When the user creates a new public link for folder "simple-folder" using the webUI
And the user logs out of the webUI
And the public accesses the last created public link using the webUI
Then file "lorem.txt" should be listed on the webUI
When the public downloads file "lorem.txt" using the webUI
Then the downloaded content should be "original content"

Scenario: user creates a new public link for a file and the public checks all the download links for the file
Given user "user1" has uploaded file with content "original content" to "/lorem.txt"
And user "user1" has logged in using the webUI
When the user creates a new public link for file "lorem.txt" using the webUI
And the user logs out of the webUI
And the public accesses the last created public link using the webUI
Then the text preview of the public link should contain "original content"
And all the links to download the public share should be the same

0 comments on commit f217552

Please sign in to comment.