Proyectos de Subversion Moodle

Rev

Rev 1 | | Comparar con el anterior | 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
 */
1441 ariadna 31
final class backup_stepslib_test extends \advanced_testcase {
1 efrain 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');
1441 ariadna 40
        parent::setUpBeforeClass();
1 efrain 41
    }
42
 
43
    /**
44
     * Test for the section structure step included elements.
45
     *
46
     * @covers \backup_section_structure_step::define_structure
47
     */
48
    public function test_backup_section_structure_step(): void {
49
        global $USER;
50
 
51
        $this->resetAfterTest();
52
        $course = $this->getDataGenerator()->create_course(['numsections' => 3, 'format' => 'topics']);
53
        $this->setAdminUser();
54
 
55
        $step = new backup_section_structure_step('section_commons', 'section.xml');
56
 
57
        // The backup_section_structure_step requires a complex dependency sequence
58
        // but it does not have an easy dependency injection system.
59
        // We create a real backup plan to get the task dependency sequence ready.
60
        $bc = new backup_controller(
61
            backup::TYPE_1COURSE,
62
            $course->id,
63
            backup::FORMAT_MOODLE,
64
            backup::INTERACTIVE_NO,
65
            backup::MODE_IMPORT,
66
            $USER->id);
67
        $tasks = $bc->get_plan()->get_tasks();
68
        foreach ($tasks as $task) {
69
            // We need only the task to backup section 1.
70
            if ($task instanceof backup_section_task && $task->get_name() == "1") {
71
                $task->add_step($step);
72
                break;
73
            }
74
        }
75
 
76
        $reflection = new \ReflectionClass($step);
77
        $method = $reflection->getMethod('define_structure');
78
        $structure = $method->invoke($step);
79
        $bc->destroy();
80
 
81
        $elements = $structure->get_final_elements();
82
        $this->assertArrayHasKey('number', $elements);
83
        $this->assertArrayHasKey('name', $elements);
84
        $this->assertArrayHasKey('summary', $elements);
85
        $this->assertArrayHasKey('summaryformat', $elements);
86
        $this->assertArrayHasKey('sequence', $elements);
87
        $this->assertArrayHasKey('visible', $elements);
88
        $this->assertArrayHasKey('availabilityjson', $elements);
89
        $this->assertArrayHasKey('component', $elements);
90
        $this->assertArrayHasKey('itemid', $elements);
91
        $this->assertArrayHasKey('timemodified', $elements);
92
    }
93
}