Search moodle.org's
Developer Documentation

See Release Notes

  • Bug fixes for general core bugs in 3.10.x will end 8 November 2021 (12 months).
  • Bug fixes for security issues in 3.10.x will end 9 May 2022 (18 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.

Differences Between: [Versions 310 and 311] [Versions 310 and 400] [Versions 310 and 401] [Versions 310 and 402] [Versions 310 and 403] [Versions 39 and 310]

   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 backup_xml_transformer class.
  19   *
  20   * @package     core_backup
  21   * @subpackage  moodle2
  22   * @category    backup
  23   * @copyright   2017 Dmitrii Metelkin (dmitriim@catalyst-au.net)
  24   * @license     http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  25   */
  26  
  27  defined('MOODLE_INTERNAL') || die();
  28  
  29  global $CFG;
  30  require_once($CFG->dirroot . '/backup/util/includes/backup_includes.php');
  31  require_once($CFG->dirroot . '/backup/moodle2/backup_plan_builder.class.php');
  32  
  33  /**
  34   * Tests for backup_xml_transformer.
  35   *
  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
  39   */
  40  class backup_xml_transformer_testcase extends advanced_testcase {
  41  
  42      /**
  43       * Initial set up.
  44       */
  45      public function setUp(): void {
  46          parent::setUp();
  47  
  48          $this->resetAfterTest(true);
  49      }
  50  
  51      /**
  52       * Data provider for ::test_filephp_links_replace.
  53       *
  54       * @return array
  55       */
  56      public function filephp_links_replace_data_provider() {
  57          return array(
  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'),
  80          );
  81      }
  82  
  83      /**
  84       * Test that backup_xml_transformer replaces file php links to $@FILEPHP@$.
  85       *
  86       * @dataProvider filephp_links_replace_data_provider
  87       * @param string $content Testing content.
  88       * @param string $expected Expected result.
  89       */
  90      public function test_filephp_links_replace($content, $expected) {
  91          global $CFG;
  92  
  93          $CFG->wwwroot = 'http://test.test';
  94  
  95          $transformer = new backup_xml_transformer(1);
  96  
  97          $this->assertEquals($expected, $transformer->process($content));
  98      }
  99  
 100  }