@@ -471,45 +471,57 @@ protected function get_cm_by_questionnaire_name(string $name): stdClass {
471
471
*
472
472
* The paths should be relative to moodle codebase.
473
473
*
474
- * @When /^I upload "(?P<filepath_string>(?:[^"]|\\")*)" to questionnaire filemanager$/
474
+ * @When /^I upload "(?P<filepath_string>(?:[^"]|\\")*)" to questionnaire "(?P<question_string>(?:[^"]|\\")*)" filemanager$/
475
475
* @param string $filepath
476
+ * @param string $question
476
477
*/
477
- public function i_upload_file_to_questionnaire_filemanager ($ filepath ) {
478
- $ this ->upload_file_to_filemanager_questionnaire ($ filepath , new TableNode (array ()) );
478
+ public function i_upload_file_to_questionnaire_question_filemanager ($ filepath, $ question ) {
479
+ $ this ->upload_file_to_question_filemanager_questionnaire ($ filepath , $ question , new TableNode ([]), false );
479
480
}
480
481
481
482
/**
482
- * Try to get the filemanager node.
483
+ * Try to get the filemanager node of a given question .
483
484
*
484
- * @return NodeElement
485
+ * @param $question
486
+ * @return \Behat\Mink\Element\NodeElement|null
485
487
*/
486
- protected function get_filemanager () {
488
+ protected function get_filepicker_node ($ question ) {
489
+ // More info about the problem (in case there is a problem).
490
+ $ exception = new ExpectationException ('The filepicker for the question with text " ' . $ question .
491
+ '" can not be found ' , $ this ->getSession ());
487
492
488
- // If no file picker label is mentioned take the first file picker from the page.
489
- return $ this ->find (
493
+ $ filepickercontainer = $ this ->find (
490
494
'xpath ' ,
491
- '//div[contains(concat(" ", normalize-space(@class), " "), " filemanager ")] '
495
+ "//p[contains(.,' " . $ question . "')] " .
496
+ "//parent::div[contains(concat(' ', normalize-space(@class), ' '), ' no-overflow ')] " .
497
+ "//parent::div[contains(concat(' ', normalize-space(@class), ' '), ' qn-question ')] " .
498
+ "//following::div[contains(concat(' ', normalize-space(@class), ' '), ' qn-answer ')] " .
499
+ "//descendant::*[@data-fieldtype = 'filemanager' or @data-fieldtype = 'filepicker'] " ,
500
+ $ exception
492
501
);
502
+
503
+ return $ filepickercontainer ;
493
504
}
494
505
495
506
/**
496
507
* Uploads a file to filemanager
497
508
*
498
509
* @param string $filepath Normally a path relative to $CFG->dirroot, but can be an absolute path too.
510
+ * @param string $question A question text.
499
511
* @param TableNode $data Data to fill in upload form
500
512
* @param false|string $overwriteaction false if we don't expect that file with the same name already exists,
501
513
* or button text in overwrite dialogue ("Overwrite", "Rename to ...", "Cancel")
502
514
* @throws DriverException
503
515
* @throws ExpectationException Thrown by behat_base::find
504
516
*/
505
- protected function upload_file_to_filemanager_questionnaire ($ filepath , TableNode $ data , $ overwriteaction = false ) {
517
+ protected function upload_file_to_question_filemanager_questionnaire ($ filepath, $ question , TableNode $ data , $ overwriteaction = false ) {
506
518
global $ CFG ;
507
519
508
520
if (!$ this ->has_tag ('_file_upload ' )) {
509
521
throw new DriverException ('File upload tests must have the @_file_upload tag on either the scenario or feature. ' );
510
522
}
511
523
512
- $ filemanagernode = $ this ->get_filemanager ( );
524
+ $ filemanagernode = $ this ->get_filepicker_node ( $ question );
513
525
514
526
// Opening the select repository window and selecting the upload repository.
515
527
$ this ->open_add_file_window ($ filemanagernode , get_string ('pluginname ' , 'repository_upload ' ));
@@ -576,40 +588,6 @@ protected function upload_file_to_filemanager_questionnaire($filepath, TableNode
576
588
577
589
}
578
590
579
- /**
580
- * Try to get the filemanager node specified by the element
581
- *
582
- * @param string $filepickerelement
583
- * @return NodeElement
584
- * @throws ExpectationException
585
- */
586
- protected function get_filepicker_node ($ filepickerelement ) {
587
-
588
- // More info about the problem (in case there is a problem).
589
- $ exception = new ExpectationException ('" ' . $ filepickerelement . '" filepicker can not be found ' , $ this ->getSession ());
590
-
591
- // If no file picker label is mentioned take the first file picker from the page.
592
- if (empty ($ filepickerelement )) {
593
- $ filepickercontainer = $ this ->find (
594
- 'xpath ' ,
595
- "//*[@class= \"form-filemanager \"] " ,
596
- $ exception
597
- );
598
- } else {
599
- // Gets the filemanager node specified by the locator which contains the filepicker container
600
- // either for filepickers created by mform or by admin config.
601
- $ filepickerelement = behat_context_helper::escape ($ filepickerelement );
602
- $ filepickercontainer = $ this ->find (
603
- 'xpath ' ,
604
- "//input[./@id = substring-before(//p[normalize-space(.)= $ filepickerelement]/@id, '_label')] " .
605
- "//ancestor::*[@data-fieldtype = 'filemanager' or @data-fieldtype = 'filepicker'] " ,
606
- $ exception
607
- );
608
- }
609
-
610
- return $ filepickercontainer ;
611
- }
612
-
613
591
/**
614
592
* Opens the filepicker modal window and selects the repository.
615
593
*
0 commit comments