Proyectos de Subversion Moodle

Rev

Rev 11 | Mostrar el archivo completo | | | Autoría | Ultima modificación | Ver Log |

Rev 11 Rev 1441
Línea 14... Línea 14...
14
// You should have received a copy of the GNU General Public License
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/>.
15
// along with Moodle.  If not, see <http://www.gnu.org/licenses/>.
Línea 16... Línea 16...
16
 
16
 
Línea -... Línea 17...
-
 
17
namespace core\task;
-
 
18
 
17
namespace core\task;
19
use stdClass;
18
 
20
 
19
/**
21
/**
20
 * Unit tests for the file_temp_cleanup task.
22
 * Unit tests for the file_temp_cleanup task.
21
 *
23
 *
22
 * @package   core
24
 * @package   core
23
 * @category  test
25
 * @category  test
24
 * @copyright 2013 Tim Gusak <tim.gusak@remote-learner.net>
26
 * @copyright 2013 Tim Gusak <tim.gusak@remote-learner.net>
25
 * @license   http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
27
 * @license   http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
26
 * @covers    \core\task\file_temp_cleanup_task
28
 * @covers    \core\task\file_temp_cleanup_task
27
 */
-
 
28
class file_temp_cleanup_task_test extends \basic_testcase {
29
 */
29
 
30
final class file_temp_cleanup_task_test extends \basic_testcase {
30
    /**
31
    /**
31
     * Data provider for cron_delete_from_temp.
32
     * Data provider for cron_delete_from_temp.
32
     *
33
     *
33
     * @return array Provider data
34
     * @return array Provider data
34
     */
35
     */
Línea 35... Línea 36...
35
    public function cron_delete_from_temp_provider() {
36
    public static function cron_delete_from_temp_provider(): array {
36
        global $CFG;
37
        global $CFG;
37
 
38
 
Línea 44... Línea 45...
44
        $beforelastweekstime = $lastweekstime - 3600 - 1; // At least 1h and 1s diff (make it DST immune).
45
        $beforelastweekstime = $lastweekstime - 3600 - 1; // At least 1h and 1s diff (make it DST immune).
45
        $afterlastweekstime = $lastweekstime + 3600 + 1; // At least 1h and 1s diff (make it DST immune).
46
        $afterlastweekstime = $lastweekstime + 3600 + 1; // At least 1h and 1s diff (make it DST immune).
Línea 46... Línea 47...
46
 
47
 
47
        $nodes = array();
48
        $nodes = array();
48
        // Really old directory to remove.
49
        // Really old directory to remove.
Línea 49... Línea 50...
49
        $nodes[] = $this->generate_test_path('/dir1/dir1_1/dir1_1_1/dir1_1_1_1/', true, $lastweekstime * 52, false);
50
        $nodes[] = self::generate_test_path('/dir1/dir1_1/dir1_1_1/dir1_1_1_1/', true, $lastweekstime * 52, false);
50
 
51
 
Línea 51... Línea 52...
51
        // New Directory to keep.
52
        // New Directory to keep.
52
        $nodes[] = $this->generate_test_path('/dir1/dir1_2/', true, $time, true);
53
        $nodes[] = self::generate_test_path('/dir1/dir1_2/', true, $time, true);
Línea 53... Línea 54...
53
 
54
 
54
        // Directory a little less than 1 week old, keep.
55
        // Directory a little less than 1 week old, keep.
Línea 55... Línea 56...
55
        $nodes[] = $this->generate_test_path('/dir2/', true, $afterlastweekstime, true);
56
        $nodes[] = self::generate_test_path('/dir2/', true, $afterlastweekstime, true);
56
 
57
 
Línea 57... Línea 58...
57
        // Directory older than 1 week old, remove.
58
        // Directory older than 1 week old, remove.
58
        $nodes[] = $this->generate_test_path('/dir3/', true, $beforelastweekstime, false);
59
        $nodes[] = self::generate_test_path('/dir3/', true, $beforelastweekstime, false);
Línea 59... Línea 60...
59
 
60
 
60
        // File older than 1 week old, remove.
61
        // File older than 1 week old, remove.
Línea 61... Línea 62...
61
        $nodes[] = $this->generate_test_path('/dir1/dir1_1/dir1_1_1/file1_1_1_1', false, $beforelastweekstime, false);
62
        $nodes[] = self::generate_test_path('/dir1/dir1_1/dir1_1_1/file1_1_1_1', false, $beforelastweekstime, false);
62
 
63
 
Línea 63... Línea 64...
63
        // New File to keep.
64
        // New File to keep.
64
        $nodes[] = $this->generate_test_path('/dir1/dir1_1/dir1_1_1/file1_1_1_2', false, $time, true);
65
        $nodes[] = self::generate_test_path('/dir1/dir1_1/dir1_1_1/file1_1_1_2', false, $time, true);
Línea 65... Línea 66...
65
 
66
 
66
        // File older than 1 week old, remove.
67
        // File older than 1 week old, remove.
Línea 67... Línea 68...
67
        $nodes[] = $this->generate_test_path('/dir1/dir1_2/file1_1_2_1', false, $beforelastweekstime, false);
68
        $nodes[] = self::generate_test_path('/dir1/dir1_2/file1_1_2_1', false, $beforelastweekstime, false);
68
 
69
 
69
        // New file to keep.
70
        // New file to keep.
Línea 70... Línea 71...
70
        $nodes[] = $this->generate_test_path('/dir1/dir1_2/file1_1_2_2', false, $time, true);
71
        $nodes[] = self::generate_test_path('/dir1/dir1_2/file1_1_2_2', false, $time, true);
Línea 71... Línea 72...
71
 
72
 
Línea 72... Línea 73...
72
        // New file to keep.
73
        // New file to keep.
73
        $nodes[] = $this->generate_test_path('/file1', false, $time, true);
74
        $nodes[] = self::generate_test_path('/file1', false, $time, true);
Línea 74... Línea 75...
74
 
75
 
75
        // File older than 1 week, keep.
76
        // File older than 1 week, keep.
76
        $nodes[] = $this->generate_test_path('/file2', false, $beforelastweekstime, false);
77
        $nodes[] = self::generate_test_path('/file2', false, $beforelastweekstime, false);
77
 
78
 
Línea 102... Línea 103...
102
                }
103
                }
103
            }
104
            }
104
        }
105
        }
105
        sort($expectednodes);
106
        sort($expectednodes);
Línea 106... Línea 107...
106
 
107
 
107
        $data = array(
-
 
108
                array(
-
 
109
                    $nodes,
108
        $data = [
110
                    $expectednodes
109
            [$nodes, $expectednodes],
111
                ),
-
 
112
                array(
-
 
113
                    array(),
-
 
114
                    array()
-
 
115
                )
110
            [[], []],
Línea 116... Línea 111...
116
        );
111
        ];
117
 
112
 
Línea 118... Línea 113...
118
        return $data;
113
        return $data;
Línea 124... Línea 119...
124
     * @param string $path Path of directory or file
119
     * @param string $path Path of directory or file
125
     * @param bool $isdir Is the node a directory
120
     * @param bool $isdir Is the node a directory
126
     * @param int $time modified time of the node in epoch
121
     * @param int $time modified time of the node in epoch
127
     * @param bool $keep Should the node exist after the delete function has run
122
     * @param bool $keep Should the node exist after the delete function has run
128
     */
123
     */
129
    private function generate_test_path($path, $isdir = false, $time = 0, $keep = false) {
124
    private static function generate_test_path($path, $isdir = false, $time = 0, $keep = false): stdClass {
130
        $node = new \stdClass();
125
        return (object) [
131
        $node->path = $path;
126
            'path' => $path,
132
        $node->isdir = $isdir;
127
            'isdir' => $isdir,
133
        $node->time = $time;
128
            'time' => $time,
134
        $node->keep = $keep;
129
            'keep' => $keep,
135
        return $node;
130
        ];
136
    }
131
    }
137
    /**
132
    /**
138
     * Test removing files and directories from tempdir.
133
     * Test removing files and directories from tempdir.
139
     *
134
     *
140
     * @dataProvider cron_delete_from_temp_provider
135
     * @dataProvider cron_delete_from_temp_provider
141
     * @param array $nodes List of files and directories
136
     * @param array $nodes List of files and directories
142
     * @param array $expected The expected results
137
     * @param array $expected The expected results
143
     * @covers ::execute
-
 
144
     */
138
     */
145
    public function test_cron_delete_from_temp($nodes, $expected): void {
139
    public function test_cron_delete_from_temp($nodes, $expected): void {
146
        global $CFG;
140
        global $CFG;
Línea 147... Línea 141...
147
 
141