Proyectos de Subversion Moodle

Rev

Rev 1 | | Comparar con el anterior | Ultima modificación | Ver Log |

Rev Autor Línea Nro. Línea
1 efrain 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 tool_messageinbound;
18
 
19
use core_privacy\tests\provider_testcase;
20
use core_privacy\local\request\approved_contextlist;
21
use core_privacy\local\request\transform;
22
use core_privacy\local\request\writer;
23
use tool_messageinbound\privacy\provider;
24
 
25
/**
26
 * Manager testcase class.
27
 *
28
 * @package    tool_messageinbound
29
 * @category   test
30
 * @copyright  2018 Frédéric Massart
31
 * @author     Frédéric Massart <fred@branchup.tech>
32
 * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
33
 */
34
class manager_test extends provider_testcase {
35
 
36
    public function setUp(): void {
37
        global $CFG;
38
        $this->resetAfterTest();
39
 
40
        // Pretend the system is enabled.
41
        $CFG->messageinbound_enabled = true;
42
        $CFG->messageinbound_mailbox = 'mailbox';
43
        $CFG->messageinbound_domain = 'example.com';
44
    }
45
 
11 efrain 46
    public function test_tidy_old_verification_failures(): void {
1 efrain 47
        global $DB;
48
 
49
        $now = time();
50
        $stale = $now - DAYSECS - 1;    // Make a second older because PHP Unit is too damn fast!!
51
 
52
        $this->create_messagelist(['timecreated' => $now]);
53
        $this->create_messagelist(['timecreated' => $now - HOURSECS]);
54
        $this->create_messagelist(['timecreated' => $stale]);
55
        $this->create_messagelist(['timecreated' => $stale - HOURSECS]);
56
        $this->create_messagelist(['timecreated' => $stale - YEARSECS]);
57
 
58
        $this->assertEquals(5, $DB->count_records('messageinbound_messagelist', []));
59
        $this->assertEquals(3, $DB->count_records_select('messageinbound_messagelist', 'timecreated < :t', ['t' => $stale + 1]));
60
 
61
        $manager = new \tool_messageinbound\manager();
62
        $manager->tidy_old_verification_failures();
63
 
64
        $this->assertEquals(2, $DB->count_records('messageinbound_messagelist', []));
65
        $this->assertEquals(0, $DB->count_records_select('messageinbound_messagelist', 'timecreated < :t', ['t' => $stale + 1]));
66
    }
67
 
68
    /**
69
     * Create a message to validate.
70
     *
71
     * @param array $params The params.
72
     * @return stdClass
73
     */
74
    protected function create_messagelist(array $params) {
75
        global $DB, $USER;
76
        $record = (object) array_merge([
77
            'messageid' => 'abc',
78
            'userid' => $USER->id,
79
            'address' => 'text@example.com',
80
            'timecreated' => time(),
81
        ], $params);
82
        $record->id = $DB->insert_record('messageinbound_messagelist', $record);
83
        return $record;
84
    }
85
 
86
}