Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

UI test for creating a folder with existing name #29991

Merged
merged 1 commit into from
Dec 29, 2017
Merged
Show file tree
Hide file tree
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
33 changes: 30 additions & 3 deletions tests/ui/features/bootstrap/FilesContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
}

/**
Expand Down Expand Up @@ -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
Expand Down
12 changes: 10 additions & 2 deletions tests/ui/features/files/createFolders.feature
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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

18 changes: 18 additions & 0 deletions tests/ui/features/lib/FilesPage.php
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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
Expand Down