MDL-29506 forum: Add tests for encode_content_links
[moodle.git] / mod / forum / tests / backup_forum_activity_test.php
CommitLineData
66a70b97
AN
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/**
18 * Tests for mod_forum_backup_forum_activity_task.
19 *
20 * @package mod_forum
21 * @category test
22 * @copyright 2016 Andrew Nicols <andrew@nicols.co.uk>
23 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
24 */
25
26defined('MOODLE_INTERNAL') || die();
27
28global $CFG;
29require_once($CFG->dirroot . '/backup/util/plan/backup_structure_step.class.php');
30require_once($CFG->dirroot . '/backup/moodle2/backup_stepslib.php');
31require_once($CFG->dirroot . '/backup/moodle2/backup_activity_task.class.php');
32require_once($CFG->dirroot . '/mod/forum/backup/moodle2/backup_forum_activity_task.class.php');
33
34/**
35 * Tests for mod_forum_backup_forum_activity_task.
36 *
37 * @package mod_forum
38 * @category test
39 * @copyright 2016 Andrew Nicols <andrew@nicols.co.uk>
40 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
41 */
42class mod_forum_backup_forum_activity_task_testcase extends advanced_testcase {
43
44 /**
45 * Test the encoding of forum content links.
46 *
47 * @param string $content The incoming content
48 * @param string $expectation The expected result
49 *
50 * @dataProvider encode_content_links_provider
51 */
52 public function test_encode_content_links($content, $expectation) {
53 $this->assertEquals($expectation, backup_forum_activity_task::encode_content_links($content));
54 }
55
56 public function encode_content_links_provider() {
57 global $CFG;
58 $altwwwroot = 'http://invalid.example.com/';
59 return [
60 'Link to the list of forums for current wwwroot' => [
61 sprintf('%s/mod/forum/index.php?id=42', $CFG->wwwroot),
62 '$@FORUMINDEX*42@$',
63 ],
64 'Link to forum view by moduleid for current wwwroot' => [
65 sprintf('%s/mod/forum/view.php?id=29', $CFG->wwwroot),
66 '$@FORUMVIEWBYID*29@$',
67 ],
68 'Link to forum view by forumid for current wwwroot' => [
69 sprintf('%s/mod/forum/view.php?f=31', $CFG->wwwroot),
70 '$@FORUMVIEWBYF*31@$',
71 ],
72 'Link to forum discussion with parent syntax for current wwwroot' => [
73 sprintf('%s/mod/forum/discuss.php?d=26&parent=99', $CFG->wwwroot),
74 '$@FORUMDISCUSSIONVIEWPARENT*26*99@$',
75 ],
76 'Link to forum discussion with parent syntax for current wwwroot encoded' => [
77 sprintf('%s/mod/forum/discuss.php?d=26&amp;parent=99', $CFG->wwwroot),
78 '$@FORUMDISCUSSIONVIEWPARENT*26*99@$',
79 ],
80 'Link to forum discussion with relative syntax for current wwwroot' => [
81 sprintf('%s/mod/forum/discuss.php?d=1040#9930', $CFG->wwwroot),
82 '$@FORUMDISCUSSIONVIEWINSIDE*1040*9930@$',
83 ],
84 'Link to forum discussion by discussionid for current wwwroot' => [
85 sprintf('%s/mod/forum/discuss.php?d=9304', $CFG->wwwroot),
86 '$@FORUMDISCUSSIONVIEW*9304@$',
87 ],
88 'Link to the list of forums for other wwwroot' => [
89 sprintf('%s/mod/forum/index.php?id=42', $altwwwroot),
90 sprintf('%s/mod/forum/index.php?id=42', $altwwwroot),
91 ],
92 'Link to forum view by moduleid for other wwwroot' => [
93 sprintf('%s/mod/forum/view.php?id=29', $altwwwroot),
94 sprintf('%s/mod/forum/view.php?id=29', $altwwwroot),
95 ],
96 'Link to forum view by forumid for other wwwroot' => [
97 sprintf('%s/mod/forum/view.php?f=31', $altwwwroot),
98 sprintf('%s/mod/forum/view.php?f=31', $altwwwroot),
99 ],
100 'Link to forum discussion with parent syntax for other wwwroot' => [
101 sprintf('%s/mod/forum/discuss.php?d=26&parent=99', $altwwwroot),
102 sprintf('%s/mod/forum/discuss.php?d=26&parent=99', $altwwwroot),
103 ],
104 'Link to forum discussion with parent syntax for other wwwroot encoded' => [
105 sprintf('%s/mod/forum/discuss.php?d=26&amp;parent=99', $altwwwroot),
106 sprintf('%s/mod/forum/discuss.php?d=26&amp;parent=99', $altwwwroot),
107 ],
108 'Link to forum discussion with relative syntax for other wwwroot' => [
109 sprintf('%s/mod/forum/discuss.php?d=1040#9930', $altwwwroot),
110 sprintf('%s/mod/forum/discuss.php?d=1040#9930', $altwwwroot),
111 ],
112 'Link to forum discussion by discussionid for other wwwroot' => [
113 sprintf('%s/mod/forum/discuss.php?d=9304', $altwwwroot),
114 sprintf('%s/mod/forum/discuss.php?d=9304', $altwwwroot),
115 ],
116 ];
117 }
118}