Proyectos de Subversion Moodle

Rev

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

Rev 11 Rev 1441
Línea 15... Línea 15...
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 17... Línea 17...
17
namespace core_backup;
17
namespace core_backup;
-
 
18
 
-
 
19
use backup;
-
 
20
use core\di;
Línea 18... Línea 21...
18
 
21
use core\hook\manager;
19
use backup;
22
use restore_controller;
20
 
23
 
21
/**
24
/**
22
 * Tests for Moodle 2 restore steplib classes.
25
 * Tests for Moodle 2 restore steplib classes.
23
 *
26
 *
24
 * @package core_backup
27
 * @package core_backup
25
 * @copyright 2023 Ferran Recio <ferran@moodle.com>
28
 * @copyright 2023 Ferran Recio <ferran@moodle.com>
26
 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
29
 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
27
 */
30
 */
28
class restore_stepslib_test extends \advanced_testcase {
31
final class restore_stepslib_test extends \advanced_testcase {
29
    /**
32
    /**
30
     * Setup to include all libraries.
33
     * Setup to include all libraries.
31
     */
34
     */
32
    public static function setUpBeforeClass(): void {
35
    public static function setUpBeforeClass(): void {
33
        global $CFG;
36
        global $CFG;
-
 
37
        require_once($CFG->dirroot . '/backup/util/includes/backup_includes.php');
34
        require_once($CFG->dirroot . '/backup/util/includes/backup_includes.php');
38
        require_once($CFG->dirroot . '/backup/util/includes/restore_includes.php');
Línea 35... Línea 39...
35
        require_once($CFG->dirroot . '/backup/util/includes/restore_includes.php');
39
        require_once($CFG->dirroot . '/backup/moodle2/restore_stepslib.php');
36
        require_once($CFG->dirroot . '/backup/moodle2/restore_stepslib.php');
40
        parent::setUpBeforeClass();
37
    }
41
    }
Línea 100... Línea 104...
100
 
104
 
101
        return $course->id;
105
        return $course->id;
Línea 102... Línea 106...
102
    }
106
    }
103
 
107
 
104
    /**
108
    /**
105
     * Test for the section structure step included elements.
109
     * Test for delegate section behaviour.
106
     *
110
     *
107
     * @covers \restore_section_structure_step::process_section
111
     * @covers \restore_section_structure_step::process_section
108
     */
112
     */
Línea 109... Línea 113...
109
    public function test_restore_section_structure_step(): void {
113
    public function test_restore_section_structure_step(): void {
110
        global $DB;
114
        global $DB;
Línea 111... Línea 115...
111
 
115
 
-
 
116
        $this->resetAfterTest();
-
 
117
        $this->setAdminUser();
-
 
118
 
-
 
119
        $course = $this->getDataGenerator()->create_course(['numsections' => 2, 'format' => 'topics']);
-
 
120
        // Section 2 has an existing delegate class for component that is not an activity.
-
 
121
        course_update_section(
-
 
122
            $course,
-
 
123
            $DB->get_record('course_sections', ['course' => $course->id, 'section' => 2]),
-
 
124
            [
Línea 112... Línea 125...
112
        $this->resetAfterTest();
125
                'component' => 'test_component',
113
        $this->setAdminUser();
126
                'itemid' => 1,
Línea 114... Línea 127...
114
 
127
            ]
115
        $course = $this->getDataGenerator()->create_course(['numsections' => 2, 'format' => 'topics']);
128
        );
Línea -... Línea 129...
-
 
129
 
-
 
130
        $backupid = $this->backup_course($course);
-
 
131
        $newcourseid = $this->restore_replacing_content($backupid);
116
 
132
 
Línea 117... Línea 133...
117
        $backupid = $this->backup_course($course);
133
        $originalsections = get_fast_modinfo($course->id)->get_section_info_all();
Línea -... Línea 134...
-
 
134
        $restoredsections = get_fast_modinfo($newcourseid)->get_section_info_all();
-
 
135
 
118
        $newcourseid = $this->restore_replacing_content($backupid);
136
        // Delegated sections depends on the plugin to be backuped and restored.
-
 
137
        // In this case, the plugin is not backuped and restored, so the section is not restored.
119
 
138
        $this->assertEquals(3, count($originalsections));
120
        $originalsections = get_fast_modinfo($course->id)->get_section_info_all();
-
 
121
        $restoredsections = get_fast_modinfo($newcourseid)->get_section_info_all();
139
        $this->assertEquals(2, count($restoredsections));
-
 
140
 
-
 
141
        $validatefields = ['name', 'summary', 'summaryformat', 'visible', 'component', 'itemid'];
-
 
142
 
-
 
143
        $this->assertEquals($originalsections[1]->name, $restoredsections[1]->name);
-
 
144
 
-
 
145
        foreach ($validatefields as $field) {
-
 
146
            $this->assertEquals($originalsections[0]->$field, $restoredsections[0]->$field);
-
 
147
            $this->assertEquals($originalsections[1]->$field, $restoredsections[1]->$field);
-
 
148
        }
-
 
149
    }
-
 
150
 
-
 
151
    /**
-
 
152
     * Tests the hooks for restore task  settings definition.
-
 
153
     *
-
 
154
     * @covers \restore_root_task::define_settings
-
 
155
     */
-
 
156
    public function test_restore_hook(): void {
-
 
157
        // Load the callback classes.
-
 
158
        require_once(__DIR__ . '/fixtures/restore_task_hooks.php');
-
 
159
 
-
 
160
        $this->resetAfterTest();
-
 
161
        $this->setAdminUser();
-
 
162
 
-
 
163
        // Replace the version of the manager in the DI container with a phpunit one.
-
 
164
        di::set(
-
 
165
            manager::class,
-
 
166
            manager::phpunit_get_instance([
-
 
167
                // Load a list of hooks for `test_plugin1` from the fixture file.
-
 
168
                'test_plugin1' => __DIR__ .
-
 
169
                    '/fixtures/restore_task_hooks.php',
-
 
170
            ]),
-
 
171
        );
-
 
172
 
-
 
173
        global $CFG, $USER;
-
 
174
 
-
 
175
        // Create course to restore into, and a user to do the restore.
Línea -... Línea 176...
-
 
176
        $generator = $this->getDataGenerator();
-
 
177
        $course = $generator->create_course();
-
 
178
 
-
 
179
        $backupid = $this->backup_course($course);
-
 
180
 
-
 
181
        // Turn off file logging, otherwise it can't delete the file (Windows).
-
 
182
        $CFG->backup_file_logger_level = backup::LOG_NONE;
-
 
183
 
-
 
184
        $course = $generator->create_course();
-
 
185
 
-
 
186
        // Do restore to new course with default settings.
-
 
187
        $rc = new restore_controller(
-
 
188
            $backupid,
-
 
189
            $course->id,
-
 
190
            backup::INTERACTIVE_NO,
-
 
191
            backup::MODE_GENERAL,
122
 
192
            $USER->id,
123
        $this->assertEquals(count($originalsections), count($restoredsections));
193
            backup::TARGET_EXISTING_DELETING