Línea 36... |
Línea 36... |
36 |
|
36 |
|
37 |
/**
|
37 |
/**
|
38 |
* @copyright 2008 The Open University
|
38 |
* @copyright 2008 The Open University
|
39 |
* @license http://www.gnu.org/copyleft/gpl.html GNU Public License
|
39 |
* @license http://www.gnu.org/copyleft/gpl.html GNU Public License
|
40 |
*/
|
40 |
*/
|
41 |
class lib_test extends \advanced_testcase {
|
41 |
final class lib_test extends \advanced_testcase {
|
Línea 42... |
Línea 42... |
42 |
use \quiz_question_helper_test_trait;
|
42 |
use \quiz_question_helper_test_trait;
|
43 |
|
43 |
|
44 |
public function test_quiz_has_grades(): void {
|
44 |
public function test_quiz_has_grades(): void {
|
Línea 137... |
Línea 137... |
137 |
// Check that any question references linked to this quiz are gone.
|
137 |
// Check that any question references linked to this quiz are gone.
|
138 |
$this->assertEquals(0, $DB->count_records('question_references', ['usingcontextid' => $context->id]));
|
138 |
$this->assertEquals(0, $DB->count_records('question_references', ['usingcontextid' => $context->id]));
|
139 |
$this->assertEquals(0, $DB->count_records('question_set_references', ['usingcontextid' => $context->id]));
|
139 |
$this->assertEquals(0, $DB->count_records('question_set_references', ['usingcontextid' => $context->id]));
|
140 |
}
|
140 |
}
|
Línea -... |
Línea 141... |
- |
|
141 |
|
- |
|
142 |
/**
|
- |
|
143 |
* Test deleting a quiz when the course is deleted.
|
- |
|
144 |
*
|
- |
|
145 |
* @covers ::quiz_delete_instance
|
- |
|
146 |
*/
|
- |
|
147 |
public function test_quiz_when_delete_course(): void {
|
- |
|
148 |
global $DB, $USER;
|
- |
|
149 |
|
- |
|
150 |
$this->resetAfterTest();
|
- |
|
151 |
$this->setAdminUser();
|
- |
|
152 |
|
- |
|
153 |
// Step 1: Create one course and a user with editing teacher capabilities.
|
- |
|
154 |
$generator = $this->getDataGenerator();
|
- |
|
155 |
$course = $generator->create_course();
|
- |
|
156 |
$teacher = $USER;
|
- |
|
157 |
$generator->enrol_user($teacher->id, $course->id, 'editingteacher');
|
- |
|
158 |
|
- |
|
159 |
// Create a quiz with questions in the first course.
|
- |
|
160 |
$quiz = $this->create_test_quiz($course);
|
- |
|
161 |
$context = \context_module::instance($quiz->cmid);
|
- |
|
162 |
// Create questions.
|
- |
|
163 |
$questiongenerator = $this->getDataGenerator()->get_plugin_generator('core_question');
|
- |
|
164 |
$cat = $questiongenerator->create_question_category(['contextid' => $context->id]);
|
- |
|
165 |
$saq = $questiongenerator->create_question('shortanswer', null, ['category' => $cat->id]);
|
- |
|
166 |
|
- |
|
167 |
// Add to the quiz.
|
- |
|
168 |
quiz_add_quiz_question($saq->id, $quiz);
|
- |
|
169 |
// Delete the course.
|
- |
|
170 |
delete_course($course, false);
|
- |
|
171 |
|
- |
|
172 |
// Check that the question was deleted.
|
- |
|
173 |
$this->assertFalse($DB->record_exists('question', ['id' => $saq->id]));
|
- |
|
174 |
// Check that all the slots were removed.
|
- |
|
175 |
$this->assertFalse($DB->record_exists('quiz_slots', ['quizid' => $quiz->id]));
|
- |
|
176 |
// Check that the quiz was removed.
|
- |
|
177 |
$this->assertFalse($DB->record_exists('quiz', ['id' => $quiz->id]));
|
- |
|
178 |
// Check that any question references linked to this quiz are gone.
|
- |
|
179 |
$this->assertFalse($DB->record_exists('question_references', ['usingcontextid' => $context->id]));
|
- |
|
180 |
$this->assertFalse($DB->record_exists('question_set_references', ['usingcontextid' => $context->id]));
|
- |
|
181 |
}
|
141 |
|
182 |
|
142 |
public function test_quiz_get_user_attempts(): void {
|
183 |
public function test_quiz_get_user_attempts(): void {
|
143 |
global $DB;
|
184 |
global $DB;
|
Línea 144... |
Línea 185... |
144 |
$this->resetAfterTest();
|
185 |
$this->resetAfterTest();
|
Línea 191... |
Línea 232... |
191 |
$attempt = quiz_create_attempt($quizobj1a, 1, false, $timenow, false, $u1->id);
|
232 |
$attempt = quiz_create_attempt($quizobj1a, 1, false, $timenow, false, $u1->id);
|
192 |
quiz_start_new_attempt($quizobj1a, $quba1a, $attempt, 1, $timenow);
|
233 |
quiz_start_new_attempt($quizobj1a, $quba1a, $attempt, 1, $timenow);
|
193 |
quiz_attempt_save_started($quizobj1a, $quba1a, $attempt);
|
234 |
quiz_attempt_save_started($quizobj1a, $quba1a, $attempt);
|
194 |
$attemptobj = quiz_attempt::create($attempt->id);
|
235 |
$attemptobj = quiz_attempt::create($attempt->id);
|
195 |
$attemptobj->process_submitted_actions($timenow, false, [1 => ['answer' => '3.14']]);
|
236 |
$attemptobj->process_submitted_actions($timenow, false, [1 => ['answer' => '3.14']]);
|
196 |
$attemptobj->process_finish($timenow, false);
|
237 |
$attemptobj->process_submit($timenow, false);
|
- |
|
238 |
$attemptobj->process_grade_submission($timenow);
|
Línea 197... |
Línea 239... |
197 |
|
239 |
|
198 |
// User 2 goes overdue in quiz 1.
|
240 |
// User 2 goes overdue in quiz 1.
|
199 |
$attempt = quiz_create_attempt($quizobj1b, 1, false, $timenow, false, $u2->id);
|
241 |
$attempt = quiz_create_attempt($quizobj1b, 1, false, $timenow, false, $u2->id);
|
200 |
quiz_start_new_attempt($quizobj1b, $quba1b, $attempt, 1, $timenow);
|
242 |
quiz_start_new_attempt($quizobj1b, $quba1b, $attempt, 1, $timenow);
|
Línea 229... |
Línea 271... |
229 |
|
271 |
|
230 |
$attempt = quiz_create_attempt($quizobj2a, 2, false, $timenow, false, $u1->id);
|
272 |
$attempt = quiz_create_attempt($quizobj2a, 2, false, $timenow, false, $u1->id);
|
231 |
quiz_start_new_attempt($quizobj2a, $quba2a, $attempt, 2, $timenow);
|
273 |
quiz_start_new_attempt($quizobj2a, $quba2a, $attempt, 2, $timenow);
|
232 |
quiz_attempt_save_started($quizobj2a, $quba2a, $attempt);
|
274 |
quiz_attempt_save_started($quizobj2a, $quba2a, $attempt);
|
233 |
$attemptobj = quiz_attempt::create($attempt->id);
|
275 |
$attemptobj = quiz_attempt::create($attempt->id);
|
- |
|
276 |
$attemptobj->process_submit($timenow, false);
|
Línea 234... |
Línea 277... |
234 |
$attemptobj->process_finish($timenow, false);
|
277 |
$attemptobj->process_grade_submission($timenow);
|
235 |
|
278 |
|
Línea 236... |
Línea 279... |
236 |
$quba2a = \question_engine::make_questions_usage_by_activity('mod_quiz', $quizobj2a->get_context());
|
279 |
$quba2a = \question_engine::make_questions_usage_by_activity('mod_quiz', $quizobj2a->get_context());
|
Línea 687... |
Línea 730... |
687 |
quiz_start_new_attempt($quizobj, $quba, $attempt, 1, $timenow);
|
730 |
quiz_start_new_attempt($quizobj, $quba, $attempt, 1, $timenow);
|
688 |
quiz_attempt_save_started($quizobj, $quba, $attempt);
|
731 |
quiz_attempt_save_started($quizobj, $quba, $attempt);
|
Línea 689... |
Línea 732... |
689 |
|
732 |
|
690 |
// Finish the attempt.
|
733 |
// Finish the attempt.
|
691 |
$attemptobj = quiz_attempt::create($attempt->id);
|
734 |
$attemptobj = quiz_attempt::create($attempt->id);
|
- |
|
735 |
$attemptobj->process_submit($timenow, false);
|
Línea 692... |
Línea 736... |
692 |
$attemptobj->process_finish($timenow, false);
|
736 |
$attemptobj->process_grade_submission($timenow);
|
693 |
|
737 |
|
Línea 694... |
Línea 738... |
694 |
// Create a calendar event.
|
738 |
// Create a calendar event.
|
Línea 742... |
Línea 786... |
742 |
quiz_start_new_attempt($quizobj, $quba, $attempt, 1, $timenow);
|
786 |
quiz_start_new_attempt($quizobj, $quba, $attempt, 1, $timenow);
|
743 |
quiz_attempt_save_started($quizobj, $quba, $attempt);
|
787 |
quiz_attempt_save_started($quizobj, $quba, $attempt);
|
Línea 744... |
Línea 788... |
744 |
|
788 |
|
745 |
// Finish the attempt.
|
789 |
// Finish the attempt.
|
746 |
$attemptobj = quiz_attempt::create($attempt->id);
|
790 |
$attemptobj = quiz_attempt::create($attempt->id);
|
- |
|
791 |
$attemptobj->process_submit($timenow, false);
|
Línea 747... |
Línea 792... |
747 |
$attemptobj->process_finish($timenow, false);
|
792 |
$attemptobj->process_grade_submission($timenow);
|
748 |
|
793 |
|
Línea 749... |
Línea 794... |
749 |
// Create a calendar event.
|
794 |
// Create a calendar event.
|
Línea 912... |
Línea 957... |
912 |
/**
|
957 |
/**
|
913 |
* Data provider for summarise_response() test cases.
|
958 |
* Data provider for summarise_response() test cases.
|
914 |
*
|
959 |
*
|
915 |
* @return array List of data sets (test cases)
|
960 |
* @return array List of data sets (test cases)
|
916 |
*/
|
961 |
*/
|
917 |
public function mod_quiz_inplace_editable_provider(): array {
|
962 |
public static function mod_quiz_inplace_editable_provider(): array {
|
918 |
return [
|
963 |
return [
|
919 |
'set to A1' => [1, 'A1'],
|
964 |
'set to A1' => [1, 'A1'],
|
920 |
'set with HTML characters' => [2, 'A & & <-:'],
|
965 |
'set with HTML characters' => [2, 'A & & <-:'],
|
921 |
'set to integer' => [3, '3'],
|
966 |
'set to integer' => [3, '3'],
|
922 |
'set to blank' => [4, ''],
|
967 |
'set to blank' => [4, ''],
|