mirror of
https://github.com/moodle/moodle.git
synced 2025-04-11 11:23:52 +02:00
Merge branch 'MDL-78749-master' of https://github.com/BruceGoodGuy/moodle
This commit is contained in:
commit
d52ea4c037
mod/quiz
@ -1103,6 +1103,8 @@ class renderer extends plugin_renderer_base {
|
||||
// Prepare table header.
|
||||
$table = new html_table();
|
||||
$table->attributes['class'] = 'generaltable quizattemptsummary';
|
||||
$table->caption = get_string('summaryofattempts', 'quiz');
|
||||
$table->captionhide = true;
|
||||
$table->head = [];
|
||||
$table->align = [];
|
||||
$table->size = [];
|
||||
|
@ -17,6 +17,7 @@
|
||||
namespace mod_quiz;
|
||||
|
||||
use core_question\local\bank\question_version_status;
|
||||
use mod_quiz\output\view_page;
|
||||
use question_engine;
|
||||
|
||||
defined('MOODLE_INTERNAL') || die();
|
||||
@ -506,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_context();
|
||||
|
||||
// Prepare view object.
|
||||
$viewobj = new view_page();
|
||||
$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 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);
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user