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