From 4b6ffc5064d76e80f25188002e1ea4fa7b9432e3 Mon Sep 17 00:00:00 2001 From: Simey Lameze Date: Thu, 12 Feb 2026 08:42:13 +0800 Subject: [PATCH] MDL-87095 behat: reorganize lesson question importing tests --- .../import_fillintheblank_question.feature | 38 ---------- mod/lesson/tests/behat/import_images.feature | 35 --------- .../tests/behat/import_questions.feature | 76 ++++++++++++------- .../fixtures/lesson_import_questions.gift | 12 --- .../tests/fixtures/moodle_questions.gift | 19 +++++ 5 files changed, 69 insertions(+), 111 deletions(-) delete mode 100644 mod/lesson/tests/behat/import_fillintheblank_question.feature delete mode 100644 mod/lesson/tests/behat/import_images.feature delete mode 100644 mod/lesson/tests/fixtures/lesson_import_questions.gift create mode 100644 mod/lesson/tests/fixtures/moodle_questions.gift diff --git a/mod/lesson/tests/behat/import_fillintheblank_question.feature b/mod/lesson/tests/behat/import_fillintheblank_question.feature deleted file mode 100644 index eaf2e7d60ad..00000000000 --- a/mod/lesson/tests/behat/import_fillintheblank_question.feature +++ /dev/null @@ -1,38 +0,0 @@ -@mod @mod_lesson -Feature: In a lesson activity, teacher can import blackboard fill in the blank question - As a teacher - I need to import a fill in the blank question made in Blackboard in a lesson - - @javascript @_file_upload - Scenario: Import fill in the blank question in a lesson - Given the following "users" exist: - | username | firstname | lastname | email | - | teacher1 | Teacher | 1 | teacher1@example.com | - | student1 | Student | 1 | student1@example.com | - And the following "courses" exist: - | fullname | shortname | category | - | Course 1 | C1 | 0 | - And the following "course enrolments" exist: - | user | course | role | - | teacher1 | C1 | editingteacher | - | student1 | C1 | student | - And the following "activity" exists: - | course | C1 | - | activity | lesson | - | name | Test lesson name | - When I am on the "Test lesson name" "lesson activity" page logged in as teacher1 - And I follow "Import questions" - And I set the field "File format" to "Blackboard" - And I upload "mod/lesson/tests/fixtures/sample_blackboard_fib_qti.dat" file to "Upload" filemanager - And I press "Import" - Then I should see "Importing 1 questions" - And I should see "Name an amphibian: __________" - And I press "Continue" - And I should not see "__________" - And I should not see "Your answer" - And I set the field "id_answer" to "frog" - And I press "Submit" - And I should see "Your answer : frog" - And I should see "A frog is an amphibian" - And I press "Continue" - And I should see "Congratulations - end of lesson reached" diff --git a/mod/lesson/tests/behat/import_images.feature b/mod/lesson/tests/behat/import_images.feature deleted file mode 100644 index 8056e0ba995..00000000000 --- a/mod/lesson/tests/behat/import_images.feature +++ /dev/null @@ -1,35 +0,0 @@ -@mod @mod_lesson -Feature: In a lesson activity, teacher can import embedded images in questions answers and responses - As a teacher - I need to import a question with images in answers and responses in a lesson - - @javascript @_file_upload - Scenario: Import questions with images in answers and responses in a lesson - Given the following "users" exist: - | username | firstname | lastname | email | - | teacher1 | Teacher | 1 | teacher1@example.com | - | student1 | Student | 1 | student1@example.com | - And the following "courses" exist: - | fullname | shortname | category | - | Course 1 | C1 | 0 | - And the following "course enrolments" exist: - | user | course | role | - | teacher1 | C1 | editingteacher | - | student1 | C1 | student | - And the following "activity" exists: - | course | C1 | - | activity | lesson | - | name | Test lesson name | - When I am on the "Test lesson name" "lesson activity" page logged in as teacher1 - And I follow "Import questions" - And I set the field "File format" to "Moodle XML format" - And I upload "mod/lesson/tests/fixtures/multichoice.xml" file to "Upload" filemanager - And I press "Import" - Then I should see "Importing 1 questions" - And I should see " Listen to this greeting:" - And I should see "What language is being spoken?" - And I press "Continue" - And I should see "What language is being spoken?" - And "//audio[contains(@title, 'Listen to this greeting:')]/source[contains(@src, 'bonjour.mp3')]" "xpath_element" should exist - And "//*[contains(@class, 'answeroption')]//img[contains(@src, 'pluginfile.php')]" "xpath_element" should exist - And "//*[contains(@class, 'answeroption')]//img[contains(@src, 'flag-france.jpg')]" "xpath_element" should exist diff --git a/mod/lesson/tests/behat/import_questions.feature b/mod/lesson/tests/behat/import_questions.feature index db3b553bf5a..66a17c3e6de 100644 --- a/mod/lesson/tests/behat/import_questions.feature +++ b/mod/lesson/tests/behat/import_questions.feature @@ -1,5 +1,7 @@ -@mod @mod_lesson @_file_upload -Feature: Teacher can import questions into a lesson activity +@mod @mod_lesson +Feature: Import questions into a lesson from multiple formats + As a teacher + I want to import question files in different formats into a lesson so images and audio are preserved Background: Given the following "users" exist: @@ -12,35 +14,57 @@ Feature: Teacher can import questions into a lesson activity | user | course | role | | teacher1 | C1 | editingteacher | And the following "activities" exist: - | activity | name | course | - | lesson | Import lesson | C1 | + | activity | name | course | + | lesson | Test lesson name | C1 | - @javascript - Scenario: Teacher imports questions using Moodle XML (image is displayed) - Given I am on the "Import lesson" "lesson activity" page logged in as "teacher1" - And I follow "Import questions" - And I set the field "File format" to "Moodle XML" - When I upload "mod/lesson/tests/fixtures/multichoice.xml" file to "Upload" filemanager - And I press "Import" - And I press "Continue" - Then I should see "Lesson is currently being previewed." - And "//img[contains(@src, 'pluginfile.php')]" "xpath_element" should exist - And I press "Edit page contents" - And I set the field "Page contents" to "Edited page contents" - And I press "Save page" - And I should see "Edited page contents" - - @javascript - Scenario: Teacher imports questions using GIFT (images are not displayed) - Given I am on the "Import lesson" "lesson activity" page logged in as "teacher1" + @javascript @_file_upload + Scenario: Imports questions using GIFT format and edits page contents + Given I am on the "Test lesson name" "lesson activity" page logged in as "teacher1" And I follow "Import questions" And I set the field "File format" to "GIFT" - When I upload "mod/lesson/tests/fixtures/lesson_import_questions.gift" file to "Upload" filemanager + When I upload "mod/lesson/tests/fixtures/moodle_questions.gift" file to "Upload" filemanager And I press "Import" And I press "Continue" Then I should see "Lesson is currently being previewed." - And "//img[contains(@src, 'pluginfile.php')]" "xpath_element" should not exist + And I should see "Match the activity to the description." + And I should see "An activity supporting asynchronous discussions." + And I should see "A teacher asks a question and specifies a choice of multiple responses." And I press "Edit page contents" - And I set the field "Page contents" to "Edited page contents" + And I set the field "Page contents" to "Match the activity to the description (Edited)" And I press "Save page" - And I should see "Edited page contents" + And I should see "Match the activity to the description (Edited)" + + @javascript @_file_upload + Scenario: Import questions in XML format with images and audio in answers and responses + Given I am on the "Test lesson name" "lesson activity" page logged in as teacher1 + And I follow "Import questions" + And I set the field "File format" to "Moodle XML format" + When I upload "mod/lesson/tests/fixtures/multichoice.xml" file to "Upload" filemanager + And I press "Import" + Then I should see "Importing 1 questions" + And I should see " Listen to this greeting:" + And I should see "What language is being spoken?" + And I press "Continue" + And I should see "What language is being spoken?" + And "//audio[contains(@title, 'Listen to this greeting:')]/source[contains(@src, 'bonjour.mp3')]" "xpath_element" should exist + And "//*[contains(@class, 'answeroption')]//img[contains(@src, 'pluginfile.php')]" "xpath_element" should exist + And "//*[contains(@class, 'answeroption')]//img[contains(@src, 'flag-france.jpg')]" "xpath_element" should exist + + @javascript @_file_upload + Scenario: Import fill in the blank question in a lesson + Given I am on the "Test lesson name" "lesson activity" page logged in as teacher1 + And I follow "Import questions" + And I set the field "File format" to "Blackboard" + When I upload "mod/lesson/tests/fixtures/sample_blackboard_fib_qti.dat" file to "Upload" filemanager + And I press "Import" + Then I should see "Importing 1 questions" + And I should see "Name an amphibian: __________" + And I press "Continue" + And I should not see "__________" + And I should not see "Your answer" + And I set the field "id_answer" to "frog" + And I press "Submit" + And I should see "Your answer : frog" + And I should see "A frog is an amphibian" + And I press "Continue" + And I should see "Congratulations - end of lesson reached" diff --git a/mod/lesson/tests/fixtures/lesson_import_questions.gift b/mod/lesson/tests/fixtures/lesson_import_questions.gift deleted file mode 100644 index a45e2b3b043..00000000000 --- a/mod/lesson/tests/fixtures/lesson_import_questions.gift +++ /dev/null @@ -1,12 +0,0 @@ -::MC question:: -What is 2 + 2? -Example image -{ -=4 -~3 -} - -::Essay question:: -Describe something. -Example image -{} diff --git a/mod/lesson/tests/fixtures/moodle_questions.gift b/mod/lesson/tests/fixtures/moodle_questions.gift new file mode 100644 index 00000000000..675f34a9e96 --- /dev/null +++ b/mod/lesson/tests/fixtures/moodle_questions.gift @@ -0,0 +1,19 @@ +// question: 0 name: switch category to $course$/Default for New Features +$CATEGORY: $course$/Default for New Features + +// question: 44 name: Moodle activities +::Moodle activities::[html]Match the activity to the description.{ + =An activity supporting asynchronous discussions. -> Forum + =A teacher asks a question and specifies a choice of multiple responses. -> Choice + =A bank of record entries which participants can add to. -> Database + =A collection of web pages that anyone can add to or edit. -> Wiki + = -> Chat +} + +// question: 46 name: Moodle user +::Moodle user::[html]Anyone who uses Moodle is a ...{ + =%100%Moodler# +} + +// question: 45 name: Moodle acronym +::Moodle acronym::[html]Moodle is an acronym for Modular Object-Oriented Dynamic Learning Environment.{TRUE}