Merge branch 'MDL-38950_master' of git://github.com/dmonllao/moodle

This commit is contained in:
Eloy Lafuente (stronk7) 2013-04-09 23:42:59 +02:00
commit 3621633194
4 changed files with 146 additions and 10 deletions

View File

@ -54,7 +54,7 @@ class behat_files extends behat_base {
* not recognized as a named selector, as it is hidden...
*
* @throws ExpectationException Thrown by behat_base::find
* @param string $filepickerelement
* @param string $filepickerelement The filepicker form field label
* @return NodeElement The hidden element node.
*/
protected function get_filepicker_node($filepickerelement) {
@ -96,16 +96,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.
*
* @throws ExpectationException Thrown by behat_base::find
* @param string $name The name of the folder/file
* @param string $filepickerelement The filepicker locator, usually the form element label
* @param string $filepickerelement The filepicker locator, the whole DOM if false
* @return void
*/
protected function open_element_contextual_menu($name, $filepickerelement) {
protected function open_element_contextual_menu($name, $filepickerelement = false) {
$filepickernode = $this->get_filepicker_node($filepickerelement);
// If a filepicker is specified we restrict the search to the filepicker descendants.
$containernode = false;
$exceptionmsg = '"'.$name.'" element can not be found';
if ($filepickerelement) {
$containernode = $this->get_filepicker_node($filepickerelement);
$exceptionmsg = 'The "'.$filepickerelement.'" filepicker ' . $exceptionmsg;
}
$exception = new ExpectationException('The "'.$filepickerelement.'" filepicker "'.$name.'" element can not be found', $this->getSession());
$exception = new ExpectationException($exceptionmsg, $this->getSession());
// Get a filepicker element (folder or file).
try {
@ -114,12 +123,12 @@ class behat_files extends behat_base {
$node = $this->find(
'xpath',
"//div[@class='fp-content']
//descendant::div[contains(concat(' ', normalize-space(@class), ' '), ' fp-file ')]
//descendant::*[self::div | self::a][contains(concat(' ', normalize-space(@class), ' '), ' fp-file ')]
[contains(concat(' ', normalize-space(@class), ' '), ' fp-folder ')][contains(normalize-space(string(.)), '" . $name . "')]
//descendant::a[contains(concat(' ', normalize-space(@class), ' '), ' fp-contextmenu ')]
",
$exception,
$filepickernode
$containernode
);
} catch (ExpectationException $e) {
@ -128,11 +137,11 @@ class behat_files extends behat_base {
$node = $this->find(
'xpath',
"//div[@class='fp-content']
//descendant::div[contains(concat(' ', normalize-space(@class), ' '), ' fp-file ')][contains(normalize-space(string(.)), '" . $name . "')]
//descendant::*[self::div | self::a][contains(concat(' ', normalize-space(@class), ' '), ' fp-file ')][contains(normalize-space(string(.)), '" . $name . "')]
//descendant::div[contains(concat(' ', normalize-space(@class), ' '), ' fp-thumbnail ')]
",
$exception,
$filepickernode
false,
$containernode
);
}

View File

@ -0,0 +1,28 @@
@repository_recent @_only_local
Feature: Recent files repository lists the recently used files
In order to save time when selecting files
As a moodle user
I need to use again the files I've just used
@javascript
Scenario: Add files recently uploaded
Given the following "courses" exists:
| fullname | shortname | category |
| Course 1 | C1 | 0 |
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 press "Save changes"
And I am on homepage
And I follow "Course 1"
And I turn editing mode on
When I add a "Folder" to section "1"
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 press "Save and display"
Then I should see "empty.txt"
And I should see "Folder description"

View File

@ -0,0 +1,65 @@
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* 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<filename_string>(?:[^"]|\\")*)" file from recent files to "(?P<filepicker_field_string>(?:[^"]|\\")*)" 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('Select this file')->click();
// Wait a while for the file to be selected.
$this->getSession()->wait(3 * 1000, false);
}
}

View File

@ -0,0 +1,34 @@
@repository @_only_local
Feature: A selected file can be cancelled
In order to refine the file manager contents
As a moodle user
I need to cancel a selected file
@javascript
Scenario: Cancel a selected recent file from being added to a folder
Given the following "courses" exists:
| fullname | shortname | category |
| Course 1 | C1 | 0 |
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 press "Save changes"
And I am on homepage
And I follow "Course 1"
And I turn editing mode on
When I add a "Folder" to section "1"
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 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(' ', @class, ' '), ' fp-file ')][contains(., 'empty.txt')]" "xpath_element"
And I wait "2" seconds
And I click on ".fp-select .fp-select-cancel" "css_element"
And I click on ".file-picker button.yui3-button-close" "css_element"
And I press "Save and display"
Then I should see "upload_users.csv"
And I should not see "empty.txt"
And I should see "Folder description"