[ Index ] |
PHP Cross Reference of Unnamed Project |
[Summary view] [Print] [Text view]
1 <?php 2 // This file is part of Moodle - http://moodle.org/ 3 // 4 // Moodle is free software: you can redistribute it and/or modify 5 // it under the terms of the GNU General Public License as published by 6 // the Free Software Foundation, either version 3 of the License, or 7 // (at your option) any later version. 8 // 9 // Moodle is distributed in the hope that it will be useful, 10 // but WITHOUT ANY WARRANTY; without even the implied warranty of 11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 // GNU General Public License for more details. 13 // 14 // You should have received a copy of the GNU General Public License 15 // along with Moodle. If not, see <http://www.gnu.org/licenses/>. 16 17 /** 18 * Filemanager and filepicker manipulation steps definitions. 19 * 20 * @package core_filepicker 21 * @category test 22 * @copyright 2013 David Monllaó 23 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later 24 */ 25 26 // NOTE: no MOODLE_INTERNAL test here, this file may be required by behat before including /config.php. 27 28 require_once (__DIR__ . '/../../../lib/behat/behat_files.php'); 29 30 use Behat\Mink\Exception\ExpectationException as ExpectationException, 31 Behat\Gherkin\Node\TableNode as TableNode; 32 33 /** 34 * Steps definitions to deal with the filemanager and filepicker. 35 * 36 * Extends behat_files rather than behat_base as is file-related. 37 * 38 * @package core_filepicker 39 * @category test 40 * @copyright 2013 David Monllaó 41 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later 42 */ 43 class behat_filepicker extends behat_files { 44 45 /** 46 * Creates a folder with specified name in the current folder and in the specified filemanager field. 47 * 48 * @Given /^I create "(?P<foldername_string>(?:[^"]|\\")*)" folder in "(?P<filemanager_field_string>(?:[^"]|\\")*)" filemanager$/ 49 * @throws ExpectationException Thrown by behat_base::find 50 * @param string $foldername 51 * @param string $filemanagerelement 52 */ 53 public function i_create_folder_in_filemanager($foldername, $filemanagerelement) { 54 55 $fieldnode = $this->get_filepicker_node($filemanagerelement); 56 57 // Looking for the create folder button inside the specified filemanager. 58 $exception = new ExpectationException('No folders can be created in "'.$filemanagerelement.'" filemanager', $this->getSession()); 59 $newfolder = $this->find('css', 'div.fp-btn-mkdir a', $exception, $fieldnode); 60 $newfolder->click(); 61 62 // Setting the folder name in the modal window. 63 $exception = new ExpectationException('The dialog to enter the folder name does not appear', $this->getSession()); 64 $dialoginput = $this->find('css', '.fp-mkdir-dlg-text input', $exception); 65 $dialoginput->setValue($foldername); 66 67 $exception = new ExpectationException('The button for the create folder dialog can not be located', $this->getSession()); 68 $dialognode = $this->find('css', '.moodle-dialogue-focused'); 69 $buttonnode = $this->find('css', '.fp-dlg-butcreate', $exception, $dialognode); 70 $buttonnode->click(); 71 } 72 73 /** 74 * Opens the contents of a filemanager folder. It looks for the folder in the current folder and in the path bar. 75 * 76 * @Given /^I open "(?P<foldername_string>(?:[^"]|\\")*)" folder from "(?P<filemanager_field_string>(?:[^"]|\\")*)" filemanager$/ 77 * @throws ExpectationException Thrown by behat_base::find 78 * @param string $foldername 79 * @param string $filemanagerelement 80 */ 81 public function i_open_folder_from_filemanager($foldername, $filemanagerelement) { 82 83 $fieldnode = $this->get_filepicker_node($filemanagerelement); 84 85 $exception = new ExpectationException( 86 'The "'.$foldername.'" folder can not be found in the "'.$filemanagerelement.'" filemanager', 87 $this->getSession() 88 ); 89 90 $folderliteral = behat_context_helper::escape($foldername); 91 92 // We look both in the pathbar and in the contents. 93 try { 94 95 // In the current folder workspace. 96 $folder = $this->find( 97 'xpath', 98 "//div[contains(concat(' ', normalize-space(@class), ' '), ' fp-folder ')]" . 99 "/descendant::div[contains(concat(' ', normalize-space(@class), ' '), ' fp-filename ')]" . 100 "[normalize-space(.)=$folderliteral]", 101 $exception, 102 $fieldnode 103 ); 104 } catch (ExpectationException $e) { 105 106 // And in the pathbar. 107 $folder = $this->find( 108 'xpath', 109 "//a[contains(concat(' ', normalize-space(@class), ' '), ' fp-path-folder-name ')]" . 110 "[normalize-space(.)=$folderliteral]", 111 $exception, 112 $fieldnode 113 ); 114 } 115 116 // It should be a NodeElement, otherwise an exception would have been thrown. 117 $folder->click(); 118 } 119 120 /** 121 * Unzips the specified file from the specified filemanager field. The zip file has to be visible in the current folder. 122 * 123 * @Given /^I unzip "(?P<filename_string>(?:[^"]|\\")*)" file from "(?P<filemanager_field_string>(?:[^"]|\\")*)" filemanager$/ 124 * @throws ExpectationException Thrown by behat_base::find 125 * @param string $filename 126 * @param string $filemanagerelement 127 */ 128 public function i_unzip_file_from_filemanager($filename, $filemanagerelement) { 129 130 // Open the contextual menu of the filemanager element. 131 $this->open_element_contextual_menu($filename, $filemanagerelement); 132 133 // Execute the action. 134 $exception = new ExpectationException($filename.' element can not be unzipped', $this->getSession()); 135 $this->perform_on_element('unzip', $exception); 136 } 137 138 /** 139 * Zips the specified folder from the specified filemanager field. The folder has to be in the current folder. 140 * 141 * @Given /^I zip "(?P<filename_string>(?:[^"]|\\")*)" folder from "(?P<filemanager_field_string>(?:[^"]|\\")*)" filemanager$/ 142 * @throws ExpectationException Thrown by behat_base::find 143 * @param string $foldername 144 * @param string $filemanagerelement 145 */ 146 public function i_zip_folder_from_filemanager($foldername, $filemanagerelement) { 147 148 // Open the contextual menu of the filemanager element. 149 $this->open_element_contextual_menu($foldername, $filemanagerelement); 150 151 // Execute the action. 152 $exception = new ExpectationException($foldername.' element can not be zipped', $this->getSession()); 153 $this->perform_on_element('zip', $exception); 154 } 155 156 /** 157 * Deletes the specified file or folder from the specified filemanager field. 158 * 159 * @Given /^I delete "(?P<file_or_folder_name_string>(?:[^"]|\\")*)" from "(?P<filemanager_field_string>(?:[^"]|\\")*)" filemanager$/ 160 * @throws ExpectationException Thrown by behat_base::find 161 * @param string $name 162 * @param string $filemanagerelement 163 */ 164 public function i_delete_file_from_filemanager($name, $filemanagerelement) { 165 166 // Open the contextual menu of the filemanager element. 167 $this->open_element_contextual_menu($name, $filemanagerelement); 168 169 // Execute the action. 170 $exception = new ExpectationException($name.' element can not be deleted', $this->getSession()); 171 $this->perform_on_element('delete', $exception); 172 173 // Yes, we are sure. 174 // Using xpath + click instead of pressButton as 'Ok' it is a common string. 175 $okbutton = $this->find('css', 'div.fp-dlg button.fp-dlg-butconfirm'); 176 $okbutton->click(); 177 } 178 179 180 /** 181 * Makes sure user can see the exact number of elements (files in folders) in the filemanager. 182 * 183 * @Then /^I should see "(?P<elementscount_number>\d+)" elements in "(?P<filemanagerelement_string>(?:[^"]|\\")*)" filemanager$/ 184 * @throws ExpectationException Thrown by behat_base::find 185 * @param int $elementscount 186 * @param string $filemanagerelement 187 */ 188 public function i_should_see_elements_in_filemanager($elementscount, $filemanagerelement) { 189 $filemanagernode = $this->get_filepicker_node($filemanagerelement); 190 191 // We count .fp-file elements inside a filemanager not being updated. 192 $xpath = "//div[contains(concat(' ', normalize-space(@class), ' '), ' filemanager ')]" . 193 "[not(contains(concat(' ', normalize-space(@class), ' '), ' fm-updating '))]" . 194 "//div[contains(concat(' ', normalize-space(@class), ' '), ' fp-content ')]" . 195 "//div[contains(concat(' ', normalize-space(@class), ' '), ' fp-file ')]"; 196 197 $elements = $this->find_all('xpath', $xpath, false, $filemanagernode); 198 if (count($elements) != $elementscount) { 199 throw new ExpectationException('Found '.count($elements).' elements in filemanager instead of expected '.$elementscount, $this->getSession()); 200 } 201 } 202 203 /** 204 * Picks the file from repository leaving default values in select file dialogue. 205 * 206 * @When /^I add "(?P<filepath_string>(?:[^"]|\\")*)" file from "(?P<repository_string>(?:[^"]|\\")*)" to "(?P<filemanagerelement_string>(?:[^"]|\\")*)" filemanager$/ 207 * @throws ExpectationException Thrown by behat_base::find 208 * @param string $filepath 209 * @param string $repository 210 * @param string $filemanagerelement 211 */ 212 public function i_add_file_from_repository_to_filemanager($filepath, $repository, $filemanagerelement) { 213 $this->add_file_from_repository_to_filemanager($filepath, $repository, $filemanagerelement, new TableNode(array()), false); 214 } 215 216 /** 217 * Picks the file from repository leaving default values in select file dialogue and confirming to overwrite an existing file. 218 * 219 * @When /^I add and overwrite "(?P<filepath_string>(?:[^"]|\\")*)" file from "(?P<repository_string>(?:[^"]|\\")*)" to "(?P<filemanagerelement_string>(?:[^"]|\\")*)" filemanager$/ 220 * @throws ExpectationException Thrown by behat_base::find 221 * @param string $filepath 222 * @param string $repository 223 * @param string $filemanagerelement 224 */ 225 public function i_add_and_overwrite_file_from_repository_to_filemanager($filepath, $repository, $filemanagerelement) { 226 $this->add_file_from_repository_to_filemanager($filepath, $repository, $filemanagerelement, new TableNode(array()), 227 get_string('overwrite', 'repository')); 228 } 229 230 /** 231 * Picks the file from repository filling the form in Select file dialogue. 232 * 233 * @When /^I add "(?P<filepath_string>(?:[^"]|\\")*)" file from "(?P<repository_string>(?:[^"]|\\")*)" to "(?P<filemanager_field_string>(?:[^"]|\\")*)" filemanager as:$/ 234 * @throws ExpectationException Thrown by behat_base::find 235 * @param string $filepath 236 * @param string $repository 237 * @param string $filemanagerelement 238 * @param TableNode $data Data to fill the form in Select file dialogue 239 */ 240 public function i_add_file_from_repository_to_filemanager_as($filepath, $repository, $filemanagerelement, TableNode $data) { 241 $this->add_file_from_repository_to_filemanager($filepath, $repository, $filemanagerelement, $data, false); 242 } 243 244 /** 245 * Picks the file from repository confirming to overwrite an existing file 246 * 247 * @When /^I add and overwrite "(?P<filepath_string>(?:[^"]|\\")*)" file from "(?P<repository_string>(?:[^"]|\\")*)" to "(?P<filemanager_field_string>(?:[^"]|\\")*)" filemanager as:$/ 248 * @throws ExpectationException Thrown by behat_base::find 249 * @param string $filepath 250 * @param string $repository 251 * @param string $filemanagerelement 252 * @param TableNode $data Data to fill the form in Select file dialogue 253 */ 254 public function i_add_and_overwrite_file_from_repository_to_filemanager_as($filepath, $repository, $filemanagerelement, TableNode $data) { 255 $this->add_file_from_repository_to_filemanager($filepath, $repository, $filemanagerelement, $data, 256 get_string('overwrite', 'repository')); 257 } 258 259 /** 260 * Picks the file from private files repository 261 * 262 * @throws ExpectationException Thrown by behat_base::find 263 * @param string $filepath 264 * @param string $repository 265 * @param string $filemanagerelement 266 * @param TableNode $data Data to fill the form in Select file dialogue 267 * @param false|string $overwriteaction false if we don't expect that file with the same name already exists, 268 * or button text in overwrite dialogue ("Overwrite", "Rename to ...", "Cancel") 269 */ 270 protected function add_file_from_repository_to_filemanager($filepath, $repository, $filemanagerelement, TableNode $data, 271 $overwriteaction = false) { 272 $filemanagernode = $this->get_filepicker_node($filemanagerelement); 273 274 // Opening the select repository window and selecting the upload repository. 275 $this->open_add_file_window($filemanagernode, $repository); 276 277 $this->open_element_contextual_menu($filepath); 278 279 // Fill the form in Select window. 280 $datahash = $data->getRowsHash(); 281 282 // The action depends on the field type. 283 foreach ($datahash as $locator => $value) { 284 285 $field = behat_field_manager::get_form_field_from_label($locator, $this); 286 287 // Delegates to the field class. 288 $field->set_value($value); 289 } 290 291 $selectfilebutton = $this->find_button(get_string('getfile', 'repository')); 292 $this->ensure_node_is_visible($selectfilebutton); 293 $selectfilebutton->click(); 294 295 // We wait for all the JS to finish as it is performing an action. 296 $this->getSession()->wait(self::TIMEOUT, self::PAGE_READY_JS); 297 298 if ($overwriteaction !== false) { 299 $overwritebutton = $this->find_button($overwriteaction); 300 $this->ensure_node_is_visible($overwritebutton); 301 $overwritebutton->click(); 302 303 // We wait for all the JS to finish. 304 $this->getSession()->wait(self::TIMEOUT, self::PAGE_READY_JS); 305 } 306 307 } 308 309 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Thu Aug 11 10:00:09 2016 | Cross-referenced by PHPXref 0.7.1 |