Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
61 changes: 46 additions & 15 deletions tests/acceptance/features/bootstrap/WebUIFilesContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
use Page\TrashbinPage;
use Page\FilesPageElement\ConflictDialog;
use Page\FilesPageElement\FileActionsMenu;
use Page\GeneralExceptionPage;
use SensioLabs\Behat\PageObjectExtension\PageObject\Exception\ElementNotFoundException;
use TestHelpers\DeleteHelper;
use TestHelpers\Asserts\WebDav as WebDavAssert;
Expand Down Expand Up @@ -144,6 +145,12 @@ class WebUIFilesContext extends RawMinkContext implements Context {

private $uploadConflictDialogTitle = "file conflict";

/**
*
* @var GeneralExceptionPage
*/
private $generalExceptionPage;

/**
* WebUIFilesContext constructor.
*
Expand All @@ -155,6 +162,7 @@ class WebUIFilesContext extends RawMinkContext implements Context {
* @param TagsPage $tagsPage
* @param SharedByLinkPage $sharedByLinkPage
* @param SharedWithOthersPage $sharedWithOthersPage
* @param GeneralExceptionPage $generalExceptionPage
*
* @return void
*/
Expand All @@ -166,7 +174,8 @@ public function __construct(
SharedWithYouPage $sharedWithYouPage,
TagsPage $tagsPage,
SharedByLinkPage $sharedByLinkPage,
SharedWithOthersPage $sharedWithOthersPage
SharedWithOthersPage $sharedWithOthersPage,
GeneralExceptionPage $generalExceptionPage
) {
$this->trashbinPage = $trashbinPage;
$this->filesPage = $filesPage;
Expand All @@ -176,6 +185,7 @@ public function __construct(
$this->tagsPage = $tagsPage;
$this->sharedByLinkPage = $sharedByLinkPage;
$this->sharedWithOthersPage = $sharedWithOthersPage;
$this->generalExceptionPage = $generalExceptionPage;
}

/**
Expand Down Expand Up @@ -1235,23 +1245,25 @@ public function theUserMarksAllFilesForBatchActionUsingTheWebUI() {
}

/**
* @When /^the user opens (trashbin|)\s?(file|folder) ((?:'[^']*')|(?:"[^"]*")) using the webUI$/
* @Given /^the user has opened (trashbin|)\s?(file|folder) ((?:'[^']*')|(?:"[^"]*")) using the webUI$/
* @When /^the user opens (trashbin|)\s?(file|folder) ((?:'[^']*')|(?:"[^"]*")) (expecting to fail|)\s?using the webUI$/
* @Given /^the user has opened (trashbin|)\s?(file|folder) ((?:'[^']*')|(?:"[^"]*")) (expecting to fail|)\s?using the webUI$/
*
* @param string $typeOfFilesPage
* @param string $fileOrFolder
* @param string $name enclosed in single or double quotes
* @param string $expectToFail
*
* @return void
* @throws \Exception
*/
public function theUserOpensFolderNamedUsingTheWebUI(
$typeOfFilesPage, $fileOrFolder, $name
$typeOfFilesPage, $fileOrFolder, $name, $expectToFail
) {
$expectToFail = $expectToFail !== "";
// The capturing groups of the regex include the quotes at each
// end of the captured string, so trim them.
$this->theUserOpensTheFileOrFolderUsingTheWebUI(
$typeOfFilesPage, $fileOrFolder, \trim($name, $name[0])
$typeOfFilesPage, $fileOrFolder, \trim($name, $name[0]), $expectToFail
);
}

Expand All @@ -1265,12 +1277,13 @@ public function theUserOpensFolderNamedUsingTheWebUI(
* @param string|array $relativePath the path from the currently open folder
* down to and including the file or folder
* to open
* @param boolean $expectToFail
*
* @return void
* @throws \Exception
*/
public function theUserOpensTheFileOrFolderUsingTheWebUI(
$typeOfFilesPage, $fileOrFolder, $relativePath
$typeOfFilesPage, $fileOrFolder, $relativePath, $expectToFail = false
) {
if ($typeOfFilesPage === "trashbin") {
$this->theUserBrowsesToTheTrashbinPage();
Expand All @@ -1293,19 +1306,37 @@ public function theUserOpensTheFileOrFolderUsingTheWebUI(
$breadCrumbs = \explode('/', \ltrim($relativePath, '/'));
$breadCrumbsForOpenFile = $breadCrumbs;
}

$failed = false;
foreach ($breadCrumbsForOpenFile as $breadCrumb) {
$pageObject->openFile($breadCrumb, $this->getSession());
$pageObject->waitTillPageIsLoaded($this->getSession());
}

if ($fileOrFolder !== "folder") {
// Pop the file name off the end of the array of breadcrumbs
\array_pop($breadCrumbs);
try {
$pageObject->waitTillPageIsLoaded($this->getSession());
} catch (\Exception $e) {
// The file was not opened correctly as the page didn't load correctly
$failed = true;
break;
}
}
// Check the status of file opened according to the expected result.
if ($failed) {
// The task was not expected to fail but failed.
if (!$expectToFail) {
throw new \Exception('The file was expected to open successfully but failed!');
}
} else {
// The task was expected to fail but didn't fail.
if ($expectToFail) {
throw new \Exception('The file was not expected to open successfully but was opened!');
}

if (\count($breadCrumbs)) {
$this->currentFolder .= "/" . \implode('/', $breadCrumbs);
// The task was not expected to fail and was successful.
if ($fileOrFolder !== "folder") {
// Pop the file name off the end of the array of breadcrumbs
\array_pop($breadCrumbs);
}
if (\count($breadCrumbs)) {
$this->currentFolder .= "/" . \implode('/', $breadCrumbs);
};
}
}

Expand Down