Merge branch 'MDL-63263-Master' of https://github.com/tuanngocnguyen/moodle
This commit is contained in:
@@ -337,6 +337,10 @@ if ($hassiteconfig or has_any_capability($capabilities, $systemcontext)) {
|
||||
|
||||
// Automated defaults section.
|
||||
$temp->add(new admin_setting_heading('automatedsettings', new lang_string('automatedsettings','backup'), ''));
|
||||
$temp->add(new admin_setting_description('recyclebin',
|
||||
new lang_string('recyclebin', 'backup'),
|
||||
new lang_string('recyclebin_desc', 'backup')
|
||||
));
|
||||
$temp->add(new admin_setting_configcheckbox('backup/backup_auto_users', new lang_string('generalusers', 'backup'), new lang_string('configgeneralusers', 'backup'), 1));
|
||||
$temp->add(new admin_setting_configcheckbox('backup/backup_auto_role_assignments', new lang_string('generalroleassignments','backup'), new lang_string('configgeneralroleassignments','backup'), 1));
|
||||
$temp->add(new admin_setting_configcheckbox('backup/backup_auto_activities', new lang_string('generalactivities','backup'), new lang_string('configgeneralactivities','backup'), 1));
|
||||
|
||||
@@ -119,7 +119,7 @@ class course_bin extends base_bin {
|
||||
$cm->id,
|
||||
\backup::FORMAT_MOODLE,
|
||||
\backup::INTERACTIVE_NO,
|
||||
\backup::MODE_GENERAL,
|
||||
\backup::MODE_AUTOMATED,
|
||||
$user->id
|
||||
);
|
||||
$controller->execute_plan();
|
||||
@@ -224,7 +224,7 @@ class course_bin extends base_bin {
|
||||
$tempdir,
|
||||
$this->_courseid,
|
||||
\backup::INTERACTIVE_NO,
|
||||
\backup::MODE_GENERAL,
|
||||
\backup::MODE_AUTOMATED,
|
||||
$user->id,
|
||||
\backup::TARGET_EXISTING_ADDING
|
||||
);
|
||||
@@ -344,4 +344,4 @@ class course_bin extends base_bin {
|
||||
$context = \context_course::instance($this->_courseid);
|
||||
return has_capability('tool/recyclebin:deleteitems', $context);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -55,7 +55,7 @@ class tool_recyclebin_course_bin_tests extends advanced_testcase {
|
||||
|
||||
$this->course = $this->getDataGenerator()->create_course();
|
||||
$this->quiz = $this->getDataGenerator()->get_plugin_generator('mod_quiz')->create_instance(array(
|
||||
'course' => $this->course->id
|
||||
'course' => $this->course->id, 'grade' => 100.0, 'sumgrades' => 1
|
||||
));
|
||||
}
|
||||
|
||||
@@ -173,4 +173,99 @@ class tool_recyclebin_course_bin_tests extends advanced_testcase {
|
||||
$deletedbook = reset($items);
|
||||
$this->assertEquals($book->name, $deletedbook->name);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests that user data is restored when module is restored.
|
||||
*/
|
||||
public function test_coursemodule_restore_with_userdata() {
|
||||
$student = $this->getDataGenerator()->create_and_enrol($this->course, 'student');
|
||||
$this->setUser($student);
|
||||
|
||||
set_config('backup_auto_users', true, 'backup');
|
||||
$this->create_quiz_attempt($this->quiz, $student);
|
||||
|
||||
// Delete quiz.
|
||||
$cm = get_coursemodule_from_instance('quiz', $this->quiz->id);
|
||||
course_delete_module($cm->id);
|
||||
phpunit_util::run_all_adhoc_tasks();
|
||||
$quizzes = get_coursemodules_in_course('quiz', $this->course->id);
|
||||
$this->assertEquals(0, count($quizzes));
|
||||
|
||||
// Restore quiz.
|
||||
$recyclebin = new \tool_recyclebin\course_bin($this->course->id);
|
||||
foreach ($recyclebin->get_items() as $item) {
|
||||
$recyclebin->restore_item($item);
|
||||
}
|
||||
$quizzes = get_coursemodules_in_course('quiz', $this->course->id);
|
||||
$this->assertEquals(1, count($quizzes));
|
||||
$cm = array_pop($quizzes);
|
||||
|
||||
// Check if user quiz attempt data is restored.
|
||||
$attempts = quiz_get_user_attempts($cm->instance, $student->id);
|
||||
$this->assertEquals(1, count($attempts));
|
||||
$attempt = array_pop($attempts);
|
||||
$attemptobj = quiz_attempt::create($attempt->id);
|
||||
$this->assertEquals($student->id, $attemptobj->get_userid());
|
||||
$this->assertEquals(true, $attemptobj->is_finished());
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests that user data is not restored when module is restored.
|
||||
*/
|
||||
public function test_coursemodule_restore_without_userdata() {
|
||||
$student = $this->getDataGenerator()->create_and_enrol($this->course, 'student');
|
||||
$this->setUser($student);
|
||||
|
||||
set_config('backup_auto_users', false, 'backup');
|
||||
$this->create_quiz_attempt($this->quiz, $student);
|
||||
|
||||
// Delete quiz.
|
||||
$cm = get_coursemodule_from_instance('quiz', $this->quiz->id);
|
||||
course_delete_module($cm->id);
|
||||
phpunit_util::run_all_adhoc_tasks();
|
||||
$quizzes = get_coursemodules_in_course('quiz', $this->course->id);
|
||||
$this->assertEquals(0, count($quizzes));
|
||||
|
||||
// Restore quiz.
|
||||
$recyclebin = new \tool_recyclebin\course_bin($this->course->id);
|
||||
foreach ($recyclebin->get_items() as $item) {
|
||||
$recyclebin->restore_item($item);
|
||||
}
|
||||
$quizzes = get_coursemodules_in_course('quiz', $this->course->id);
|
||||
$this->assertEquals(1, count($quizzes));
|
||||
$cm = array_pop($quizzes);
|
||||
|
||||
// Check if user quiz attempt data is restored.
|
||||
$attempts = quiz_get_user_attempts($cm->instance, $student->id);
|
||||
$this->assertEquals(0, count($attempts));
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a question to quiz and create a quiz attempt.
|
||||
* @param \stdClass $quiz Quiz
|
||||
* @param \stdClass $student User
|
||||
* @throws coding_exception
|
||||
* @throws moodle_exception
|
||||
*/
|
||||
private function create_quiz_attempt($quiz, $student) {
|
||||
// Add Question.
|
||||
$questiongenerator = $this->getDataGenerator()->get_plugin_generator('core_question');
|
||||
$cat = $questiongenerator->create_question_category();
|
||||
$numq = $questiongenerator->create_question('numerical', null, array('category' => $cat->id));
|
||||
quiz_add_quiz_question($numq->id, $quiz);
|
||||
|
||||
// Create quiz attempt.
|
||||
$quizobj = quiz::create($quiz->id, $student->id);
|
||||
$quba = question_engine::make_questions_usage_by_activity('mod_quiz', $quizobj->get_context());
|
||||
$quba->set_preferred_behaviour($quizobj->get_quiz()->preferredbehaviour);
|
||||
$timenow = time();
|
||||
$attempt = quiz_create_attempt($quizobj, 1, false, $timenow, false, $student->id);
|
||||
quiz_start_new_attempt($quizobj, $quba, $attempt, 1, $timenow);
|
||||
quiz_attempt_save_started($quizobj, $quba, $attempt);
|
||||
$attemptobj = quiz_attempt::create($attempt->id);
|
||||
$tosubmit = array(1 => array('answer' => '0'));
|
||||
$attemptobj->process_submitted_actions($timenow, false, $tosubmit);
|
||||
$attemptobj = quiz_attempt::create($attempt->id);
|
||||
$attemptobj->process_finish($timenow, false);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -332,3 +332,5 @@ $string['unnamedsection'] = 'Unnamed section';
|
||||
$string['userinfo'] = 'Userinfo';
|
||||
$string['module'] = 'Module';
|
||||
$string['morecoursesearchresults'] = 'More than {$a} courses found, showing first {$a} results';
|
||||
$string['recyclebin'] = 'Recycle bin';
|
||||
$string['recyclebin_desc'] = 'These settings will be also applied to recycle bin';
|
||||
|
||||
Reference in New Issue
Block a user