From 09aa11280bef12c87e17b92c5dda7f344250c6b9 Mon Sep 17 00:00:00 2001 From: Dipak Acharya Date: Mon, 20 May 2019 15:09:03 +0545 Subject: [PATCH] Fix openFile method to handle error in acceptance tests --- .../features/bootstrap/WebUIFilesContext.php | 61 ++++++++++++++----- 1 file changed, 46 insertions(+), 15 deletions(-) diff --git a/tests/acceptance/features/bootstrap/WebUIFilesContext.php b/tests/acceptance/features/bootstrap/WebUIFilesContext.php index 76ce913f754c..e44025175e04 100644 --- a/tests/acceptance/features/bootstrap/WebUIFilesContext.php +++ b/tests/acceptance/features/bootstrap/WebUIFilesContext.php @@ -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; @@ -144,6 +145,12 @@ class WebUIFilesContext extends RawMinkContext implements Context { private $uploadConflictDialogTitle = "file conflict"; + /** + * + * @var GeneralExceptionPage + */ + private $generalExceptionPage; + /** * WebUIFilesContext constructor. * @@ -155,6 +162,7 @@ class WebUIFilesContext extends RawMinkContext implements Context { * @param TagsPage $tagsPage * @param SharedByLinkPage $sharedByLinkPage * @param SharedWithOthersPage $sharedWithOthersPage + * @param GeneralExceptionPage $generalExceptionPage * * @return void */ @@ -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; @@ -176,6 +185,7 @@ public function __construct( $this->tagsPage = $tagsPage; $this->sharedByLinkPage = $sharedByLinkPage; $this->sharedWithOthersPage = $sharedWithOthersPage; + $this->generalExceptionPage = $generalExceptionPage; } /** @@ -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 ); } @@ -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(); @@ -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); + }; } }