2 // This file is part of Moodle - http://moodle.org/
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.
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.
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/>.
18 * Tests for backup_xml_transformer class.
20 * @package core_backup
23 * @copyright 2017 Dmitrii Metelkin (dmitriim@catalyst-au.net)
24 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
27 defined('MOODLE_INTERNAL') ||
die();
30 require_once($CFG->dirroot
. '/backup/util/includes/backup_includes.php');
31 require_once($CFG->dirroot
. '/backup/moodle2/backup_plan_builder.class.php');
34 * Tests for backup_xml_transformer.
36 * @package core_backup
37 * @copyright 2017 Dmitrii Metelkin (dmitriim@catalyst-au.net)
38 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
40 class backup_xml_transformer_testcase
extends advanced_testcase
{
45 public function setUp(): void
{
48 $this->resetAfterTest(true);
52 * Data provider for ::test_filephp_links_replace.
56 public function filephp_links_replace_data_provider() {
58 array('http://test.test/', 'http://test.test/'),
59 array('http://test.test/file.php/1', 'http://test.test/file.php/1'),
60 array('http://test.test/file.php/2/1.jpg', 'http://test.test/file.php/2/1.jpg'),
61 array('http://test.test/file.php/2', 'http://test.test/file.php/2'),
62 array('http://test.test/file.php/1/1.jpg', '$@FILEPHP@$$@SLASH@$1.jpg'),
63 array('http://test.test/file.php/1//1.jpg', '$@FILEPHP@$$@SLASH@$$@SLASH@$1.jpg'),
64 array('http://test.test/file.php?file=/1', '$@FILEPHP@$'),
65 array('http://test.test/file.php?file=/2/1.jpg', 'http://test.test/file.php?file=/2/1.jpg'),
66 array('http://test.test/file.php?file=/2', 'http://test.test/file.php?file=/2'),
67 array('http://test.test/file.php?file=/1/1.jpg', '$@FILEPHP@$$@SLASH@$1.jpg'),
68 array('http://test.test/file.php?file=/1//1.jpg', '$@FILEPHP@$$@SLASH@$$@SLASH@$1.jpg'),
69 array('http://test.test/file.php?file=%2f1', '$@FILEPHP@$'),
70 array('http://test.test/file.php?file=%2f2%2f1.jpg', 'http://test.test/file.php?file=%2f2%2f1.jpg'),
71 array('http://test.test/file.php?file=%2f2', 'http://test.test/file.php?file=%2f2'),
72 array('http://test.test/file.php?file=%2f1%2f1.jpg', '$@FILEPHP@$$@SLASH@$1.jpg'),
73 array('http://test.test/file.php?file=%2f1%2f%2f1.jpg', '$@FILEPHP@$$@SLASH@$$@SLASH@$1.jpg'),
74 array('http://test.test/file.php?file=%2F1', '$@FILEPHP@$'),
75 array('http://test.test/file.php?file=%2F2%2F1.jpg', 'http://test.test/file.php?file=%2F2%2F1.jpg'),
76 array('http://test.test/file.php?file=%2F2', 'http://test.test/file.php?file=%2F2'),
77 array('http://test.test/file.php?file=%2F1%2F1.jpg', '$@FILEPHP@$$@SLASH@$1.jpg'),
78 array('http://test.test/file.php?file=%2F1%2F%2F1.jpg', '$@FILEPHP@$$@SLASH@$$@SLASH@$1.jpg'),
79 array('http://test.test/h5p/embed.php?url=testurl', '$@H5PEMBED@$?url=testurl'),
84 * Test that backup_xml_transformer replaces file php links to $@FILEPHP@$.
86 * @dataProvider filephp_links_replace_data_provider
87 * @param string $content Testing content.
88 * @param string $expected Expected result.
90 public function test_filephp_links_replace($content, $expected) {
93 $CFG->wwwroot
= 'http://test.test';
95 $transformer = new backup_xml_transformer(1);
97 $this->assertEquals($expected, $transformer->process($content));