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 gradepenalty_duedate\tests;
18
 
19
use advanced_testcase;
20
use context_system;
21
 
22
/**
23
 * Base test.
24
 *
25
 * @package   gradepenalty_duedate
26
 * @copyright 2024 Catalyst IT Australia Pty Ltd
27
 * @license   http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
28
 */
29
abstract class penalty_testcase extends advanced_testcase {
30
    /**
31
     * Reset after test.
32
     *
33
     * @return void
34
     */
35
    public function setUp(): void {
36
        parent::setUp();
37
        $this->resetAfterTest();
38
    }
39
 
40
    /**
41
     * Create sample rules.
42
     *
43
     * @param int|null $contextid The context id.
44
     */
45
    public function create_sample_rules(?int $contextid = null): void {
46
        global $DB;
47
 
48
        // Use system context by default.
49
        $contextid ??= context_system::instance()->id;
50
 
51
        // Remove initial rule.
52
        $DB->delete_records('gradepenalty_duedate_rule', ['contextid' => $contextid]);
53
 
54
        $rules = [
55
            ['contextid' => $contextid, 'overdueby' => DAYSECS, 'penalty' => 10, 'sortorder' => 0],
56
            ['contextid' => $contextid, 'overdueby' => DAYSECS * 2, 'penalty' => 20, 'sortorder' => 1],
57
            ['contextid' => $contextid, 'overdueby' => DAYSECS * 3, 'penalty' => 30, 'sortorder' => 2],
58
            ['contextid' => $contextid, 'overdueby' => DAYSECS * 4, 'penalty' => 40, 'sortorder' => 3],
59
            ['contextid' => $contextid, 'overdueby' => DAYSECS * 5, 'penalty' => 50, 'sortorder' => 4],
60
        ];
61
        foreach ($rules as $rule) {
62
            $DB->insert_record('gradepenalty_duedate_rule', (object)$rule);
63
        }
64
    }
65
}