diff --git a/admin/tests/behat/upload_users.feature b/admin/tests/behat/upload_users.feature index ae9d83beed0..16aef6dc396 100644 --- a/admin/tests/behat/upload_users.feature +++ b/admin/tests/behat/upload_users.feature @@ -19,7 +19,7 @@ Feature: Upload users And I expand "Users" node And I expand "Accounts" node And I follow "Upload users" - When I upload "lib/tests/fixtures/upload_users.csv" file to "File" filepicker + When I upload "lib/tests/fixtures/upload_users.csv" file to "File" filemanager And I press "Upload users" Then I should see "Upload users preview" And I should see "Tom" diff --git a/admin/tool/uploadcourse/tests/behat/create.feature b/admin/tool/uploadcourse/tests/behat/create.feature index ee95ca1f525..ce2c98b8dfa 100644 --- a/admin/tool/uploadcourse/tests/behat/create.feature +++ b/admin/tool/uploadcourse/tests/behat/create.feature @@ -15,7 +15,7 @@ Feature: An admin can create courses using a CSV file @javascript Scenario: Creation of unexisting courses - Given I upload "admin/tool/uploadcourse/tests/fixtures/courses.csv" file to "File" filepicker + Given I upload "admin/tool/uploadcourse/tests/fixtures/courses.csv" file to "File" filemanager And I click on "Preview" "button" When I click on "Upload courses" "button" Then I should see "The course exists and update is not allowed" @@ -29,7 +29,7 @@ Feature: An admin can create courses using a CSV file @javascript Scenario: Creation of existing courses - Given I upload "admin/tool/uploadcourse/tests/fixtures/courses.csv" file to "File" filepicker + Given I upload "admin/tool/uploadcourse/tests/fixtures/courses.csv" file to "File" filemanager And I select "Create all, increment shortname if needed" from "Upload mode" And I click on "Preview" "button" When I click on "Upload courses" "button" diff --git a/admin/tool/uploadcourse/tests/behat/update.feature b/admin/tool/uploadcourse/tests/behat/update.feature index 3a06d163c2e..457f07d2007 100644 --- a/admin/tool/uploadcourse/tests/behat/update.feature +++ b/admin/tool/uploadcourse/tests/behat/update.feature @@ -15,7 +15,7 @@ Feature: An admin can update courses using a CSV file @javascript Scenario: Updating a course fullname - Given I upload "admin/tool/uploadcourse/tests/fixtures/courses.csv" file to "File" filepicker + Given I upload "admin/tool/uploadcourse/tests/fixtures/courses.csv" file to "File" filemanager And I select "Only update existing courses" from "Upload mode" And I select "Update with CSV data only" from "Update mode" And I click on "Preview" "button" diff --git a/badges/tests/behat/add_badge.feature b/badges/tests/behat/add_badge.feature index 9d4b5faf244..64bf70431a2 100644 --- a/badges/tests/behat/add_badge.feature +++ b/badges/tests/behat/add_badge.feature @@ -36,7 +36,7 @@ Feature: Add badges to the system | Description | Test badge description | | issuername | Test Badge Site | | issuercontact | testuser@test-badge-site.com | - And I upload "badges/tests/behat/badge.png" file to "Image" filepicker + And I upload "badges/tests/behat/badge.png" file to "Image" filemanager When I press "Create badge" Then I should see "Edit details" And I should see "Test Badge" diff --git a/badges/tests/behat/award_badge.feature b/badges/tests/behat/award_badge.feature index d34d36e5201..c738acf92b8 100644 --- a/badges/tests/behat/award_badge.feature +++ b/badges/tests/behat/award_badge.feature @@ -18,7 +18,7 @@ Feature: Award badges | Description | Test badge description | | issuername | Test Badge Site | | issuercontact | testuser@test-badge-site.com | - And I upload "badges/tests/behat/badge.png" file to "Image" filepicker + And I upload "badges/tests/behat/badge.png" file to "Image" filemanager And I press "Create badge" And I select "Profile completion" from "type" And I check "First name" @@ -53,7 +53,7 @@ Feature: Award badges | Name | Site Badge | | Description | Site badge description | | issuername | Tester of site badge | - And I upload "badges/tests/behat/badge.png" file to "Image" filepicker + And I upload "badges/tests/behat/badge.png" file to "Image" filemanager And I press "Create badge" And I select "Manual issue by role" from "type" And I check "Teacher" @@ -98,7 +98,7 @@ Feature: Award badges | Name | Course Badge | | Description | Course badge description | | issuername | Tester of course badge | - And I upload "badges/tests/behat/badge.png" file to "Image" filepicker + And I upload "badges/tests/behat/badge.png" file to "Image" filemanager And I press "Create badge" And I select "Manual issue by role" from "type" And I check "Teacher" @@ -156,7 +156,7 @@ Feature: Award badges | Name | Course Badge | | Description | Course badge description | | issuername | Tester of course badge | - And I upload "badges/tests/behat/badge.png" file to "Image" filepicker + And I upload "badges/tests/behat/badge.png" file to "Image" filemanager And I press "Create badge" And I select "Activity completion" from "type" And I check "Test assignment name" @@ -219,7 +219,7 @@ Feature: Award badges | Name | Course Badge | | Description | Course badge description | | issuername | Tester of course badge | - And I upload "badges/tests/behat/badge.png" file to "Image" filepicker + And I upload "badges/tests/behat/badge.png" file to "Image" filemanager And I press "Create badge" And I select "Course completion" from "type" And I fill the moodle form with: diff --git a/cohort/tests/behat/upload_cohort_users.feature b/cohort/tests/behat/upload_cohort_users.feature index 5e6a5ad7ab8..eb0ea178c60 100644 --- a/cohort/tests/behat/upload_cohort_users.feature +++ b/cohort/tests/behat/upload_cohort_users.feature @@ -27,7 +27,7 @@ Feature: Upload users to a cohort And I expand "Users" node And I expand "Accounts" node When I follow "Upload users" - And I upload "lib/tests/fixtures/upload_users_cohorts.csv" file to "File" filepicker + And I upload "lib/tests/fixtures/upload_users_cohorts.csv" file to "File" filemanager And I press "Upload users" And I press "Upload users" And I press "Continue" diff --git a/group/tests/behat/groups_import.feature b/group/tests/behat/groups_import.feature index 57aca33119d..83322aa558d 100644 --- a/group/tests/behat/groups_import.feature +++ b/group/tests/behat/groups_import.feature @@ -22,7 +22,7 @@ Feature: Importing of groups and groupings And I expand "Users" node And I follow "Groups" And I press "Import groups" - When I upload "group/tests/fixtures/groups_import.csv" file to "Import" filepicker + When I upload "group/tests/fixtures/groups_import.csv" file to "Import" filemanager And I press "Import groups" And I press "Continue" Then I should see "group-id-1" @@ -47,7 +47,7 @@ Feature: Importing of groups and groupings And I expand "Users" node And I follow "Groups" And I press "Import groups" - When I upload "group/tests/fixtures/groups_import.csv" file to "Import" filepicker + When I upload "group/tests/fixtures/groups_import.csv" file to "Import" filemanager And I press "Import groups" Then I should see "Group group-id-1 added successfully" And I should see "Group group-id-2 added successfully" @@ -91,7 +91,7 @@ Feature: Importing of groups and groupings And I expand "Users" node And I follow "Groups" And I press "Import groups" - When I upload "group/tests/fixtures/groups_import.csv" file to "Import" filepicker + When I upload "group/tests/fixtures/groups_import.csv" file to "Import" filemanager And I press "Import groups" And I press "Continue" Then I select "group-id-1" from "groups" diff --git a/lib/behat/behat_base.php b/lib/behat/behat_base.php index 6278ff7389d..241a773d236 100644 --- a/lib/behat/behat_base.php +++ b/lib/behat/behat_base.php @@ -29,7 +29,8 @@ // NOTE: no MOODLE_INTERNAL test here, this file may be required by behat before including /config.php. use Behat\Mink\Exception\ExpectationException as ExpectationException, - Behat\Mink\Exception\ElementNotFoundException as ElementNotFoundException; + Behat\Mink\Exception\ElementNotFoundException as ElementNotFoundException, + Behat\Mink\Element\NodeElement as NodeElement; /** * Steps definitions base class. @@ -39,6 +40,11 @@ use Behat\Mink\Exception\ExpectationException as ExpectationException, * It can not contain steps definitions to avoid duplicates, only utility * methods shared between steps. * + * @method NodeElement find_field(string $locator) Finds a form element + * @method NodeElement find_button(string $locator) Finds a form input submit element or a button + * @method NodeElement find_link(string $locator) Finds a link on a page + * @method NodeElement find_file(string $locator) Finds a forum input file element + * * @package core * @category test * @copyright 2012 David Monllaó diff --git a/lib/behat/behat_files.php b/lib/behat/behat_files.php index 3ee17b6d206..06358f3f9ea 100644 --- a/lib/behat/behat_files.php +++ b/lib/behat/behat_files.php @@ -32,7 +32,7 @@ require_once(__DIR__ . '/behat_base.php'); use Behat\Mink\Exception\ExpectationException as ExpectationException, - Behat\Mink\Exception\ElementNotFoundException as ElementNotFoundException; + Behat\Mink\Element\NodeElement as NodeElement; /** * Files-related actions. @@ -49,9 +49,9 @@ use Behat\Mink\Exception\ExpectationException as ExpectationException, class behat_files extends behat_base { /** - * Gets the filepicker NodeElement. + * Gets the NodeElement for filepicker of filemanager moodleform element. * - * The filepicker field label is pointing to a hidden input which is + * The filepicker/filemanager element label is pointing to a hidden input which is * not recognized as a named selector, as it is hidden... * * @throws ExpectationException Thrown by behat_base::find @@ -77,7 +77,7 @@ class behat_files extends behat_base { } /** - * Performs $action on a filepicker container element (file or folder). + * Performs $action on a filemanager container element (file or folder). * * It works together with open_element_contextual_menu * as this method needs the contextual menu to be opened. @@ -99,22 +99,25 @@ class behat_files extends behat_base { /** * Opens the contextual menu of a folder or a file. * - * Works both in filepicker elements and when dealing with repository - * elements inside modal windows. + * Works both in filemanager elements and when dealing with repository + * elements inside filepicker modal window. * * @throws ExpectationException Thrown by behat_base::find * @param string $name The name of the folder/file - * @param string $filepickerelement The filepicker locator, the whole DOM if false + * @param string $filemanagerelement The filemanager form element locator, the repository items are in filepicker modal window if false * @return void */ - protected function open_element_contextual_menu($name, $filepickerelement = false) { + protected function open_element_contextual_menu($name, $filemanagerelement = false) { - // If a filepicker is specified we restrict the search to the filepicker descendants. + // If a filemanager is specified we restrict the search to the descendants of this particular filemanager form element. $containernode = false; $exceptionmsg = '"'.$name.'" element can not be found'; - if ($filepickerelement) { - $containernode = $this->get_filepicker_node($filepickerelement); - $exceptionmsg = 'The "'.$filepickerelement.'" filepicker ' . $exceptionmsg; + if ($filemanagerelement) { + $containernode = $this->get_filepicker_node($filemanagerelement); + $exceptionmsg = 'The "'.$filemanagerelement.'" filemanager ' . $exceptionmsg; + $locatorprefix = "//div[@class='fp-content']"; + } else { + $locatorprefix = "//div[contains(concat(' ', normalize-space(@class), ' '), ' fp-repo-items ')]//descendant::div[@class='fp-content']"; } $exception = new ExpectationException($exceptionmsg, $this->getSession()); @@ -122,13 +125,13 @@ class behat_files extends behat_base { // Avoid quote-related problems. $name = $this->getSession()->getSelectorsHandler()->xpathLiteral($name); - // Get a filepicker element (folder or file). + // Get a filepicker/filemanager element (folder or file). try { // First we look at the folder as we need to click on the contextual menu otherwise it would be opened. $node = $this->find( 'xpath', - "//div[@class='fp-content']" . + $locatorprefix . "//descendant::*[self::div | self::a][contains(concat(' ', normalize-space(@class), ' '), ' fp-file ')]" . "[contains(concat(' ', normalize-space(@class), ' '), ' fp-folder ')]" . "[normalize-space(.)=$name]" . @@ -142,7 +145,7 @@ class behat_files extends behat_base { // Here the contextual menu is hidden, we click on the thumbnail. $node = $this->find( 'xpath', - "//div[@class='fp-content']" . + $locatorprefix . "//descendant::*[self::div | self::a][contains(concat(' ', normalize-space(@class), ' '), ' fp-file ')]" . "[normalize-space(.)=$name]" . "//descendant::div[contains(concat(' ', normalize-space(@class), ' '), ' fp-thumbnail ')]", @@ -156,25 +159,25 @@ class behat_files extends behat_base { } /** - * Opens the 'add file' modal window and selects the repository. + * Opens the filepicker modal window and selects the repository. * * @throws ExpectationException Thrown by behat_base::find - * @param NodeElement $filepickernode The filepicker DOM node. + * @param NodeElement $filemanagernode The filemanager or filepicker form element DOM node. * @param mixed $repositoryname The repo name. * @return void */ - protected function open_add_file_window($filepickernode, $repositoryname) { + protected function open_add_file_window($filemanagernode, $repositoryname) { - $exception = new ExpectationException('No files can be added to the specified filepicker', $this->getSession()); + $exception = new ExpectationException('No files can be added to the specified filemanager', $this->getSession()); - // We should deal with single-file and multiple-file filepickers, + // We should deal with single-file and multiple-file filemanagers, // catching the exception thrown by behat_base::find() in case is not multiple try { - // Looking for the add button inside the specified filepicker. - $add = $this->find('css', 'div.fp-btn-add a', $exception, $filepickernode); + // Looking for the add button inside the specified filemanager. + $add = $this->find('css', 'div.fp-btn-add a', $exception, $filemanagernode); } catch (Exception $e) { - // Otherwise should be a single-file filepicker. - $add = $this->find('css', 'input.fp-btn-choose', $exception, $filepickernode); + // Otherwise should be a single-file filepicker form element. + $add = $this->find('css', 'input.fp-btn-choose', $exception, $filemanagernode); } $add->click(); @@ -184,7 +187,7 @@ class behat_files extends behat_base { // Avoid problems with both double and single quotes in the same string. $repositoryname = $this->getSession()->getSelectorsHandler()->xpathLiteral($repositoryname); - // Here we don't need to look inside the selected filepicker because there can only be one modal window. + // Here we don't need to look inside the selected element because there can only be one modal window. $repositorylink = $this->find( 'xpath', "//div[contains(concat(' ', normalize-space(@class), ' '), ' fp-repo-area ')]" . diff --git a/lib/tests/behat/behat_deprecated.php b/lib/tests/behat/behat_deprecated.php index 25c8bb442f0..5532c815cb2 100644 --- a/lib/tests/behat/behat_deprecated.php +++ b/lib/tests/behat/behat_deprecated.php @@ -27,7 +27,8 @@ require_once(__DIR__ . '/../../../lib/behat/behat_base.php'); -use Behat\Mink\Exception\ElementNotFoundException as ElementNotFoundException; +use Behat\Mink\Exception\ElementNotFoundException as ElementNotFoundException, + Behat\Behat\Context\Step\Given as Given; /** * Deprecated behat step definitions. @@ -94,6 +95,143 @@ class behat_deprecated extends behat_base { ); } + /** + * Adds the specified file from the 'Recent files' repository to the specified filepicker of the current page. + * + * @deprecated since 2.7 + * @todo MDL-42862 This will be deleted in Moodle 2.9 + * @see behat_filepicker::i_add_file_from_repository_to_filemanager() + * + * @When /^I add "(?P(?:[^"]|\\")*)" file from recent files to "(?P(?:[^"]|\\")*)" filepicker$/ + * @param string $filename + * @param string $filepickerelement + */ + public function i_add_file_from_recent_files_to_filepicker($filename, $filepickerelement) { + $reponame = get_string('pluginname', 'repository_recent'); + $alternative = 'I add "' . $this->escape($filename) . '" file from "' . + $reponame . '" to "' . $this->escape($filepickerelement) . '" filemanager'; + $this->deprecated_message($alternative); + return array( + new Given($alternative) + ); + } + + /** + * Uploads a file to the specified filemanager leaving other fields in upload form default. The paths should be relative to moodle codebase. + * + * @deprecated since 2.7 + * @todo MDL-42862 This will be deleted in Moodle 2.9 + * @see behat_repository_upload::i_upload_file_to_filemanager() + * + * @When /^I upload "(?P(?:[^"]|\\")*)" file to "(?P(?:[^"]|\\")*)" filepicker$/ + * @throws ExpectationException Thrown by behat_base::find + * @param string $filepath + * @param string $filepickerelement + */ + public function i_upload_file_to_filepicker($filepath, $filepickerelement) { + $alternative = 'I upload "' . $this->escape($filepath) . '" file to "' . + $this->escape($filepickerelement) . '" filemanager'; + $this->deprecated_message($alternative); + return array( + new Given($alternative) + ); + } + + /** + * Creates a folder with specified name in the current folder and in the specified filepicker field. + * + * @deprecated since 2.7 + * @todo MDL-42862 This will be deleted in Moodle 2.9 + * @see behat_filepicker::i_create_folder_in_filemanager() + * + * @Given /^I create "(?P(?:[^"]|\\")*)" folder in "(?P(?:[^"]|\\")*)" filepicker$/ + * @throws ExpectationException Thrown by behat_base::find + * @param string $foldername + * @param string $filepickerelement + */ + public function i_create_folder_in_filepicker($foldername, $filepickerelement) { + $alternative = 'I create "' . $this->escape($foldername) . + '" folder in "' . $this->escape($filepickerelement) . '" filemanager'; + $this->deprecated_message($alternative); + return array(new Given($alternative)); + } + + /** + * Opens the contents of a filepicker folder. It looks for the folder in the current folder and in the path bar. + * + * @deprecated since 2.7 + * @todo MDL-42862 This will be deleted in Moodle 2.9 + * @see behat_filepicker::i_open_folder_from_filemanager() + * + * @Given /^I open "(?P(?:[^"]|\\")*)" folder from "(?P(?:[^"]|\\")*)" filepicker$/ + * @throws ExpectationException Thrown by behat_base::find + * @param string $foldername + * @param string $filepickerelement + */ + public function i_open_folder_from_filepicker($foldername, $filepickerelement) { + $alternative = 'I open "' . $this->escape($foldername) . '" folder from "' . + $this->escape($filepickerelement) . '" filemanager'; + $this->deprecated_message($alternative); + return array(new Given($alternative)); + } + + /** + * Unzips the specified file from the specified filepicker field. The zip file has to be visible in the current folder. + * + * @deprecated since 2.7 + * @todo MDL-42862 This will be deleted in Moodle 2.9 + * @see behat_filepicker::i_unzip_file_from_filemanager() + * + * @Given /^I unzip "(?P(?:[^"]|\\")*)" file from "(?P(?:[^"]|\\")*)" filepicker$/ + * @throws ExpectationException Thrown by behat_base::find + * @param string $filename + * @param string $filepickerelement + */ + public function i_unzip_file_from_filepicker($filename, $filepickerelement) { + $alternative = 'I unzip "' . $this->escape($filename) . '" file from "' . + $this->escape($filepickerelement) . '" filemanager'; + $this->deprecated_message($alternative); + return array(new Given($alternative)); + } + + /** + * Zips the specified folder from the specified filepicker field. The folder has to be in the current folder. + * + * @deprecated since 2.7 + * @todo MDL-42862 This will be deleted in Moodle 2.9 + * @see behat_filepicker::i_zip_folder_from_filemanager() + * + * @Given /^I zip "(?P(?:[^"]|\\")*)" folder from "(?P(?:[^"]|\\")*)" filepicker$/ + * @throws ExpectationException Thrown by behat_base::find + * @param string $foldername + * @param string $filepickerelement + */ + public function i_zip_folder_from_filepicker($foldername, $filepickerelement) { + $alternative = 'I zip "' . $this->escape($foldername) . '" folder from "' . + $this->escape($filepickerelement) . '" filemanager'; + $this->deprecated_message($alternative); + return array(new Given($alternative)); + } + + /** + * Deletes the specified file or folder from the specified filepicker field. + * + * @deprecated since 2.7 + * @todo MDL-42862 This will be deleted in Moodle 2.9 + * @see behat_filepicker::i_delete_file_from_filemanager() + * + * @Given /^I delete "(?P(?:[^"]|\\")*)" from "(?P(?:[^"]|\\")*)" filepicker$/ + * @throws ExpectationException Thrown by behat_base::find + * @param string $name + * @param string $filepickerelement + */ + public function i_delete_file_from_filepicker($name, $filepickerelement) { + $alternative = 'I delete "' . $this->escape($name) . '" from "' . + $this->escape($filepickerelement) . '" filemanager'; + $this->deprecated_message($alternative); + return array(new Given($alternative)); + } + /** * Throws an exception if $CFG->behat_usedeprecated is not allowed. * diff --git a/mod/assign/tests/behat/file_submission.feature b/mod/assign/tests/behat/file_submission.feature index 7bc5380e88b..4e33ee93589 100644 --- a/mod/assign/tests/behat/file_submission.feature +++ b/mod/assign/tests/behat/file_submission.feature @@ -31,13 +31,13 @@ Feature: In an assignment, students can upload files for assessment And I follow "Course 1" And I follow "Test assignment name" When I press "Add submission" - And I upload "lib/tests/fixtures/empty.txt" file to "File submissions" filepicker + And I upload "lib/tests/fixtures/empty.txt" file to "File submissions" filemanager And I press "Save changes" Then I should see "Submitted for grading" And I should see "empty.txt" And I should see "Not graded" And I press "Edit submission" - And I upload "lib/tests/fixtures/upload_users.csv" file to "File submissions" filepicker + And I upload "lib/tests/fixtures/upload_users.csv" file to "File submissions" filemanager And ".ffilemanager .fm-maxfiles .fp-btn-add" "css_element" should exists And I press "Save changes" And I should see "Submitted for grading" diff --git a/mod/scorm/tests/behat/add_scorm.feature b/mod/scorm/tests/behat/add_scorm.feature index 8aa26a9565f..feb613df53c 100644 --- a/mod/scorm/tests/behat/add_scorm.feature +++ b/mod/scorm/tests/behat/add_scorm.feature @@ -21,7 +21,7 @@ Feature: Add scorm activity And I follow "Course 1" And I turn editing mode on And I add a "SCORM package" to section "1" - And I upload "mod/scorm/tests/packages/singlescobasic.zip" file to "Package file" filepicker + And I upload "mod/scorm/tests/packages/singlescobasic.zip" file to "Package file" filemanager And I fill the moodle form with: | Name | Awesome SCORM package | | Description | Description | diff --git a/repository/recent/tests/behat/add_recent.feature b/repository/recent/tests/behat/add_recent.feature index 25048265b5d..0e245d03d3e 100644 --- a/repository/recent/tests/behat/add_recent.feature +++ b/repository/recent/tests/behat/add_recent.feature @@ -12,8 +12,8 @@ Feature: Recent files repository lists the recently used files And I log in as "admin" And I expand "My profile" node And I follow "My private files" - And I upload "lib/tests/fixtures/empty.txt" file to "Files" filepicker - And I upload "lib/tests/fixtures/upload_users.csv" file to "Files" filepicker + And I upload "lib/tests/fixtures/empty.txt" file to "Files" filemanager + And I upload "lib/tests/fixtures/upload_users.csv" file to "Files" filemanager And I press "Save changes" And I am on homepage And I follow "Course 1" @@ -22,7 +22,10 @@ Feature: Recent files repository lists the recently used files And I fill the moodle form with: | Name | Folder name | | Description | Folder description | - And I add "empty.txt" file from recent files to "Files" filepicker + And I add "empty.txt" file from "Recent files" to "Files" filemanager + And I add "empty.txt" file from "Recent files" to "Files" filemanager as: + | Save as | empty_copy.txt | And I press "Save and display" Then I should see "empty.txt" + And I should see "empty_copy.txt" And I should see "Folder description" diff --git a/repository/recent/tests/behat/behat_repository_recent.php b/repository/recent/tests/behat/behat_repository_recent.php deleted file mode 100644 index 27dcaf53f75..00000000000 --- a/repository/recent/tests/behat/behat_repository_recent.php +++ /dev/null @@ -1,68 +0,0 @@ -. - -/** - * Steps definitions for recent files repository type. - * - * @package repository_recent - * @category test - * @copyright 2013 David Monllaó - * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later - */ - -// NOTE: no MOODLE_INTERNAL test here, this file may be required by behat before including /config.php. - -require_once(__DIR__ . '/../../../../lib/behat/behat_files.php'); - -/** - * Steps definitions to deal with recent files and the filepicker. - * - * Extends behat_files rather than behat_base as is file-related. - * - * @package repository_recent - * @category test - * @copyright 2013 David Monllaó - * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later - */ -class behat_repository_recent extends behat_files { - - /** - * Adds the specified file from the 'Recent files' repository to the specified filepicker of the current page. - * - * @When /^I add "(?P(?:[^"]|\\")*)" file from recent files to "(?P(?:[^"]|\\")*)" filepicker$/ - * @param string $filename - * @param string $filepickerelement - */ - public function i_add_file_from_recent_files_to_filepicker($filename, $filepickerelement) { - - $filepickernode = $this->get_filepicker_node($filepickerelement); - - // Opening the select repository window and selecting the recent repository. - $this->open_add_file_window($filepickernode, get_string('pluginname', 'repository_recent')); - - // Opening the specified file contextual menu from the modal window. - $this->open_element_contextual_menu($filename); - - $this->find_button(get_string('getfile', 'repository'))->click(); - - // Ensure the file has been selected and we returned to the form page. - $this->wait_until_return_to_form(); - - // Wait until file manager contents are updated. - $this->wait_until_contents_are_updated($filepickernode); - } - -} diff --git a/repository/tests/behat/behat_filepicker.php b/repository/tests/behat/behat_filepicker.php index a077f565a26..4dac65fe829 100644 --- a/repository/tests/behat/behat_filepicker.php +++ b/repository/tests/behat/behat_filepicker.php @@ -15,7 +15,7 @@ // along with Moodle. If not, see . /** - * Files and filepicker manipulation steps definitions. + * Filemanager and filepicker manipulation steps definitions. * * @package core * @category test @@ -27,10 +27,11 @@ require_once(__DIR__ . '/../../../lib/behat/behat_files.php'); -use Behat\Mink\Exception\ExpectationException as ExpectationException; +use Behat\Mink\Exception\ExpectationException as ExpectationException, + Behat\Gherkin\Node\TableNode as TableNode; /** - * Steps definitions to deal with the filepicker. + * Steps definitions to deal with the filemanager and filepicker. * * Extends behat_files rather than behat_base as is file-related. * @@ -42,19 +43,19 @@ use Behat\Mink\Exception\ExpectationException as ExpectationException; class behat_filepicker extends behat_files { /** - * Creates a folder with specified name in the current folder and in the specified filepicker field. + * Creates a folder with specified name in the current folder and in the specified filemanager field. * - * @Given /^I create "(?P(?:[^"]|\\")*)" folder in "(?P(?:[^"]|\\")*)" filepicker$/ + * @Given /^I create "(?P(?:[^"]|\\")*)" folder in "(?P(?:[^"]|\\")*)" filemanager$/ * @throws ExpectationException Thrown by behat_base::find * @param string $foldername - * @param string $filepickerelement + * @param string $filemanagerelement */ - public function i_create_folder_in_filepicker($foldername, $filepickerelement) { + public function i_create_folder_in_filemanager($foldername, $filemanagerelement) { - $fieldnode = $this->get_filepicker_node($filepickerelement); + $fieldnode = $this->get_filepicker_node($filemanagerelement); - // Looking for the create folder button inside the specified filepicker. - $exception = new ExpectationException('No folders can be created in "'.$filepickerelement.'" filepicker', $this->getSession()); + // Looking for the create folder button inside the specified filemanager. + $exception = new ExpectationException('No folders can be created in "'.$filemanagerelement.'" filemanager', $this->getSession()); $newfolder = $this->find('css', 'div.fp-btn-mkdir a', $exception, $fieldnode); $newfolder->click(); @@ -76,19 +77,19 @@ class behat_filepicker extends behat_files { } /** - * Opens the contents of a filepicker folder. It looks for the folder in the current folder and in the path bar. + * Opens the contents of a filemanager folder. It looks for the folder in the current folder and in the path bar. * - * @Given /^I open "(?P(?:[^"]|\\")*)" folder from "(?P(?:[^"]|\\")*)" filepicker$/ + * @Given /^I open "(?P(?:[^"]|\\")*)" folder from "(?P(?:[^"]|\\")*)" filemanager$/ * @throws ExpectationException Thrown by behat_base::find * @param string $foldername - * @param string $filepickerelement + * @param string $filemanagerelement */ - public function i_open_folder_from_filepicker($foldername, $filepickerelement) { + public function i_open_folder_from_filemanager($foldername, $filemanagerelement) { - $fieldnode = $this->get_filepicker_node($filepickerelement); + $fieldnode = $this->get_filepicker_node($filemanagerelement); $exception = new ExpectationException( - 'The "'.$foldername.'" folder can not be found in the "'.$filepickerelement.'" filepicker', + 'The "'.$foldername.'" folder can not be found in the "'.$filemanagerelement.'" filemanager', $this->getSession() ); @@ -129,17 +130,17 @@ class behat_filepicker extends behat_files { } /** - * Unzips the specified file from the specified filepicker field. The zip file has to be visible in the current folder. + * Unzips the specified file from the specified filemanager field. The zip file has to be visible in the current folder. * - * @Given /^I unzip "(?P(?:[^"]|\\")*)" file from "(?P(?:[^"]|\\")*)" filepicker$/ + * @Given /^I unzip "(?P(?:[^"]|\\")*)" file from "(?P(?:[^"]|\\")*)" filemanager$/ * @throws ExpectationException Thrown by behat_base::find * @param string $filename - * @param string $filepickerelement + * @param string $filemanagerelement */ - public function i_unzip_file_from_filepicker($filename, $filepickerelement) { + public function i_unzip_file_from_filemanager($filename, $filemanagerelement) { - // Open the contextual menu of the filepicker element. - $this->open_element_contextual_menu($filename, $filepickerelement); + // Open the contextual menu of the filemanager element. + $this->open_element_contextual_menu($filename, $filemanagerelement); // Execute the action. $exception = new ExpectationException($filename.' element can not be unzipped', $this->getSession()); @@ -149,22 +150,22 @@ class behat_filepicker extends behat_files { $this->wait_until_return_to_form(); // Wait until the current folder contents are updated - $containernode = $this->get_filepicker_node($filepickerelement); + $containernode = $this->get_filepicker_node($filemanagerelement); $this->wait_until_contents_are_updated($containernode); } /** - * Zips the specified folder from the specified filepicker field. The folder has to be in the current folder. + * Zips the specified folder from the specified filemanager field. The folder has to be in the current folder. * - * @Given /^I zip "(?P(?:[^"]|\\")*)" folder from "(?P(?:[^"]|\\")*)" filepicker$/ + * @Given /^I zip "(?P(?:[^"]|\\")*)" folder from "(?P(?:[^"]|\\")*)" filemanager$/ * @throws ExpectationException Thrown by behat_base::find * @param string $foldername - * @param string $filepickerelement + * @param string $filemanagerelement */ - public function i_zip_folder_from_filepicker($foldername, $filepickerelement) { + public function i_zip_folder_from_filemanager($foldername, $filemanagerelement) { - // Open the contextual menu of the filepicker element. - $this->open_element_contextual_menu($foldername, $filepickerelement); + // Open the contextual menu of the filemanager element. + $this->open_element_contextual_menu($foldername, $filemanagerelement); // Execute the action. $exception = new ExpectationException($foldername.' element can not be zipped', $this->getSession()); @@ -174,22 +175,22 @@ class behat_filepicker extends behat_files { $this->wait_until_return_to_form(); // Wait until the current folder contents are updated - $containernode = $this->get_filepicker_node($filepickerelement); + $containernode = $this->get_filepicker_node($filemanagerelement); $this->wait_until_contents_are_updated($containernode); } /** - * Deletes the specified file or folder from the specified filepicker field. + * Deletes the specified file or folder from the specified filemanager field. * - * @Given /^I delete "(?P(?:[^"]|\\")*)" from "(?P(?:[^"]|\\")*)" filepicker$/ + * @Given /^I delete "(?P(?:[^"]|\\")*)" from "(?P(?:[^"]|\\")*)" filemanager$/ * @throws ExpectationException Thrown by behat_base::find - * @param string $foldername - * @param string $filepickerelement + * @param string $name + * @param string $filemanagerelement */ - public function i_delete_file_from_filepicker($name, $filepickerelement) { + public function i_delete_file_from_filemanager($name, $filemanagerelement) { - // Open the contextual menu of the filepicker element. - $this->open_element_contextual_menu($name, $filepickerelement); + // Open the contextual menu of the filemanager element. + $this->open_element_contextual_menu($name, $filemanagerelement); // Execute the action. $exception = new ExpectationException($name.' element can not be deleted', $this->getSession()); @@ -204,8 +205,134 @@ class behat_filepicker extends behat_files { $this->wait_until_return_to_form(); // Wait until file manager contents are updated. - $containernode = $this->get_filepicker_node($filepickerelement); + $containernode = $this->get_filepicker_node($filemanagerelement); $this->wait_until_contents_are_updated($containernode); } + + /** + * Makes sure user can see the exact number of elements (files in folders) in the filemanager. + * + * @Then /^I should see "(?P\d+)" elements in "(?P(?:[^"]|\\")*)" filemanager$/ + * @throws ExpectationException Thrown by behat_base::find + * @param int $elementscount + * @param string $filemanagerelement + */ + public function i_should_see_elements_in_filemanager($elementscount, $filemanagerelement) { + $filemanagernode = $this->get_filepicker_node($filemanagerelement); + $this->wait_until_contents_are_updated($filemanagernode); + $elements = $this->find_all('css', '.fp-content .fp-file', false, $filemanagernode); + if (count($elements) != $elementscount) { + throw new ExpectationException('Found '.count($elements).' elements in filemanager instead of expected '.$elementscount); + } + } + + /** + * Picks the file from repository leaving default values in select file dialogue. + * + * @When /^I add "(?P(?:[^"]|\\")*)" file from "(?P(?:[^"]|\\")*)" to "(?P(?:[^"]|\\")*)" filemanager$/ + * @throws ExpectationException Thrown by behat_base::find + * @param string $filepath + * @parma string $repository + * @param string $filemanagerelement + */ + public function i_add_file_from_repository_to_filemanager($filepath, $repository, $filemanagerelement) { + $this->add_file_from_repository_to_filemanager($filepath, $repository, $filemanagerelement, new TableNode(), false); + } + + /** + * Picks the file from repository leaving default values in select file dialogue and confirming to overwrite an existing file. + * + * @When /^I add and overwrite "(?P(?:[^"]|\\")*)" file from "(?P(?:[^"]|\\")*)" to "(?P(?:[^"]|\\")*)" filemanager$/ + * @throws ExpectationException Thrown by behat_base::find + * @param string $filepath + * @parma string $repository + * @param string $filemanagerelement + */ + public function i_add_and_overwrite_file_from_repository_to_filemanager($filepath, $repository, $filemanagerelement) { + $this->add_file_from_repository_to_filemanager($filepath, $repository, $filemanagerelement, new TableNode(), + get_string('overwrite', 'repository')); + } + + /** + * Picks the file from repository filling the form in Select file dialogue. + * + * @When /^I add "(?P(?:[^"]|\\")*)" file from "(?P(?:[^"]|\\")*)" to "(?P(?:[^"]|\\")*)" filemanager as:$/ + * @throws ExpectationException Thrown by behat_base::find + * @param string $filepath + * @parma string $repository + * @param string $filemanagerelement + * @param TableNode $data Data to fill the form in Select file dialogue + */ + public function i_add_file_from_repository_to_filemanager_as($filepath, $repository, $filemanagerelement, TableNode $data) { + $this->add_file_from_repository_to_filemanager($filepath, $repository, $filemanagerelement, $data, false); + } + + /** + * Picks the file from repository confirming to overwrite an existing file + * + * @When /^I add and overwrite "(?P(?:[^"]|\\")*)" file from "(?P(?:[^"]|\\")*)" to "(?P(?:[^"]|\\")*)" filemanager as:$/ + * @throws ExpectationException Thrown by behat_base::find + * @param string $filepath + * @parma string $repository + * @param string $filemanagerelement + * @param TableNode $data Data to fill the form in Select file dialogue + */ + public function i_add_and_overwrite_file_from_repository_to_filemanager_as($filepath, $repository, $filemanagerelement, TableNode $data) { + $this->add_file_from_repository_to_filemanager($filepath, $repository, $filemanagerelement, $data, + get_string('overwrite', 'repository')); + } + + /** + * Picks the file from private files repository + * + * @throws ExpectationException Thrown by behat_base::find + * @param string $filepath + * @parma string $repository + * @param string $filemanagerelement + * @param TableNode $data Data to fill the form in Select file dialogue + * @param false|string $overwriteaction false if we don't expect that file with the same name already exists, + * or button text in overwrite dialogue ("Overwrite", "Rename to ...", "Cancel") + */ + protected function add_file_from_repository_to_filemanager($filepath, $repository, $filemanagerelement, TableNode $data, + $overwriteaction = false) { + $filemanagernode = $this->get_filepicker_node($filemanagerelement); + + // Wait until file manager is completely loaded. + $this->wait_until_contents_are_updated($filemanagernode); + + // Opening the select repository window and selecting the upload repository. + $this->open_add_file_window($filemanagernode, $repository); + + $this->open_element_contextual_menu($filepath); + + // Fill the form in Select window. + $datahash = $data->getRowsHash(); + + // The action depends on the field type. + foreach ($datahash as $locator => $value) { + // Getting the node element pointed by the label. + $fieldnode = $this->find_field($locator); + + // Gets the field type from a parent node. + $field = behat_field_manager::get_form_field($fieldnode, $this->getSession()); + + // Delegates to the field class. + $field->set_value($value); + } + + $this->find_button(get_string('getfile', 'repository'))->click(); + + if ($overwriteaction !== false) { + $this->getSession()->wait(1 * 1000, false); + $this->find_button($overwriteaction)->click(); + } + + // Ensure the file has been uploaded and all ajax processes finished. + $this->wait_until_return_to_form(); + + // Wait until file manager contents are updated. + $this->wait_until_contents_are_updated($filemanagernode); + } + } diff --git a/repository/tests/behat/cancel_add_file.feature b/repository/tests/behat/cancel_add_file.feature index 32d05c76852..eae9f54559b 100644 --- a/repository/tests/behat/cancel_add_file.feature +++ b/repository/tests/behat/cancel_add_file.feature @@ -12,7 +12,7 @@ Feature: A selected file can be cancelled And I log in as "admin" And I expand "My profile" node And I follow "My private files" - And I upload "lib/tests/fixtures/empty.txt" file to "Files" filepicker + And I upload "lib/tests/fixtures/empty.txt" file to "Files" filemanager And I press "Save changes" And I am on homepage And I follow "Course 1" @@ -21,7 +21,7 @@ Feature: A selected file can be cancelled And I fill the moodle form with: | Name | Folder name | | Description | Folder description | - And I upload "lib/tests/fixtures/upload_users.csv" file to "Files" filepicker + And I upload "lib/tests/fixtures/upload_users.csv" file to "Files" filemanager And I click on "#fitem_id_files .fp-btn-add a" "css_element" And I click on "Recent files" "link" in the ".fp-repo-area" "css_element" And I click on "//a[contains(concat(' ', normalize-space(@class), ' '), ' fp-file ')][normalize-space(.)='empty.txt']" "xpath_element" diff --git a/repository/tests/behat/create_folders.feature b/repository/tests/behat/create_folders.feature index 7492dad227f..a37dcf20e47 100644 --- a/repository/tests/behat/create_folders.feature +++ b/repository/tests/behat/create_folders.feature @@ -16,11 +16,11 @@ Feature: Create folders in the file manager And I fill the moodle form with: | Name | Folder resource | | Description | The description | - And I create "Folder 1" folder in "Files" filepicker - And I open "Folder 1" folder from "Files" filepicker - And I create "SubFolder 1" folder in "Files" filepicker - When I open "Files" folder from "Files" filepicker + And I create "Folder 1" folder in "Files" filemanager + And I open "Folder 1" folder from "Files" filemanager + And I create "SubFolder 1" folder in "Files" filemanager + When I open "Files" folder from "Files" filemanager Then I should see "Folder 1" - And I open "Folder 1" folder from "Files" filepicker + And I open "Folder 1" folder from "Files" filemanager And I should see "SubFolder 1" And I press "Save and return to course" diff --git a/repository/tests/behat/create_shortcut.feature b/repository/tests/behat/create_shortcut.feature new file mode 100644 index 00000000000..74f8211722b --- /dev/null +++ b/repository/tests/behat/create_shortcut.feature @@ -0,0 +1,68 @@ +@core @core_filepicker @repository @repository_user @_only_local +Feature: Create shortcuts + In order to automatically synchronize copies of the file with the source + As a teacher + I need to be able to pick file as a shortcut + + @javascript + Scenario: Upload a file as a copy and as a shortcut in filemanager + Given the following "users" exists: + | username | firstname | lastname | email | + | teacher1 | Terry | Teacher | teacher1@asd.com | + And the following "courses" exists: + | fullname | shortname | category | + | Course 1 | C1 | 0 | + And the following "course enrolments" exists: + | user | course | role | + | teacher1 | C1 | editingteacher | + When I log in as "teacher1" + And I expand "My profile" node + And I follow "My private files" + And I upload "lib/tests/fixtures/empty.txt" file to "Files" filemanager + Then I should see "empty.txt" in the "div.fp-content" "css_element" + And I press "Save changes" + And I am on homepage + And I follow "Course 1" + And I turn editing mode on + And I add a "Folder" to section "1" + And I fill the moodle form with: + | Name | Test folder | + | Description | Test folder description | + And I add "empty.txt" file from "Private files" to "Files" filemanager + And I should see "1" elements in "Files" filemanager + And I should see "empty.txt" in the ".fp-content .fp-file" "css_element" + And ".fp-content .fp-file.fp-isreference" "css_element" should not exists + And I add "empty.txt" file from "Private files" to "Files" filemanager as: + | Save as | empty_ref.txt | + | Create an alias/shortcut to the file | 1 | + And I should see "2" elements in "Files" filemanager + And I should see "empty_ref.txt" in the ".fp-content .fp-file.fp-isreference" "css_element" + And I press "Save and display" + And I should see "empty.txt" + And I should see "empty_ref.txt" + And I press "Edit" + And I should see "2" elements in "Files" filemanager + And I should see "empty_ref.txt" in the ".fp-content .fp-file.fp-isreference" "css_element" + # ------ Overwriting the reference with a non-reference --------- + And I add and overwrite "empty.txt" file from "Private files" to "Files" filemanager as: + | Save as | empty_ref.txt | + And I should see "2" elements in "Files" filemanager + And ".fp-content .fp-file.fp-isreference" "css_element" should not exists + And I press "Save changes" + And I should see "empty.txt" + And I should see "empty_ref.txt" + And I press "Edit" + And I should see "2" elements in "Files" filemanager + And ".fp-content .fp-file.fp-isreference" "css_element" should not exists + # ------ Overwriting non-reference with a reference --------- + And I add and overwrite "empty.txt" file from "Private files" to "Files" filemanager as: + | Save as | empty_ref.txt | + | Create an alias/shortcut to the file | 1 | + And I should see "2" elements in "Files" filemanager + And I should see "empty_ref.txt" in the ".fp-content .fp-file.fp-isreference" "css_element" + And I press "Save changes" + And I should see "empty.txt" + And I should see "empty_ref.txt" + And I press "Edit" + And I should see "2" elements in "Files" filemanager + And I should see "empty_ref.txt" in the ".fp-content .fp-file.fp-isreference" "css_element" diff --git a/repository/tests/behat/delete_files.feature b/repository/tests/behat/delete_files.feature index c6bb5ff5be6..df5dcce1e29 100644 --- a/repository/tests/behat/delete_files.feature +++ b/repository/tests/behat/delete_files.feature @@ -9,13 +9,13 @@ Feature: Delete files and folders from the file manager Given I log in as "admin" And I expand "My profile" node And I follow "My private files" - And I upload "lib/tests/fixtures/empty.txt" file to "Files" filepicker - And I create "Delete me" folder in "Files" filepicker + And I upload "lib/tests/fixtures/empty.txt" file to "Files" filemanager + And I create "Delete me" folder in "Files" filemanager And I press "Save changes" - When I delete "empty.txt" from "Files" filepicker + When I delete "empty.txt" from "Files" filemanager And I press "Save changes" Then I should not see "empty.txt" - And I delete "Delete me" from "Files" filepicker + And I delete "Delete me" from "Files" filemanager And I press "Save changes" And I should not see "Delete me" And I press "Cancel" diff --git a/repository/tests/behat/overwrite_file.feature b/repository/tests/behat/overwrite_file.feature new file mode 100644 index 00000000000..135f47eefb8 --- /dev/null +++ b/repository/tests/behat/overwrite_file.feature @@ -0,0 +1,51 @@ +@core @core_filepicker @_only_local +Feature: Overwrite file feature + In order to update an existing file + As a user + I need to pick the file with the same name and select to overwrite + + @javascript + Scenario: Upload a file in filemanager and overwrite it + Given the following "users" exists: + | username | firstname | lastname | email | + | teacher1 | Terry | Teacher | teacher1@asd.com | + And the following "courses" exists: + | fullname | shortname | category | + | Course 1 | C1 | 0 | + And the following "course enrolments" exists: + | user | course | role | + | teacher1 | C1 | editingteacher | + When I log in as "teacher1" + And I expand "My profile" node + And I follow "My private files" + And I upload "lib/tests/fixtures/empty.txt" file to "Files" filemanager + Then I should see "1" elements in "Files" filemanager + And I upload and overwrite "lib/tests/fixtures/empty.txt" file to "Files" filemanager + And I should see "1" elements in "Files" filemanager + And I upload "lib/tests/fixtures/empty.txt" file to "Files" filemanager as: + | Save as | empty_copy.txt | + And I should see "2" elements in "Files" filemanager + And I upload and overwrite "lib/tests/fixtures/empty.txt" file to "Files" filemanager as: + | Save as | empty_copy.txt | + And I should see "2" elements in "Files" filemanager + And I press "Save changes" + And I am on homepage + And I follow "Course 1" + And I turn editing mode on + And I add a "Folder" to section "1" + And I fill the moodle form with: + | Name | Test folder | + | Description | Test folder description | + And I add "empty.txt" file from "Private files" to "Files" filemanager + And I should see "1" elements in "Files" filemanager + And I add and overwrite "empty.txt" file from "Private files" to "Files" filemanager + And I should see "1" elements in "Files" filemanager + And I add "empty.txt" file from "Private files" to "Files" filemanager as: + | Save as | empty_copy.txt | + And I should see "2" elements in "Files" filemanager + And I add and overwrite "empty.txt" file from "Private files" to "Files" filemanager as: + | Save as | empty_copy.txt | + And I should see "2" elements in "Files" filemanager + And I press "Save and display" + And I should see "empty.txt" + And I should see "empty_copy.txt" diff --git a/repository/tests/behat/zip_and_unzip.feature b/repository/tests/behat/zip_and_unzip.feature index 230fb2b3a28..ba8470c77cc 100644 --- a/repository/tests/behat/zip_and_unzip.feature +++ b/repository/tests/behat/zip_and_unzip.feature @@ -16,15 +16,15 @@ Feature: Zip folders and unzip compressed files And I fill the moodle form with: | Name | Folder resource | | Description | The description | - And I create "Folder 1" folder in "Files" filepicker - And I open "Folder 1" folder from "Files" filepicker - And I create "SubFolder 1" folder in "Files" filepicker - And I open "Files" folder from "Files" filepicker - And I zip "Folder 1" folder from "Files" filepicker - And I delete "Folder 1" from "Files" filepicker - When I unzip "Folder 1.zip" file from "Files" filepicker - And I delete "Folder 1.zip" from "Files" filepicker + And I create "Folder 1" folder in "Files" filemanager + And I open "Folder 1" folder from "Files" filemanager + And I create "SubFolder 1" folder in "Files" filemanager + And I open "Files" folder from "Files" filemanager + And I zip "Folder 1" folder from "Files" filemanager + And I delete "Folder 1" from "Files" filemanager + When I unzip "Folder 1.zip" file from "Files" filemanager + And I delete "Folder 1.zip" from "Files" filemanager Then I should see "Folder 1" - And I open "Folder 1" folder from "Files" filepicker + And I open "Folder 1" folder from "Files" filemanager And I should see "SubFolder 1" And I press "Save and return to course" diff --git a/repository/upload/tests/behat/behat_repository_upload.php b/repository/upload/tests/behat/behat_repository_upload.php index 08697fe694c..9fa490e287e 100644 --- a/repository/upload/tests/behat/behat_repository_upload.php +++ b/repository/upload/tests/behat/behat_repository_upload.php @@ -27,10 +27,11 @@ require_once(__DIR__ . '/../../../../lib/behat/behat_files.php'); -use Behat\Mink\Exception\ExpectationException as ExpectationException; +use Behat\Mink\Exception\ExpectationException as ExpectationException, + Behat\Gherkin\Node\TableNode as TableNode; /** - * Steps definitions to deal with the filepicker. + * Steps definitions to deal with the upload repository. * * Extends behat_files rather than behat_base as is file-related. * @@ -42,23 +43,77 @@ use Behat\Mink\Exception\ExpectationException as ExpectationException; class behat_repository_upload extends behat_files { /** - * Uploads a file to the specified file picker. It deals both with single-file and multiple-file filepickers. The paths should be relative to moodle codebase. + * Uploads a file to the specified filemanager leaving other fields in upload form default. The paths should be relative to moodle codebase. * - * @When /^I upload "(?P(?:[^"]|\\")*)" file to "(?P(?:[^"]|\\")*)" filepicker$/ + * @When /^I upload "(?P(?:[^"]|\\")*)" file to "(?P(?:[^"]|\\")*)" filemanager$/ * @throws ExpectationException Thrown by behat_base::find * @param string $filepath - * @param string $filepickerelement + * @param string $filemanagerelement */ - public function i_upload_file_to_filepicker($filepath, $filepickerelement) { + public function i_upload_file_to_filemanager($filepath, $filemanagerelement) { + $this->upload_file_to_filemanager($filepath, $filemanagerelement, new TableNode(), false); + } + + /** + * Uploads a file to the specified filemanager leaving other fields in upload form default and confirms to overwrite an existing file. The paths should be relative to moodle codebase. + * + * @When /^I upload and overwrite "(?P(?:[^"]|\\")*)" file to "(?P(?:[^"]|\\")*)" filemanager$/ + * @throws ExpectationException Thrown by behat_base::find + * @param string $filepath + * @param string $filemanagerelement + */ + public function i_upload_and_overwrite_file_to_filemanager($filepath, $filemanagerelement) { + $this->upload_file_to_filemanager($filepath, $filemanagerelement, new TableNode(), + get_string('overwrite', 'repository')); + } + + /** + * Uploads a file to the specified filemanager and confirms to overwrite an existing file. The paths should be relative to moodle codebase. + * + * @When /^I upload "(?P(?:[^"]|\\")*)" file to "(?P(?:[^"]|\\")*)" filemanager as:$/ + * @throws ExpectationException Thrown by behat_base::find + * @param string $filepath + * @param string $filemanagerelement + * @param TableNode $data Data to fill in upload form + */ + public function i_upload_file_to_filemanager_as($filepath, $filemanagerelement, TableNode $data) { + $this->upload_file_to_filemanager($filepath, $filemanagerelement, $data, false); + } + + /** + * Uploads a file to the specified filemanager. The paths should be relative to moodle codebase. + * + * @When /^I upload and overwrite "(?P(?:[^"]|\\")*)" file to "(?P(?:[^"]|\\")*)" filemanager as:$/ + * @throws ExpectationException Thrown by behat_base::find + * @param string $filepath + * @param string $filemanagerelement + * @param TableNode $data Data to fill in upload form + */ + public function i_upload_and_overwrite_file_to_filemanager_as($filepath, $filemanagerelement, TableNode $data) { + $this->upload_file_to_filemanager($filepath, $filemanagerelement, $data, + get_string('overwrite', 'repository')); + } + + /** + * Uploads a file to filemanager + * + * @throws ExpectationException Thrown by behat_base::find + * @param string $filepath + * @param string $filemanagerelement + * @param TableNode $data Data to fill in upload form + * @param false|string $overwriteaction false if we don't expect that file with the same name already exists, + * or button text in overwrite dialogue ("Overwrite", "Rename to ...", "Cancel") + */ + protected function upload_file_to_filemanager($filepath, $filemanagerelement, TableNode $data, $overwriteaction = false) { global $CFG; - $filepickernode = $this->get_filepicker_node($filepickerelement); + $filemanagernode = $this->get_filepicker_node($filemanagerelement); // Wait until file manager is completely loaded. - $this->wait_until_contents_are_updated($filepickernode); + $this->wait_until_contents_are_updated($filemanagernode); // Opening the select repository window and selecting the upload repository. - $this->open_add_file_window($filepickernode, get_string('pluginname', 'repository_upload')); + $this->open_add_file_window($filemanagernode, get_string('pluginname', 'repository_upload')); // Ensure all the form is ready. $this->getSession()->wait(2 * 1000, false); @@ -76,7 +131,6 @@ class behat_repository_upload extends behat_files { // Form elements to interact with. $file = $this->find_file('repo_upload_file'); - $submit = $this->find_button(get_string('upload', 'repository')); // Attaching specified file to the node. // Replace 'admin/' if it is in start of path with $CFG->admin . @@ -88,14 +142,35 @@ class behat_repository_upload extends behat_files { $fileabsolutepath = $CFG->dirroot . DIRECTORY_SEPARATOR . $filepath; $file->attachFile($fileabsolutepath); + // Fill the form in Upload window. + $datahash = $data->getRowsHash(); + + // The action depends on the field type. + foreach ($datahash as $locator => $value) { + // Getting the node element pointed by the label. + $fieldnode = $this->find_field($locator); + + // Gets the field type from a parent node. + $field = behat_field_manager::get_form_field($fieldnode, $this->getSession()); + + // Delegates to the field class. + $field->set_value($value); + } + // Submit the file. + $submit = $this->find_button(get_string('upload', 'repository')); $submit->press(); + if ($overwriteaction !== false) { + $this->getSession()->wait(1 * 1000, false); + $this->find_button($overwriteaction)->click(); + } + // Ensure the file has been uploaded and all ajax processes finished. $this->wait_until_return_to_form(); // Wait until file manager contents are updated. - $this->wait_until_contents_are_updated($filepickernode); + $this->wait_until_contents_are_updated($filemanagernode); } } diff --git a/repository/upload/tests/behat/upload_file.feature b/repository/upload/tests/behat/upload_file.feature index 1e028f7e2a3..0deead2b217 100644 --- a/repository/upload/tests/behat/upload_file.feature +++ b/repository/upload/tests/behat/upload_file.feature @@ -5,13 +5,19 @@ Feature: Upload files I need to upload files @javascript - Scenario: Upload a file in a multiple file filepicker + Scenario: Upload a file in a multiple file filemanager Given the following "courses" exists: | fullname | shortname | category | | Course 1 | C1 | 0 | And I log in as "admin" And I follow "Admin User" And I follow "My private files" - And I upload "lib/tests/fixtures/empty.txt" file to "Files" filepicker - Then I should see "empty.txt" in the "div.fp-content" "css_element" + And I upload "lib/tests/fixtures/empty.txt" file to "Files" filemanager + Then I should see "1" elements in "Files" filemanager + And I should see "empty.txt" in the "div.fp-content" "css_element" + When I upload "lib/tests/fixtures/empty.txt" file to "Files" filemanager as: + | Save as | empty_copy.txt | + Then I should see "2" elements in "Files" filemanager + And I should see "empty.txt" + And I should see "empty_copy.txt" And I press "Cancel"