From d87bbb3d3dc83357c411ca466bdcb429915f3100 Mon Sep 17 00:00:00 2001 From: David Monllao Date: Mon, 1 Apr 2013 12:16:57 +0800 Subject: [PATCH 1/3] MDL-38814 behat: Move filepicker steps definitions to repository/ --- repository/tests/behat/behat_filepicker.php | 189 ++++++++++++++++++++ 1 file changed, 189 insertions(+) create mode 100644 repository/tests/behat/behat_filepicker.php diff --git a/repository/tests/behat/behat_filepicker.php b/repository/tests/behat/behat_filepicker.php new file mode 100644 index 00000000000..10c9b3f0241 --- /dev/null +++ b/repository/tests/behat/behat_filepicker.php @@ -0,0 +1,189 @@ +. + +/** + * Files and filepicker manipulation steps definitions. + * + * @package core + * @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'); + +use Behat\Mink\Exception\ExpectationException as ExpectationException; + +/** + * Steps definitions to deal with the filepicker. + * + * Extends behat_files rather than behat_base as is file-related. + * + * @package core + * @category test + * @copyright 2013 David Monllaó + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ +class behat_filepicker extends behat_files { + + /** + * Creates a folder with specified name in the current folder and in the specified filepicker field. + * + * @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) { + + $fieldnode = $this->get_filepicker_node($filepickerelement); + + // Looking for the create folder button inside the specified filepicker. + $exception = new ExpectationException('No folders can be created in "'.$filepickerelement.'" filepicker', $this->getSession()); + $newfolder = $this->find('css', 'div.fp-btn-mkdir a', $exception, $fieldnode); + $newfolder->click(); + + // Setting the folder name in the modal window. + $exception = new ExpectationException('The dialog to enter the folder name does not appear', $this->getSession()); + $dialoginput = $this->find('css', '.fp-mkdir-dlg-text input'); + $dialoginput->setValue($foldername); + + $this->getSession()->getPage()->pressButton('Create folder'); + + // Wait few seconds for the folder to be created and filepicker contents reloaded. + $this->getSession()->wait(4 * 1000, false); + } + + /** + * Opens the contents of a filepicker folder. It looks for the folder in the current folder and in the path bar. + * + * @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) { + + $fieldnode = $this->get_filepicker_node($filepickerelement); + + $exception = new ExpectationException( + 'The "'.$foldername.'" folder can not be found in the "'.$filepickerelement.'" filepicker', + $this->getSession() + ); + + // We look both in the pathbar and in the contents. + try { + + // In the current folder workspace. + $folder = $this->find( + 'xpath', + "//div[contains(concat(' ', normalize-space(@class), ' '), ' fp-folder ')] +//descendant::div[contains(concat(' ', normalize-space(.), ' '), '" . $foldername . "')]", + $exception, + $fieldnode + ); + } catch (ExpectationException $e) { + + // And in the pathbar. + $folder = $this->find( + 'xpath', + "//a[contains(concat(' ', normalize-space(@class), ' '), ' fp-path-folder-name ')] +[contains(concat(' ', normalize-space(.), ' '), '" . $foldername . "')]", + $exception, + $fieldnode + ); + } + + // It should be a NodeElement, otherwise an exception would have been thrown. + $folder->click(); + + // Wait few seconds for the filepicker contents to be updated. + $this->getSession()->wait(4 * 1000, false); + } + + /** + * Unzips the specified file from the specified filepicker field. The zip file has to be visible in the current folder. + * + * @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) { + + // Open the contextual menu of the filepicker element. + $this->open_element_contextual_menu($filename, $filepickerelement); + + // Execute the action. + $exception = new ExpectationException($filename.' element can not be unzipped', $this->getSession()); + $this->perform_on_element('unzip', $exception); + + // Wait few seconds. + // Here the time will depend on the zip contents and the server load, so it better to be conservative. + $this->getSession()->wait(8 * 1000, false); + } + + /** + * Zips the specified folder from the specified filepicker field. The folder has to be in the current folder. + * + * @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) { + + // Open the contextual menu of the filepicker element. + $this->open_element_contextual_menu($foldername, $filepickerelement); + + // Execute the action. + $exception = new ExpectationException($foldername.' element can not be zipped', $this->getSession()); + $this->perform_on_element('zip', $exception); + + // Wait few seconds. + // Here the time will depend on the folder contents and the server load, so it better to be conservative. + $this->getSession()->wait(8 * 1000, false); + } + + /** + * Deletes the specified file or folder from the specified filepicker field. + * + * @Given /^I delete "(?P(?:[^"]|\\")*)" from "(?P(?:[^"]|\\")*)" filepicker$/ + * @throws ExpectationException Thrown by behat_base::find + * @param string $foldername + * @param string $filepickerelement + */ + public function i_delete_file_from_filepicker($name, $filepickerelement) { + + // Open the contextual menu of the filepicker element. + $this->open_element_contextual_menu($name, $filepickerelement); + + // Execute the action. + $exception = new ExpectationException($name.' element can not be deleted', $this->getSession()); + $this->perform_on_element('delete', $exception); + + // Yes, we are sure. + // Using xpath + click instead of pressButton as 'Ok' it is a common string. + $okbutton = $this->find('css', 'div.fp-dlg button.fp-dlg-butconfirm'); + $okbutton->click(); + + // Wait few seconds until filepicker contents are reloaded. + $this->getSession()->wait(4 * 1000, false); + } + +} From 95932c376b16c4e57b5dba8cc759372fe837d470 Mon Sep 17 00:00:00 2001 From: David Monllao Date: Mon, 1 Apr 2013 12:17:41 +0800 Subject: [PATCH 2/3] DML-38814 behat: Split steps definitions tests into features --- repository/tests/behat/create_folders.feature | 26 ++++++++++++++++ repository/tests/behat/zip_and_unzip.feature | 30 +++++++++++++++++++ 2 files changed, 56 insertions(+) create mode 100644 repository/tests/behat/create_folders.feature create mode 100644 repository/tests/behat/zip_and_unzip.feature diff --git a/repository/tests/behat/create_folders.feature b/repository/tests/behat/create_folders.feature new file mode 100644 index 00000000000..d34712a19ab --- /dev/null +++ b/repository/tests/behat/create_folders.feature @@ -0,0 +1,26 @@ +@core_form @filepicker +Feature: Create folders in the file manager + In order to create a directory structure in a file area + As a moodle user + I need to create folders and subfolders in a file area + + @javascript + Scenario: Create folders and subfolders + Given the following "courses" exists: + | fullname | shortname | category | + | Course 1 | C1 | 0 | + And I log in as "admin" + And I follow "Course 1" + And I turn editing mode on + And I add a "Folder" to section "0" + 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 + Then I should see "Folder 1" + And I open "Folder 1" folder from "Files" filepicker + And I should see "SubFolder 1" + And I press "Save and return to course" diff --git a/repository/tests/behat/zip_and_unzip.feature b/repository/tests/behat/zip_and_unzip.feature new file mode 100644 index 00000000000..ff5f79a983e --- /dev/null +++ b/repository/tests/behat/zip_and_unzip.feature @@ -0,0 +1,30 @@ +@core_form @filepicker +Feature: Zip folders and unzip compressed files + In order to download or add contents to file areas easily + As a moodle user + I need to zip and unzip folders and files + + @javascript + Scenario: Zip and unzip folders and files + Given the following "courses" exists: + | fullname | shortname | category | + | Course 1 | C1 | 0 | + And I log in as "admin" + And I follow "Course 1" + And I turn editing mode on + And I add a "Folder" to section "0" + 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 + Then I should see "Folder 1" + And I open "Folder 1" folder from "Files" filepicker + And I should see "SubFolder 1" + And I press "Save and return to course" From 5bc64b0fab594625f06d9d0672936ebbafd50385 Mon Sep 17 00:00:00 2001 From: David Monllao Date: Mon, 1 Apr 2013 12:21:05 +0800 Subject: [PATCH 3/3] MDL-38814 behat: Deleting old files --- .../tests/behat/manipulate_filepicker.feature | 40 ---- lib/tests/behat/behat_filepicker.php | 189 ------------------ 2 files changed, 229 deletions(-) delete mode 100644 admin/tool/behat/tests/behat/manipulate_filepicker.feature delete mode 100644 lib/tests/behat/behat_filepicker.php diff --git a/admin/tool/behat/tests/behat/manipulate_filepicker.feature b/admin/tool/behat/tests/behat/manipulate_filepicker.feature deleted file mode 100644 index b5b3d94cb9f..00000000000 --- a/admin/tool/behat/tests/behat/manipulate_filepicker.feature +++ /dev/null @@ -1,40 +0,0 @@ -@tool_behat @core_form @filepicker -Feature: Manipulate filepicker - In order to provide external resources - As a moodle user - I need to upload files to moodle - - Background: - Given the following "courses" exists: - | fullname | shortname | category | - | Course 1 | C1 | 0 | - And I log in as "admin" - And I follow "Course 1" - And I turn editing mode on - And I add a "Folder" to section "0" - 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 - - @javascript - Scenario: Create folders and subfolders - When I open "Files" folder from "Files" filepicker - Then I should see "Folder 1" - And I open "Folder 1" folder from "Files" filepicker - And I should see "SubFolder 1" - And I press "Save and return to course" - - @javascript - Scenario: Zip and unzip folders and files - Given 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 - Then I should see "Folder 1" - And I open "Folder 1" folder from "Files" filepicker - And I should see "SubFolder 1" - And I press "Save and return to course" diff --git a/lib/tests/behat/behat_filepicker.php b/lib/tests/behat/behat_filepicker.php deleted file mode 100644 index 68a79b11d94..00000000000 --- a/lib/tests/behat/behat_filepicker.php +++ /dev/null @@ -1,189 +0,0 @@ -. - -/** - * Files and filepicker manipulation steps definitions. - * - * @package core - * @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__ . '/../../behat/behat_files.php'); - -use Behat\Mink\Exception\ExpectationException as ExpectationException; - -/** - * Steps definitions to deal with the filepicker. - * - * Extends behat_files rather than behat_base as is file-related. - * - * @package core - * @category test - * @copyright 2013 David Monllaó - * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later - */ -class behat_filepicker extends behat_files { - - /** - * Creates a folder with specified name in the current folder and in the specified filepicker field. - * - * @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) { - - $fieldnode = $this->get_filepicker_node($filepickerelement); - - // Looking for the create folder button inside the specified filepicker. - $exception = new ExpectationException('No folders can be created in "'.$filepickerelement.'" filepicker', $this->getSession()); - $newfolder = $this->find('css', 'div.fp-btn-mkdir a', $exception, $fieldnode); - $newfolder->click(); - - // Setting the folder name in the modal window. - $exception = new ExpectationException('The dialog to enter the folder name does not appear', $this->getSession()); - $dialoginput = $this->find('css', '.fp-mkdir-dlg-text input'); - $dialoginput->setValue($foldername); - - $this->getSession()->getPage()->pressButton('Create folder'); - - // Wait few seconds for the folder to be created and filepicker contents reloaded. - $this->getSession()->wait(4 * 1000, false); - } - - /** - * Opens the contents of a filepicker folder. It looks for the folder in the current folder and in the path bar. - * - * @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) { - - $fieldnode = $this->get_filepicker_node($filepickerelement); - - $exception = new ExpectationException( - 'The "'.$foldername.'" folder can not be found in the "'.$filepickerelement.'" filepicker', - $this->getSession() - ); - - // We look both in the pathbar and in the contents. - try { - - // In the current folder workspace. - $folder = $this->find( - 'xpath', - "//div[contains(concat(' ', normalize-space(@class), ' '), ' fp-folder ')] -//descendant::div[contains(concat(' ', normalize-space(.), ' '), '" . $foldername . "')]", - $exception, - $fieldnode - ); - } catch (ExpectationException $e) { - - // And in the pathbar. - $folder = $this->find( - 'xpath', - "//a[contains(concat(' ', normalize-space(@class), ' '), ' fp-path-folder-name ')] -[contains(concat(' ', normalize-space(.), ' '), '" . $foldername . "')]", - $exception, - $fieldnode - ); - } - - // It should be a NodeElement, otherwise an exception would have been thrown. - $folder->click(); - - // Wait few seconds for the filepicker contents to be updated. - $this->getSession()->wait(4 * 1000, false); - } - - /** - * Unzips the specified file from the specified filepicker field. The zip file has to be visible in the current folder. - * - * @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) { - - // Open the contextual menu of the filepicker element. - $this->open_element_contextual_menu($filename, $filepickerelement); - - // Execute the action. - $exception = new ExpectationException($filename.' element can not be unzipped', $this->getSession()); - $this->perform_on_element('unzip', $exception); - - // Wait few seconds. - // Here the time will depend on the zip contents and the server load, so it better to be conservative. - $this->getSession()->wait(8 * 1000, false); - } - - /** - * Zips the specified folder from the specified filepicker field. The folder has to be in the current folder. - * - * @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) { - - // Open the contextual menu of the filepicker element. - $this->open_element_contextual_menu($foldername, $filepickerelement); - - // Execute the action. - $exception = new ExpectationException($foldername.' element can not be zipped', $this->getSession()); - $this->perform_on_element('zip', $exception); - - // Wait few seconds. - // Here the time will depend on the folder contents and the server load, so it better to be conservative. - $this->getSession()->wait(8 * 1000, false); - } - - /** - * Deletes the specified file or folder from the specified filepicker field. - * - * @Given /^I delete "(?P(?:[^"]|\\")*)" from "(?P(?:[^"]|\\")*)" filepicker$/ - * @throws ExpectationException Thrown by behat_base::find - * @param string $foldername - * @param string $filepickerelement - */ - public function i_delete_file_from_filepicker($name, $filepickerelement) { - - // Open the contextual menu of the filepicker element. - $this->open_element_contextual_menu($name, $filepickerelement); - - // Execute the action. - $exception = new ExpectationException($name.' element can not be deleted', $this->getSession()); - $this->perform_on_element('delete', $exception); - - // Yes, we are sure. - // Using xpath + click instead of pressButton as 'Ok' it is a common string. - $okbutton = $this->find('css', 'div.fp-dlg button.fp-dlg-butconfirm'); - $okbutton->click(); - - // Wait few seconds until filepicker contents are reloaded. - $this->getSession()->wait(4 * 1000, false); - } - -}