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.

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

   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   * Test for restore_stepslib.
  19   *
  20   * @package core_backup
  21   * @copyright 2016 Andrew Nicols <andrew@nicols.co.uk>
  22   * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  23   */
  24  
  25  defined('MOODLE_INTERNAL') || die();
  26  
  27  global $CFG;
  28  require_once($CFG->dirroot . '/backup/util/includes/backup_includes.php');
  29  require_once($CFG->dirroot . '/backup/util/includes/restore_includes.php');
  30  require_once($CFG->libdir . '/completionlib.php');
  31  
  32  /**
  33   * Test for restore_stepslib.
  34   *
  35   * @package core_backup
  36   * @copyright 2016 Andrew Nicols <andrew@nicols.co.uk>
  37   * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  38   */
  39  class core_backup_restore_gradebook_structure_step_testcase extends advanced_testcase {
  40  
  41      /**
  42       * Provide tests for rewrite_step_backup_file_for_legacy_freeze based upon fixtures.
  43       *
  44       * @return array
  45       */
  46      public function rewrite_step_backup_file_for_legacy_freeze_provider() {
  47          $fixturesdir = realpath(__DIR__ . '/fixtures/rewrite_step_backup_file_for_legacy_freeze/');
  48          $tests = [];
  49          $iterator = new \RecursiveIteratorIterator(
  50                  new \RecursiveDirectoryIterator($fixturesdir),
  51                  \RecursiveIteratorIterator::LEAVES_ONLY);
  52  
  53          foreach ($iterator as $sourcefile) {
  54              $pattern = '/\.test$/';
  55              if (!preg_match($pattern, $sourcefile)) {
  56                  continue;
  57              }
  58  
  59              $expectfile = preg_replace($pattern, '.expectation', $sourcefile);
  60              $test = array($sourcefile, $expectfile);
  61              $tests[basename($sourcefile)] = $test;
  62          }
  63  
  64          return $tests;
  65      }
  66  
  67      /**
  68       * @dataProvider rewrite_step_backup_file_for_legacy_freeze_provider
  69       * @param   string  $source     The source file to test
  70       * @param   string  $expected   The expected result of the transformation
  71       */
  72      public function test_rewrite_step_backup_file_for_legacy_freeze($source, $expected) {
  73          $restore = $this->getMockBuilder('\restore_gradebook_structure_step')
  74              ->setMethods(null)
  75              ->disableOriginalConstructor()
  76              ->getMock()
  77              ;
  78  
  79          // Copy the file somewhere as the rewrite_step_backup_file_for_legacy_freeze will write the file.
  80          $dir = make_request_directory(true);
  81          $filepath = $dir . DIRECTORY_SEPARATOR . 'file.xml';
  82          copy($source, $filepath);
  83  
  84          $rc = new \ReflectionClass('\restore_gradebook_structure_step');
  85          $rcm = $rc->getMethod('rewrite_step_backup_file_for_legacy_freeze');
  86          $rcm->setAccessible(true);
  87          $rcm->invoke($restore, $filepath);
  88  
  89          // Check the result.
  90          $this->assertFileEquals($expected, $filepath);
  91      }
  92  }