Proyectos de Subversion Moodle

Rev

| 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
/**
18
 * Unit tests for the relativedate condition.
19
 *
20
 * @package   availability_relativedate
21
 * @copyright 2022 eWallah.net
22
 * @author    Renaat Debleu <info@eWallah.net>
23
 * @license   http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
24
 */
25
namespace availability_relativedate;
26
 
27
use availability_relativedate\condition;
28
 
29
/**
30
 * Unit tests for the relativedate condition.
31
 *
32
 * @package   availability_relativedate
33
 * @copyright 2022 eWallah.net
34
 * @author    Renaat Debleu <info@eWallah.net>
35
 * @license   http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
36
 * @coversDefaultClass \availability_relativedate\condition
37
 */
38
final class backup_test extends \advanced_testcase {
39
    /**
40
     * Backup check.
41
     * @covers \availability_relativedate\condition
42
     */
43
    public function test_backup(): void {
44
        global $CFG, $DB;
45
        $this->resetAfterTest();
46
        $this->setAdminUser();
47
 
48
        require_once($CFG->dirroot . '/backup/util/includes/backup_includes.php');
49
        require_once($CFG->dirroot . '/backup/util/includes/restore_includes.php');
50
 
51
        $dg = $this->getDataGenerator();
52
        $now = time();
53
        $course = $dg->create_course(['startdate' => $now, 'enddate' => $now + 7 * WEEKSECS, 'enablecompletion' => 1]);
54
 
55
        $pg = $this->getDataGenerator()->get_plugin_generator('mod_page');
56
        $page0 = $pg->create_instance(['course' => $course, 'completion' => COMPLETION_TRACKING_MANUAL]);
57
        $page1 = $pg->create_instance(['course' => $course, 'completion' => COMPLETION_TRACKING_MANUAL]);
58
        $page2 = $pg->create_instance(['course' => $course, 'completion' => COMPLETION_TRACKING_MANUAL]);
59
        $str = '{"op":"|","show":true,"c":[{"type":"relativedate","n":4,"d":4,"s":7,"m":' . $page1->cmid . '}]}';
60
        $DB->set_field('course_modules', 'availability', $str, ['id' => $page0->cmid]);
61
        $str = '{"op":"|","c":[{"type":"relativedate","n":1,"d":1,"s":6,"m":999999}], "show":true}';
62
        $DB->set_field('course_modules', 'availability', $str, ['id' => $page2->cmid]);
63
        rebuild_course_cache($course->id, true);
64
        $bc = new \backup_controller(
65
            \backup::TYPE_1COURSE,
66
            $course->id,
67
            \backup::FORMAT_MOODLE,
68
            \backup::INTERACTIVE_NO,
69
            \backup::MODE_GENERAL,
70
            2
71
        );
72
        $bc->execute_plan();
73
        $results = $bc->get_results();
74
        $file = $results['backup_destination'];
75
        $fp = get_file_packer('application/vnd.moodle.backup');
76
        $filepath = $CFG->dataroot . '/temp/backup/test-restore-course-event';
77
        $file->extract_to_pathname($fp, $filepath);
78
        $bc->destroy();
79
        $rc = new \restore_controller(
80
            'test-restore-course-event',
81
            $course->id,
82
            \backup::INTERACTIVE_NO,
83
            \backup::MODE_GENERAL,
84
            2,
85
            \backup::TARGET_NEW_COURSE
86
        );
87
        $rc->execute_precheck();
88
        $rc->execute_plan();
89
        $newid = $rc->get_courseid();
90
        $rc->destroy();
91
        $newcourse = get_course($newid);
92
        $modinfo = get_fast_modinfo($newcourse);
93
        $this->assertCount(6, $modinfo->get_instances_of('page'));
94
 
95
        $bc = new \backup_controller(
96
            \backup::TYPE_1COURSE,
97
            $course->id,
98
            \backup::FORMAT_MOODLE,
99
            \backup::INTERACTIVE_NO,
100
            \backup::MODE_GENERAL,
101
            2
102
        );
103
        $bc->execute_plan();
104
        $results = $bc->get_results();
105
        $file = $results['backup_destination'];
106
        $fp = get_file_packer('application/vnd.moodle.backup');
107
        $filepath = $CFG->dataroot . '/temp/backup/test-restore-course-event';
108
        $file->extract_to_pathname($fp, $filepath);
109
        $bc->destroy();
110
        $rc = new \restore_controller(
111
            'test-restore-course-event',
112
            $course->id,
113
            \backup::INTERACTIVE_NO,
114
            \backup::MODE_GENERAL,
115
            2,
116
            \backup::TARGET_CURRENT_ADDING
117
        );
118
        $rc->execute_precheck();
119
        $rc->execute_plan();
120
        $newid = $rc->get_courseid();
121
        $rc->destroy();
122
        $course = get_course($newid);
123
        $modinfo = get_fast_modinfo($course);
124
        $this->assertCount(12, $modinfo->get_instances_of('page'));
125
    }
126
}