Proyectos de Subversion Moodle

Rev

| Ultima modificación | Ver Log |

Rev Autor Línea Nro. Línea
1441 ariadna 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_data\backup;
18
 
19
/**
20
 * Tests for Database
21
 *
22
 * @package    mod_data
23
 * @category   test
24
 * @copyright  2025 ISB Bayern
25
 * @author     Stefan Hanauska <stefan.hanauska@csg-in.de>
26
 * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
27
 */
28
final class encode_links_test extends \advanced_testcase {
29
    /**
30
     * Test that links are encoded correctly.
31
     *
32
     * @return void
33
     *
34
     * @covers       \backup_data_activity_task::encode_content_links
35
     * @covers       \restore_data_activity_task::define_decode_rules
36
     */
37
    public function test_encode_links(): void {
38
        global $CFG, $DB;
39
        $this->resetAfterTest();
40
        $this->setAdminUser();
41
 
42
        // Make a test course.
43
        $generator = $this->getDataGenerator();
44
        $course = $generator->create_course();
45
        $newcourse = $generator->create_course();
46
        $data = $this->getDataGenerator()->create_module('data', ['course' => $course->id]);
47
        $datagenerator = $this->getDataGenerator()->get_plugin_generator('mod_data');
48
        $field = $datagenerator->create_field(
49
            (object) ['name' => 'field', 'type' => 'text'],
50
            $data
51
        );
52
 
53
        $entry = [$field->field->id => 'test'];
54
        $datagenerator->create_entry($data, $entry);
55
 
56
        $data->intro = $CFG->wwwroot . '/mod/data/view.php?id=' . $data->cmid . '|';
57
        $data->intro .= urlencode($CFG->wwwroot . '/mod/data/view.php?id='. $data->cmid) . '|';
58
        $data->intro .= $CFG->wwwroot . '/mod/data/view.php?d=' . $data->id . '|';
59
        $data->intro .= urlencode($CFG->wwwroot . '/mod/data/view.php?d='. $data->id) . '|';
60
        $data->intro .= $CFG->wwwroot . '/mod/data/index.php?id=' . $data->course . '|';
61
        $data->intro .= urlencode($CFG->wwwroot . '/mod/data/index.php?id=' . $data->course) . '|';
62
        $data->intro .= $CFG->wwwroot . '/mod/data/edit.php?id=' . $data->cmid . '|';
63
        $data->intro .= urlencode($CFG->wwwroot . '/mod/data/edit.php?id='. $data->cmid) . '|';
64
        $data->intro .= $CFG->wwwroot . '/mod/data/edit.php?d=' . $data->id . '|';
65
        $data->intro .= urlencode($CFG->wwwroot . '/mod/data/edit.php?d=' . $data->id) . '|';
66
 
67
        $DB->update_record('data', $data);
68
 
69
        // Duplicate the data module with the type.
70
        $newcm = duplicate_module($course, get_fast_modinfo($course)->get_cm($data->cmid));
71
 
72
        $newdata = $DB->get_record('data', ['id' => $newcm->instance]);
73
 
74
        $expected = $CFG->wwwroot . '/mod/data/view.php?id=' . $newcm->id . '|';
75
        $expected .= urlencode($CFG->wwwroot . '/mod/data/view.php?id=' . $newcm->id) . '|';
76
        $expected .= $CFG->wwwroot . '/mod/data/view.php?d=' . $newdata->id . '|';
77
        $expected .= urlencode($CFG->wwwroot . '/mod/data/view.php?d=' . $newdata->id) . '|';
78
        $expected .= $CFG->wwwroot . '/mod/data/index.php?id=' . $newcm->course . '|';
79
        $expected .= urlencode($CFG->wwwroot . '/mod/data/index.php?id=' . $newcm->course) . '|';
80
        $expected .= $CFG->wwwroot . '/mod/data/edit.php?id=' . $newcm->id . '|';
81
        $expected .= urlencode($CFG->wwwroot . '/mod/data/edit.php?id='. $newcm->id) . '|';
82
        $expected .= $CFG->wwwroot . '/mod/data/edit.php?d=' . $newdata->id . '|';
83
        $expected .= urlencode($CFG->wwwroot . '/mod/data/edit.php?d=' . $newdata->id) . '|';
84
 
85
        $this->assertEquals($expected, $newdata->intro);
86
    }
87
}