Proyectos de Subversion Moodle

Rev

Rev 11 | Mostrar el archivo completo | | | Autoría | Ultima modificación | Ver Log |

Rev 11 Rev 1441
Línea 24... Línea 24...
24
 *
24
 *
25
 * @package    tool_recyclebin
25
 * @package    tool_recyclebin
26
 * @copyright  2015 University of Kent
26
 * @copyright  2015 University of Kent
27
 * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
27
 * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
28
 */
28
 */
29
class course_bin_test extends \advanced_testcase {
29
final class course_bin_test extends \advanced_testcase {
Línea 30... Línea 30...
30
 
30
 
31
    /**
31
    /**
32
     * @var \stdClass $course
32
     * @var \stdClass $course
33
     */
33
     */
Línea 40... Línea 40...
40
 
40
 
41
    /**
41
    /**
42
     * Setup for each test.
42
     * Setup for each test.
43
     */
43
     */
-
 
44
    protected function setUp(): void {
44
    protected function setUp(): void {
45
        parent::setUp();
45
        $this->resetAfterTest(true);
46
        $this->resetAfterTest(true);
Línea 46... Línea 47...
46
        $this->setAdminUser();
47
        $this->setAdminUser();
47
 
48
 
Línea 64... Línea 65...
64
        $this->assertEquals(0, $DB->count_records('tool_recyclebin_course'));
65
        $this->assertEquals(0, $DB->count_records('tool_recyclebin_course'));
Línea 65... Línea 66...
65
 
66
 
66
        // Delete the course module.
67
        // Delete the course module.
Línea 67... Línea -...
67
        course_delete_module($this->quiz->cmid);
-
 
68
 
-
 
69
        // Now, run the course module deletion adhoc task.
-
 
70
        \phpunit_util::run_all_adhoc_tasks();
68
        course_delete_module($this->quiz->cmid);
71
 
69
 
Línea 72... Línea 70...
72
        // Check the course module is now in the recycle bin.
70
        // Check the course module is now in the recycle bin.
73
        $this->assertEquals(1, $DB->count_records('tool_recyclebin_course'));
71
        $this->assertEquals(1, $DB->count_records('tool_recyclebin_course'));
Línea 108... Línea 106...
108
        $startcount = $DB->count_records('course_modules');
106
        $startcount = $DB->count_records('course_modules');
Línea 109... Línea 107...
109
 
107
 
110
        // Delete the course module.
108
        // Delete the course module.
Línea 111... Línea -...
111
        course_delete_module($this->quiz->cmid);
-
 
112
 
-
 
113
        // Now, run the course module deletion adhoc task.
-
 
114
        \phpunit_util::run_all_adhoc_tasks();
109
        course_delete_module($this->quiz->cmid);
115
 
110
 
116
        // Try purging.
111
        // Try purging.
117
        $recyclebin = new \tool_recyclebin\course_bin($this->course->id);
112
        $recyclebin = new \tool_recyclebin\course_bin($this->course->id);
118
        foreach ($recyclebin->get_items() as $item) {
113
        foreach ($recyclebin->get_items() as $item) {
Línea 133... Línea 128...
133
        set_config('coursebinexpiry', WEEKSECS, 'tool_recyclebin');
128
        set_config('coursebinexpiry', WEEKSECS, 'tool_recyclebin');
Línea 134... Línea 129...
134
 
129
 
135
        // Delete the quiz.
130
        // Delete the quiz.
Línea 136... Línea -...
136
        course_delete_module($this->quiz->cmid);
-
 
137
 
-
 
138
        // Now, run the course module deletion adhoc task.
-
 
139
        \phpunit_util::run_all_adhoc_tasks();
131
        course_delete_module($this->quiz->cmid);
140
 
132
 
141
        // Set deleted date to the distant past.
133
        // Set deleted date to the distant past.
142
        $recyclebin = new \tool_recyclebin\course_bin($this->course->id);
134
        $recyclebin = new \tool_recyclebin\course_bin($this->course->id);
143
        foreach ($recyclebin->get_items() as $item) {
135
        foreach ($recyclebin->get_items() as $item) {
Línea 149... Línea 141...
149
        $book = $this->getDataGenerator()->get_plugin_generator('mod_book')->create_instance(array(
141
        $book = $this->getDataGenerator()->get_plugin_generator('mod_book')->create_instance(array(
150
            'course' => $this->course->id));
142
            'course' => $this->course->id));
Línea 151... Línea 143...
151
 
143
 
Línea 152... Línea -...
152
        course_delete_module($book->cmid);
-
 
153
 
-
 
154
        // Now, run the course module deletion adhoc task.
-
 
155
        \phpunit_util::run_all_adhoc_tasks();
144
        course_delete_module($book->cmid);
156
 
145
 
Línea 157... Línea 146...
157
        // Should have 2 items now.
146
        // Should have 2 items now.
158
        $this->assertEquals(2, count($recyclebin->get_items()));
147
        $this->assertEquals(2, count($recyclebin->get_items()));
Línea 173... Línea 162...
173
     * Provider for test_coursemodule_restore_with_userdata() and test_coursemodule_restore_without_userdata()
162
     * Provider for test_coursemodule_restore_with_userdata() and test_coursemodule_restore_without_userdata()
174
     *
163
     *
175
     * Used to verify that recycle bin is immune to various settings. Provides plugin, name, value for
164
     * Used to verify that recycle bin is immune to various settings. Provides plugin, name, value for
176
     * direct usage with set_config()
165
     * direct usage with set_config()
177
     */
166
     */
178
    public function recycle_bin_settings_provider() {
167
    public static function recycle_bin_settings_provider(): array {
179
        return [
168
        return [
180
            'backup/backup_auto_storage moodle' => [[
169
            'backup/backup_auto_storage moodle' => [[
181
                (object)['plugin' => 'backup', 'name' => 'backup_auto_storage', 'value' => 0],
170
                (object)['plugin' => 'backup', 'name' => 'backup_auto_storage', 'value' => 0],
182
            ]],
171
            ]],
Línea 221... Línea 210...
221
        $this->create_quiz_attempt($this->quiz, $student);
210
        $this->create_quiz_attempt($this->quiz, $student);
Línea 222... Línea 211...
222
 
211
 
223
        // Delete quiz.
212
        // Delete quiz.
224
        $cm = get_coursemodule_from_instance('quiz', $this->quiz->id);
213
        $cm = get_coursemodule_from_instance('quiz', $this->quiz->id);
225
        course_delete_module($cm->id);
-
 
226
        \phpunit_util::run_all_adhoc_tasks();
214
        course_delete_module($cm->id);
227
        $quizzes = get_coursemodules_in_course('quiz', $this->course->id);
215
        $quizzes = get_coursemodules_in_course('quiz', $this->course->id);
Línea 228... Línea 216...
228
        $this->assertEquals(0, count($quizzes));
216
        $this->assertEquals(0, count($quizzes));
229
 
217
 
Línea 258... Línea 246...
258
        set_config('backup_auto_activities', false, 'backup');
246
        set_config('backup_auto_activities', false, 'backup');
Línea 259... Línea 247...
259
 
247
 
260
        // Delete the course module.
248
        // Delete the course module.
Línea 261... Línea -...
261
        course_delete_module($this->quiz->cmid);
-
 
262
 
-
 
263
        // Now, run the course module deletion adhoc task.
-
 
264
        \phpunit_util::run_all_adhoc_tasks();
249
        course_delete_module($this->quiz->cmid);
265
 
250
 
266
        // Check there is no items in the recycle bin.
251
        // Check there is no items in the recycle bin.
267
        $recyclebin = new \tool_recyclebin\course_bin($this->course->id);
252
        $recyclebin = new \tool_recyclebin\course_bin($this->course->id);
Línea 291... Línea 276...
291
        $this->create_quiz_attempt($this->quiz, $student);
276
        $this->create_quiz_attempt($this->quiz, $student);
Línea 292... Línea 277...
292
 
277
 
293
        // Delete quiz.
278
        // Delete quiz.
294
        $cm = get_coursemodule_from_instance('quiz', $this->quiz->id);
279
        $cm = get_coursemodule_from_instance('quiz', $this->quiz->id);
295
        course_delete_module($cm->id);
-
 
296
        \phpunit_util::run_all_adhoc_tasks();
280
        course_delete_module($cm->id);
297
        $quizzes = get_coursemodules_in_course('quiz', $this->course->id);
281
        $quizzes = get_coursemodules_in_course('quiz', $this->course->id);
Línea 298... Línea 282...
298
        $this->assertEquals(0, count($quizzes));
282
        $this->assertEquals(0, count($quizzes));
299
 
283
 
Línea 335... Línea 319...
335
        quiz_attempt_save_started($quizobj, $quba, $attempt);
319
        quiz_attempt_save_started($quizobj, $quba, $attempt);
336
        $attemptobj = quiz_attempt::create($attempt->id);
320
        $attemptobj = quiz_attempt::create($attempt->id);
337
        $tosubmit = array(1 => array('answer' => '0'));
321
        $tosubmit = array(1 => array('answer' => '0'));
338
        $attemptobj->process_submitted_actions($timenow, false, $tosubmit);
322
        $attemptobj->process_submitted_actions($timenow, false, $tosubmit);
339
        $attemptobj = quiz_attempt::create($attempt->id);
323
        $attemptobj = quiz_attempt::create($attempt->id);
340
        $attemptobj->process_finish($timenow, false);
324
        $attemptobj->process_submit($timenow, false);
-
 
325
        $attemptobj->process_grade_submission($timenow);
341
    }
326
    }
342
}
327
}