Proyectos de Subversion Moodle

Rev

| Ultima modificación | Ver Log |

Rev Autor Línea Nro. Línea
1441 ariadna 1
<?php
2
// This file is part of Moodle - http://moodle.org/
3
//
4
// Moodle is free software: you can redistribute it and/or modify
5
// it under the terms of the GNU General Public License as published by
6
// the Free Software Foundation, either version 3 of the License, or
7
// (at your option) any later version.
8
//
9
// Moodle is distributed in the hope that it will be useful,
10
// but WITHOUT ANY WARRANTY; without even the implied warranty of
11
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12
// GNU General Public License for more details.
13
//
14
// You should have received a copy of the GNU General Public License
15
// along with Moodle.  If not, see <http://www.gnu.org/licenses/>.
16
 
17
namespace mod_assign\tests;
18
 
19
/**
20
 * TODO describe file provider_testcase
21
 *
22
 * @package    mod_assign
23
 * @copyright  2024 Andrew Lyons <andrew@nicols.co.uk>
24
 * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
25
 */
26
abstract class provider_testcase extends \core_privacy\tests\provider_testcase {
27
    #[\Override]
28
    public static function setUpBeforeClass(): void {
29
        global $CFG;
30
 
31
        parent::setUpBeforeClass();
32
 
33
        require_once($CFG->dirroot . '/mod/assign/locallib.php');
34
    }
35
 
36
    /**
37
     * Convenience method for creating a submission.
38
     *
39
     * @param  assign  $assign The assign object
40
     * @param  stdClass  $user The user object
41
     * @param  string  $submissiontext Submission text
42
     * @param  integer $attemptnumber The attempt number
43
     * @return object A submission object.
44
     */
45
    protected function create_submission($assign, $user, $submissiontext, $attemptnumber = 0) {
46
        $submission = $assign->get_user_submission($user->id, true, $attemptnumber);
47
        $submission->onlinetext_editor = ['text' => $submissiontext,
48
                                         'format' => FORMAT_MOODLE];
49
 
50
        $this->setUser($user);
51
        $notices = [];
52
        $assign->save_submission($submission, $notices);
53
        return $submission;
54
    }
55
 
56
    /**
57
     * Convenience function to create an instance of an assignment.
58
     *
59
     * @param array $params Array of parameters to pass to the generator
60
     * @return assign The assign class.
61
     */
62
    protected function create_instance($params = array()) {
63
        $generator = $this->getDataGenerator()->get_plugin_generator('mod_assign');
64
        $instance = $generator->create_instance($params);
65
        $cm = get_coursemodule_from_instance('assign', $instance->id);
66
        $context = \context_module::instance($cm->id);
67
        return new \assign($context, $cm, $params['course']);
68
    }
69
}