Search moodle.org's
Developer Documentation

See Release Notes
Long Term Support Release

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