Skip to content

Commit

Permalink
MDL-38950 behat: File manager elements contextual menu
Browse files Browse the repository at this point in the history
Modified to work with both file manager elements
and file/folder elements inside modal windows.
  • Loading branch information
David Monllao committed Apr 9, 2013
1 parent 422f68f commit 0b297fd
Showing 1 changed file with 20 additions and 11 deletions.
31 changes: 20 additions & 11 deletions lib/behat/behat_files.php
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -96,16 +96,25 @@ protected function perform_on_element($action, ExpectationException $exception)
/**
* 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) {

$filepickernode = $this->get_filepicker_node($filepickerelement);
protected function open_element_contextual_menu($name, $filepickerelement = false) {

// 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 {
Expand All @@ -114,12 +123,12 @@ protected function open_element_contextual_menu($name, $filepickerelement) {
$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) {
Expand All @@ -128,11 +137,11 @@ protected function open_element_contextual_menu($name, $filepickerelement) {
$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
);
}

Expand Down

0 comments on commit 0b297fd

Please sign in to comment.