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