From bc6048a872766285a38b84ad3cf17f1cc5b06205 Mon Sep 17 00:00:00 2001 From: Moheet Shrestha Date: Wed, 27 Dec 2017 16:56:10 +0545 Subject: [PATCH] test for creating a folder with existing name --- tests/ui/features/bootstrap/FilesContext.php | 33 +++++++++++++++++-- tests/ui/features/files/createFolders.feature | 12 +++++-- tests/ui/features/lib/FilesPage.php | 18 ++++++++++ 3 files changed, 58 insertions(+), 5 deletions(-) diff --git a/tests/ui/features/bootstrap/FilesContext.php b/tests/ui/features/bootstrap/FilesContext.php index b2a86971a320..f743ff0395b7 100644 --- a/tests/ui/features/bootstrap/FilesContext.php +++ b/tests/ui/features/bootstrap/FilesContext.php @@ -158,15 +158,32 @@ public function theFilesPageIsReloaded() { } /** - * @When /^I create a folder with the name ((?:'[^']*')|(?:"[^"]*"))$/ + * @When /^I create a folder with the (invalid|)\s?name ((?:'[^']*')|(?:"[^"]*"))$/ * + * @param string $invalid contains "invalid" + * if the folder creation is expected to fail * @param string $name enclosed in single or double quotes * @return void */ - public function iCreateAFolder($name) { + public function iCreateAFolder($invalid, $name) { // The capturing group of the regex always includes the quotes at each // end of the captured string, so trim them. - $this->createAFolder(trim($name, $name[0])); + $name = trim($name, $name[0]); + try { + $this->createAFolder($name); + if ($invalid === "invalid") { + throw new Exception( + "folder '$name' should not have been created but was" + ); + } + } catch (Exception $e) { + //do not throw the exception if we expect the folder creation to fail + if ($invalid !== "invalid" + || $e->getMessage() !== "could not create folder" + ) { + throw $e; + } + } } /** @@ -762,6 +779,16 @@ public function nearTheFileATooltipWithTheTextShouldBeDisplayed( ); } + /** + * @Then near the folder input field a tooltip with the text :tooltiptext should be displayed + * @param string $tooltiptext + * @return void + */ + public function folderInputFieldTooltipTextShouldBe($tooltiptext) { + $createFolderTooltip = $this->filesPage->getCreateFolderTooltip(); + PHPUnit_Framework_Assert::assertSame($tooltiptext, $createFolderTooltip); + } + /** * @Then it should not be possible to delete the file/folder :name * @param string $name diff --git a/tests/ui/features/files/createFolders.feature b/tests/ui/features/files/createFolders.feature index a5301adccc51..b0e9ebcb5ccd 100644 --- a/tests/ui/features/files/createFolders.feature +++ b/tests/ui/features/files/createFolders.feature @@ -5,8 +5,11 @@ I want to create folders So that I can organise my data structure Background: - Given a regular user exists - And I am logged in as a regular user + Given these users exist: + |username|password|displayname|email | + |user1 |1234 |User One |u1@oc.com.np| + And I am on the login page + And I login with username "user1" and password "1234" And I am on the files page Scenario: Create a folder inside another folder @@ -17,3 +20,8 @@ So that I can organise my data structure Then the folder "sub-folder" should be listed And the files page is reloaded Then the folder "sub-folder" should be listed + + Scenario: Create a folder with existing name + When I create a folder with the invalid name "simple-folder" + Then near the folder input field a tooltip with the text 'simple-folder already exists' should be displayed + \ No newline at end of file diff --git a/tests/ui/features/lib/FilesPage.php b/tests/ui/features/lib/FilesPage.php index db7b56515318..05e2105e355e 100644 --- a/tests/ui/features/lib/FilesPage.php +++ b/tests/ui/features/lib/FilesPage.php @@ -43,6 +43,7 @@ class FilesPage extends FilesPageBasic { protected $newFileFolderButtonXpath = './/*[@id="controls"]//a[@class="button new"]'; protected $newFolderButtonXpath = './/div[contains(@class, "newFileMenu")]//a[@data-templatename="New folder"]'; protected $newFolderNameInputLabel = 'New folder'; + protected $newFolderTooltipXpath = './/div[contains(@class, "newFileMenu")]//div[@class="tooltip-inner"]'; protected $fileUploadInputId = "file_upload_start"; protected $uploadProgressbarLabelXpath = "//div[@id='uploadprogressbar']/em"; private $strForNormalFileName = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890'; @@ -166,6 +167,23 @@ public function createFolder( return $name; } + /** + * + * @throws ElementNotFoundException + * @return string + */ + public function getCreateFolderTooltip() { + $newFolderTooltip = $this->find("xpath", $this->newFolderTooltipXpath); + if (is_null($newFolderTooltip)) { + throw new ElementNotFoundException( + __METHOD__ . + " xpath $this->newFolderTooltipXpath " . + "could not find tooltip" + ); + } + return $newFolderTooltip->getText(); + } + /** * * @param Session $session