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 core\task;
18
 
19
use core\output\stored_progress_bar;
20
 
21
/**
22
 * Unit tests for stored_progress_bar_cleanup
23
 *
24
 * @package   core
25
 * @copyright 2024 onwards Catalyst IT EU {@link https://catalyst-eu.net}
26
 * @author    Mark Johnson <mark.johnson@catalyst-eu.net>
27
 * @license   http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
28
 * @covers    \core\task\stored_progress_bar_cleanup_task
29
 */
30
final class stored_progress_bar_cleanup_task_test extends \advanced_testcase {
31
    /**
32
     * Clean up stored_progress records that were last updated over 24 hours ago.
33
     */
34
    public function test_execute(): void {
35
        $this->resetAfterTest();
36
        $generator = $this->getDataGenerator();
37
        $neverupdated = $generator->create_stored_progress();
38
        $updatednow = $generator->create_stored_progress(lastupdate: time());
39
        $updated23hours = $generator->create_stored_progress(lastupdate: time() - (HOURSECS * 23));
40
        $updated24hours = $generator->create_stored_progress(lastupdate: time() - DAYSECS - 1);
41
 
42
        $task = new stored_progress_bar_cleanup_task();
43
        $this->expectOutputRegex('/Deleted old stored_progress records/');
44
        $task->execute();
45
 
46
        $this->assertNotNull(stored_progress_bar::get_by_id($neverupdated->id));
47
        $this->assertNotNull(stored_progress_bar::get_by_id($updatednow->id));
48
        $this->assertNotNull(stored_progress_bar::get_by_id($updated23hours->id));
49
        $this->assertNull(stored_progress_bar::get_by_id($updated24hours->id));
50
    }
51
}