MDL-78749 Accessibility\Quiz: Previous attempt table caption missing

This commit is contained in:
Khoa Nguyen Dang 2023-07-19 18:41:36 +07:00
parent 272fdb321a
commit 1408e3b964
2 changed files with 54 additions and 0 deletions

View File

@ -1082,6 +1082,8 @@ class mod_quiz_renderer extends plugin_renderer_base {
$table->head = array();
$table->align = array();
$table->size = array();
$table->caption = get_string('summaryofattempts', 'quiz');
$table->captionhide = true;
if ($viewobj->attemptcolumn) {
$table->head[] = get_string('attemptnumber', 'quiz');
$table->align[] = 'center';

View File

@ -507,4 +507,56 @@ class attempt_test extends \advanced_testcase {
$this->expectExceptionObject(new \moodle_exception('questiondraftonly', 'mod_quiz', '', $question->name));
quiz_start_attempt_built_on_last($quba, $newattempt, $attempt);
}
/**
* Starting a new attempt and check the summary previous attempts table.
*
* @covers ::view_table()
*/
public function test_view_table(): void {
global $PAGE;
$this->resetAfterTest();
$timenow = time();
// Create attempt object.
$attempt = $this->create_quiz_and_attempt_with_layout('1,1,0');
// Finish attempt.
$attempt->process_finish($timenow, false);
$quiz = $attempt->get_quiz();
$context = $attempt->get_quizobj()->get_context();
// Prepare view object.
$viewobj = new \mod_quiz_view_object();
$viewobj->attemptcolumn = true;
$viewobj->markcolumn = true;
$viewobj->gradecolumn = true;
$viewobj->canreviewmine = true;
$viewobj->mygrade = 0.00;
$viewobj->feedbackcolumn = false;
$viewobj->attempts = $attempt;
$viewobj->attemptobjs[] = new quiz_attempt($attempt->get_attempt(),
$quiz, $attempt->get_cm(), $attempt->get_course(), false);
$viewobj->accessmanager = new \quiz_access_manager($attempt->get_quizobj(), $timenow,
has_capability('mod/quiz:ignoretimelimits', $context, null, false));
// Render summary previous attempts table.
$renderer = $PAGE->get_renderer('mod_quiz');
$table = $renderer->view_table($quiz, $context, $viewobj);
$captionpattern = '/<caption\b[^>]*>' . get_string('summaryofattempts', 'quiz') . '<\/caption>/';
// Check caption existed.
$this->assertMatchesRegularExpression($captionpattern, $table);
// Check column attempt.
$this->assertMatchesRegularExpression('/<td\b[^>]*>' . $attempt->get_attempt_number() . '<\/td>/', $table);
// Check column state.
$this->assertMatchesRegularExpression('/<td\b[^>]*>' . ucfirst($attempt->get_state()) . '.+?<\/td>/', $table);
// Check column marks.
$this->assertMatchesRegularExpression('/<td\b[^>]* c2.+?' .
quiz_format_grade($quiz, $attempt->get_sum_marks()) .'<\/td>/', $table);
// Check column grades.
$this->assertMatchesRegularExpression('/<td\b[^>]* c2.+?0\.00<\/td>/', $table);
// Check column review.
$this->assertMatchesRegularExpression('/<td\b[^>]*>.+?Review<\/a><\/td>/', $table);
}
}