Search moodle.org's
Developer Documentation

See Release Notes
Long Term Support Release

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