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.

Differences Between: [Versions 310 and 401] [Versions 39 and 401]

   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 core_backup;
  18  
  19  use backup_xml_transformer;
  20  
  21  defined('MOODLE_INTERNAL') || die();
  22  
  23  global $CFG;
  24  require_once($CFG->dirroot . '/backup/util/includes/backup_includes.php');
  25  require_once($CFG->dirroot . '/backup/moodle2/backup_plan_builder.class.php');
  26  
  27  /**
  28   * Tests for backup_xml_transformer.
  29   *
  30   * @package core_backup
  31   * @subpackage  moodle2
  32   * @category    test
  33   * @copyright 2017 Dmitrii Metelkin (dmitriim@catalyst-au.net)
  34   * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  35   */
  36  class backup_xml_transformer_test extends \advanced_testcase {
  37  
  38      /**
  39       * Initial set up.
  40       */
  41      public function setUp(): void {
  42          parent::setUp();
  43  
  44          $this->resetAfterTest(true);
  45      }
  46  
  47      /**
  48       * Data provider for ::test_filephp_links_replace.
  49       *
  50       * @return array
  51       */
  52      public function filephp_links_replace_data_provider() {
  53          return array(
  54              array('http://test.test/', 'http://test.test/'),
  55              array('http://test.test/file.php/1', 'http://test.test/file.php/1'),
  56              array('http://test.test/file.php/2/1.jpg', 'http://test.test/file.php/2/1.jpg'),
  57              array('http://test.test/file.php/2', 'http://test.test/file.php/2'),
  58              array('http://test.test/file.php/1/1.jpg', '$@FILEPHP@$$@SLASH@$1.jpg'),
  59              array('http://test.test/file.php/1//1.jpg', '$@FILEPHP@$$@SLASH@$$@SLASH@$1.jpg'),
  60              array('http://test.test/file.php?file=/1', '$@FILEPHP@$'),
  61              array('http://test.test/file.php?file=/2/1.jpg', 'http://test.test/file.php?file=/2/1.jpg'),
  62              array('http://test.test/file.php?file=/2', 'http://test.test/file.php?file=/2'),
  63              array('http://test.test/file.php?file=/1/1.jpg', '$@FILEPHP@$$@SLASH@$1.jpg'),
  64              array('http://test.test/file.php?file=/1//1.jpg', '$@FILEPHP@$$@SLASH@$$@SLASH@$1.jpg'),
  65              array('http://test.test/file.php?file=%2f1', '$@FILEPHP@$'),
  66              array('http://test.test/file.php?file=%2f2%2f1.jpg', 'http://test.test/file.php?file=%2f2%2f1.jpg'),
  67              array('http://test.test/file.php?file=%2f2', 'http://test.test/file.php?file=%2f2'),
  68              array('http://test.test/file.php?file=%2f1%2f1.jpg', '$@FILEPHP@$$@SLASH@$1.jpg'),
  69              array('http://test.test/file.php?file=%2f1%2f%2f1.jpg', '$@FILEPHP@$$@SLASH@$$@SLASH@$1.jpg'),
  70              array('http://test.test/file.php?file=%2F1', '$@FILEPHP@$'),
  71              array('http://test.test/file.php?file=%2F2%2F1.jpg', 'http://test.test/file.php?file=%2F2%2F1.jpg'),
  72              array('http://test.test/file.php?file=%2F2', 'http://test.test/file.php?file=%2F2'),
  73              array('http://test.test/file.php?file=%2F1%2F1.jpg', '$@FILEPHP@$$@SLASH@$1.jpg'),
  74              array('http://test.test/file.php?file=%2F1%2F%2F1.jpg', '$@FILEPHP@$$@SLASH@$$@SLASH@$1.jpg'),
  75              array('http://test.test/h5p/embed.php?url=testurl', '$@H5PEMBED@$?url=testurl'),
  76          );
  77      }
  78  
  79      /**
  80       * Test that backup_xml_transformer replaces file php links to $@FILEPHP@$.
  81       *
  82       * @dataProvider filephp_links_replace_data_provider
  83       * @param string $content Testing content.
  84       * @param string $expected Expected result.
  85       */
  86      public function test_filephp_links_replace($content, $expected) {
  87          global $CFG;
  88  
  89          $CFG->wwwroot = 'http://test.test';
  90  
  91          $transformer = new backup_xml_transformer(1);
  92  
  93          $this->assertEquals($expected, $transformer->process($content));
  94      }
  95  
  96  }