Skip to content

Commit

Permalink
Merge pull request #17 from PhilippImhof/info-noattempts
Browse files Browse the repository at this point in the history
Display notification if there are no attempts to show
  • Loading branch information
lucaboesch authored Nov 11, 2023
2 parents e13a18e + a3224d2 commit 50f49ed
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 0 deletions.
4 changes: 4 additions & 0 deletions report.php
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,11 @@ public function display($quiz, $cm, $course) {
* Display all attempts.
*/
protected function display_archive() {
global $OUTPUT;
$studentattempts = $this->quizreportgetstudentandattempts($this->quizobj);
if (count($studentattempts) === 0) {
echo $OUTPUT->notification(get_string('noattemptstoshow', 'quiz'));
}
foreach ($studentattempts as $studentattempt) {
echo $this->quiz_report_get_student_attempt($studentattempt['attemptid'], $studentattempt['userid']);
}
Expand Down
51 changes: 51 additions & 0 deletions tests/behat/noattempts.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
@mod @mod_quiz @quiz @quiz_archive @javascript
Feature: Showing a message if there are no attempts to show
If there are no attempts to show
As a teacher
I need to see a notification

Background:
Given the following "users" exist:
| username | firstname | lastname | email | idnumber |
| teacher1 | T1 | Teacher1 | teacher1@example.com | T1000 |
| student1 | S1 | Student1 | student1@example.com | S1000 |
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 "question categories" exist:
| contextlevel | reference | name |
| Course | C1 | Test questions |
And the following "activities" exist:
| activity | name | intro | course | idnumber |
| quiz | Quiz 1 | Quiz 1 description | C1 | quiz1 |
And the following "questions" exist:
| questioncategory | qtype | name | questiontext |
| Test questions | truefalse | TF1 | First question |
And quiz "Quiz 1" contains the following questions:
| question | page | maxmark |
| TF1 | 1 | |

And I am on the "Quiz 1" "quiz_archive > Archive" page logged in as "teacher1"

Scenario: Check handling of no attempts situation
# Check if no attempt
Then I should see "There are no attempts to show"

# Add an attempt
And I log in as "student1"
And I am on "Course 1" course homepage
And I follow "Quiz 1"
And I press "Attempt quiz"
And I click on "True" "radio" in the "First question" "question"
And I press "Finish attempt ..."
And I press "Submit all and finish"
And I confirm the quiz submission in the modal dialog
And I log out
And I am on the "Quiz 1" "quiz_archive > Archive" page logged in as "teacher1"

# Check that the message is gone
Then I should not see "There are no attempts to show"

0 comments on commit 50f49ed

Please sign in to comment.