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
namespace core_backup;
18
 
19
use backup;
20
use backup_controller;
21
use backup_section_structure_step;
22
use backup_section_task;
23
 
24
/**
25
 * Tests for Moodle 2 steplib classes.
26
 *
27
 * @package core_backup
28
 * @copyright 2023 Ferran Recio <ferran@moodle.com>
29
 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
30
 */
31
class backup_stepslib_test extends \advanced_testcase {
32
    /**
33
     * Setup to include all libraries.
34
     */
35
    public static function setUpBeforeClass(): void {
36
        global $CFG;
37
        require_once($CFG->dirroot . '/backup/util/includes/backup_includes.php');
38
        require_once($CFG->dirroot . '/backup/util/includes/restore_includes.php');
39
        require_once($CFG->dirroot . '/backup/moodle2/backup_stepslib.php');
40
    }
41
 
42
    /**
43
     * Test for the section structure step included elements.
44
     *
45
     * @covers \backup_section_structure_step::define_structure
46
     */
47
    public function test_backup_section_structure_step(): void {
48
        global $USER;
49
 
50
        $this->resetAfterTest();
51
        $course = $this->getDataGenerator()->create_course(['numsections' => 3, 'format' => 'topics']);
52
        $this->setAdminUser();
53
 
54
        $step = new backup_section_structure_step('section_commons', 'section.xml');
55
 
56
        // The backup_section_structure_step requires a complex dependency sequence
57
        // but it does not have an easy dependency injection system.
58
        // We create a real backup plan to get the task dependency sequence ready.
59
        $bc = new backup_controller(
60
            backup::TYPE_1COURSE,
61
            $course->id,
62
            backup::FORMAT_MOODLE,
63
            backup::INTERACTIVE_NO,
64
            backup::MODE_IMPORT,
65
            $USER->id);
66
        $tasks = $bc->get_plan()->get_tasks();
67
        foreach ($tasks as $task) {
68
            // We need only the task to backup section 1.
69
            if ($task instanceof backup_section_task && $task->get_name() == "1") {
70
                $task->add_step($step);
71
                break;
72
            }
73
        }
74
 
75
        $reflection = new \ReflectionClass($step);
76
        $method = $reflection->getMethod('define_structure');
77
        $structure = $method->invoke($step);
78
        $bc->destroy();
79
 
80
        $elements = $structure->get_final_elements();
81
        $this->assertArrayHasKey('number', $elements);
82
        $this->assertArrayHasKey('name', $elements);
83
        $this->assertArrayHasKey('summary', $elements);
84
        $this->assertArrayHasKey('summaryformat', $elements);
85
        $this->assertArrayHasKey('sequence', $elements);
86
        $this->assertArrayHasKey('visible', $elements);
87
        $this->assertArrayHasKey('availabilityjson', $elements);
88
        $this->assertArrayHasKey('component', $elements);
89
        $this->assertArrayHasKey('itemid', $elements);
90
        $this->assertArrayHasKey('timemodified', $elements);
91
    }
92
}