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 mod_wiki\backup;
18
 
19
/**
20
 * Unit tests for wiki restoration process
21
 *
22
 * @package   mod_wiki
23
 * @copyright 2024 Laurent David <laurent.david@moodle.com>
24
 *
25
 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
26
 */
27
class restore_format_test extends \advanced_testcase {
28
 
29
    /**
30
     * Data provider for test_duplicating_wiki_removes_unwanted_formats.
31
     *
32
     * @return array[]
33
     */
34
    public static function restore_format_test_provider(): array {
35
        return [
36
            'creole' => [
37
                'data' => 'creole',
38
                'expected' => 'creole',
39
            ],
40
            'html' => [
41
                'data' => 'html',
42
                'expected' => 'html',
43
            ],
44
            'wikimarkup' => [
45
                'data' => 'nwiki',
46
                'expected' => 'nwiki',
47
            ],
48
            'wrong format' => [
49
                'data' => '../wrongformat123',
50
                'expected' => 'wrongformat',
51
            ],
52
        ];
53
    }
54
 
55
    /**
56
     * Test that duplicating a wiki removes unwanted / invalid format.
57
     *
58
     * @param string $format The format of the wiki.
59
     * @param string $expected The expected format of the wiki after duplication.
60
     *
61
     * @covers       \restore_wiki_activity_structure_step
62
     * @dataProvider restore_format_test_provider
63
     */
64
    public function test_duplicating_wiki_removes_unwanted_formats(string $format, string $expected): void {
65
        global $DB;
66
 
67
        $this->resetAfterTest();
68
        $this->setAdminUser();
69
 
70
        // Make a test course.
71
        $generator = $this->getDataGenerator();
72
        $course = $generator->create_course();
73
        $wiki = $generator->create_module('wiki', array_merge(['course' => $course->id, 'defaultformat' => $format]));
74
        // Duplicate the wiki.
75
        $newwikicm = duplicate_module($course, get_fast_modinfo($course)->get_cm($wiki->cmid));
76
        // Verify the settings of the duplicated activity.
77
        $newwiki = $DB->get_record('wiki', ['id' => $newwikicm->instance]);
78
        $this->assertEquals($expected, $newwiki->defaultformat);
79
    }
80
}