From 2f2c6408c96f1b66165f9dfde3c564dbc96be090 Mon Sep 17 00:00:00 2001 From: Angelia Dela Cruz Date: Wed, 10 Jan 2024 15:28:18 +0800 Subject: [PATCH 1/2] MDL-80479 mod_quiz: Behat to set quiz opening and closing time --- .../behat/quiz_activity_availability.feature | 136 ++++++++++++++++++ 1 file changed, 136 insertions(+) create mode 100644 mod/quiz/tests/behat/quiz_activity_availability.feature diff --git a/mod/quiz/tests/behat/quiz_activity_availability.feature b/mod/quiz/tests/behat/quiz_activity_availability.feature new file mode 100644 index 00000000000..20b1c3b8321 --- /dev/null +++ b/mod/quiz/tests/behat/quiz_activity_availability.feature @@ -0,0 +1,136 @@ +@mod @mod_quiz +Feature: Quiz availability can be set + In order to see quiz availability + As a teacher + I need to be able to set quiz opening and closing times + + Background: + Given the following "users" exist: + | username | firstname | lastname | email | + | teacher1 | Teacher | One | teacher1@example.com | + | student1 | Student | One | student1@example.com | + And the following "courses" exist: + | fullname | shortname | + | Course 1 | C1 | + And the following "course enrolments" exist: + | user | course | role | + | teacher1 | C1 | editingteacher | + | student1 | C1 | student | + And the following "question categories" exist: + | contextlevel | reference | name | + | Course | C1 | Test questions | + And the following "questions" exist: + | questioncategory | qtype | name | questiontext | + | Test questions | truefalse | TF1 | First question | + + Scenario Outline: Set quiz opening time while closing time is disabled + Given the following "activities" exist: + | activity | course | name | timeopen | + | quiz | C1 | Quiz 1 | | + And quiz "Quiz 1" contains the following questions: + | question | page | maxmark | + | TF1 | 1 | 2 | + When I am on the "Quiz 1" "quiz activity" page logged in as student1 + # Confirm display as student depending on case. + Then I should see ":" + And I should see "%A, %d %B %Y, %I:%M##" + And I should not see "Close:" + And I see "This quiz is currently not available." + And "Attempt quiz" "button" exist + + Examples: + | opentext | timeopen | attemptvisibility | quizavailability | + # Case 1 - open is set to future date, close is disabled. + | Opens | ##tomorrow## | should not | should | + # Case 4 - open is set to past date, close is disabled. + | Opened | ##yesterday## | should | should not | + + Scenario Outline: Set quiz closing time while opening time is disabled + Given the following "activities" exist: + | activity | course | name | timeclose | + | quiz | C1 | Quiz 1 | | + And quiz "Quiz 1" contains the following questions: + | question | page | maxmark | + | TF1 | 1 | 2 | + When I am on the "Quiz 1" "quiz activity" page logged in as student1 + # Confirm display as student depending on case. + Then I should see ":" + And I should see "%A, %d %B %Y, %I:%M##" + And I see "This quiz is currently not available." + And "Attempt quiz" "button" exist + + Examples: + | closetext | timeclose | attemptvisibility | quizavailability | + # Case 2 - open is disabled, close is set to past date. + | Closed | ##yesterday## | should not | should not | + # Case 5 - open is disabled, close is set to future date. + | Closes | ##tomorrow## | should | should not | + + Scenario Outline: Set quiz opening and closing times + Given the following "activities" exist: + | activity | course | name | timeopen | timeclose | + | quiz | C1 | Quiz 1 | | | + And quiz "Quiz 1" contains the following questions: + | question | page | maxmark | + | TF1 | 1 | 2 | + When I am on the "Quiz 1" "quiz activity" page logged in as student1 + # Confirm display as student depending on case. + Then I should see ":" + And I should see "%A, %d %B %Y, %I:%M##" + And I should see ":" + And I should see "%A, %d %B %Y, %I:%M##" + And I see "This quiz is currently not available." + And "Attempt quiz" "button" exist + + Examples: + | opentext | timeopen | closetext | timeclose | attemptvisibility | quizavailability | + # Case 6 - open and close are set to past date. + | Opened | ##3 days ago## | Closed | ##yesterday## | should not | should not | + # Case 7 - open is set to past date, close is set to future date. + | Opened | ##yesterday## | Closes | ##tomorrow## | should | should not | + # Case 8 - open and close are set to future date + | Opens | ##tomorrow## | Closes | ##+2 days## | should not | should | + + Scenario: Quiz time open and time close are disabled + # Case 3 - both open and close are disabled. + Given the following "activities" exist: + | activity | course | name | + | quiz | C1 | Quiz 1 | + And quiz "Quiz 1" contains the following questions: + | question | page | maxmark | + | TF1 | 1 | 2 | + When I am on the "Quiz 1" "quiz activity" page logged in as student1 + Then I should not see "Opens" + And I should not see "Opened" + And I should not see "Closes" + And I should not see "Closed" + And I should not see "This quiz is currently not available." + And "Attempt quiz" "button" should exist + + @javascript + Scenario Outline: Timer is displayed when quiz closes in less than an hour + Given the following "activities" exist: + | activity | course | name | + | quiz | C1 | Quiz 1 | + And quiz "Quiz 1" contains the following questions: + | question | page | + | TF1 | 1 | + Given I am on the "Quiz 1" "quiz activity editing" page logged in as teacher1 + And I set the following fields to these values: + | timeclose[enabled] | 1 | + | Close the quiz | | + And I press "Save and display" + When I press "Preview quiz" + # Confirm timer visibility for teacher + Then I see "Time left" + # Confirm timer visibility for student + And I am on the "Quiz 1" "quiz activity" page logged in as student1 + And I press "Attempt quiz" + And I see "Time left" + + Examples: + | closedate | timervisibility | + # Case 1 - closedate is < 1hr, the timer is visible + | ##now +10 minutes## | should | + # Case 2 - closedate is > 1hr, the timer is not visible + | ##now +2 hours## | should not | From cf5e25259d946ba45160ed08d5c6f0cbbf20e5a4 Mon Sep 17 00:00:00 2001 From: Simey Lameze Date: Thu, 14 Mar 2024 10:17:09 +0800 Subject: [PATCH 2/2] MDL-80479 behat: improve new test for quiz timer --- .../behat/quiz_activity_availability.feature | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) diff --git a/mod/quiz/tests/behat/quiz_activity_availability.feature b/mod/quiz/tests/behat/quiz_activity_availability.feature index 20b1c3b8321..bb07940006d 100644 --- a/mod/quiz/tests/behat/quiz_activity_availability.feature +++ b/mod/quiz/tests/behat/quiz_activity_availability.feature @@ -42,7 +42,7 @@ Feature: Quiz availability can be set | opentext | timeopen | attemptvisibility | quizavailability | # Case 1 - open is set to future date, close is disabled. | Opens | ##tomorrow## | should not | should | - # Case 4 - open is set to past date, close is disabled. + # Case 4 - open is set to past date, close is disabled. | Opened | ##yesterday## | should | should not | Scenario Outline: Set quiz closing time while opening time is disabled @@ -110,22 +110,18 @@ Feature: Quiz availability can be set @javascript Scenario Outline: Timer is displayed when quiz closes in less than an hour Given the following "activities" exist: - | activity | course | name | - | quiz | C1 | Quiz 1 | + | activity | course | name | timeclose | + | quiz | C1 | Quiz 1 | | And quiz "Quiz 1" contains the following questions: | question | page | | TF1 | 1 | - Given I am on the "Quiz 1" "quiz activity editing" page logged in as teacher1 - And I set the following fields to these values: - | timeclose[enabled] | 1 | - | Close the quiz | | - And I press "Save and display" + And I am on the "Quiz 1" "quiz activity" page logged in as "teacher1" When I press "Preview quiz" # Confirm timer visibility for teacher Then I see "Time left" - # Confirm timer visibility for student - And I am on the "Quiz 1" "quiz activity" page logged in as student1 + And I am on the "Quiz 1" "quiz activity" page logged in as "student1" And I press "Attempt quiz" + # Confirm timer visibility for student And I see "Time left" Examples: