|
Moodle
2.2.1
http://www.collinsharper.com
|
00001 <?php 00002 00003 // This file is part of Moodle - http://moodle.org/ 00004 // 00005 // Moodle is free software: you can redistribute it and/or modify 00006 // it under the terms of the GNU General Public License as published by 00007 // the Free Software Foundation, either version 3 of the License, or 00008 // (at your option) any later version. 00009 // 00010 // Moodle is distributed in the hope that it will be useful, 00011 // but WITHOUT ANY WARRANTY; without even the implied warranty of 00012 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00013 // GNU General Public License for more details. 00014 // 00015 // You should have received a copy of the GNU General Public License 00016 // along with Moodle. If not, see <http://www.gnu.org/licenses/>. 00017 00027 defined('MOODLE_INTERNAL') || die(); 00028 00029 require_once($CFG->dirroot . '/backup/util/helper/convert_helper.class.php'); 00030 00034 class testable_convert_helper extends convert_helper { 00035 00036 public static function choose_conversion_path($format, array $descriptions) { 00037 return parent::choose_conversion_path($format, $descriptions); 00038 } 00039 } 00040 00044 class convert_helper_test extends UnitTestCase { 00045 00046 public static $includecoverage = array(); 00047 00048 public function test_choose_conversion_path() { 00049 00050 // no converters available 00051 $descriptions = array(); 00052 $path = testable_convert_helper::choose_conversion_path(backup::FORMAT_MOODLE1, $descriptions); 00053 $this->assertEqual($path, array()); 00054 00055 // missing source and/or targets 00056 $descriptions = array( 00057 // some custom converter 00058 'exporter' => array( 00059 'from' => backup::FORMAT_MOODLE1, 00060 'to' => 'some_custom_format', 00061 'cost' => 10, 00062 ), 00063 // another custom converter 00064 'converter' => array( 00065 'from' => 'yet_another_crazy_custom_format', 00066 'to' => backup::FORMAT_MOODLE, 00067 'cost' => 10, 00068 ), 00069 ); 00070 $path = testable_convert_helper::choose_conversion_path(backup::FORMAT_MOODLE1, $descriptions); 00071 $this->assertEqual($path, array()); 00072 00073 $path = testable_convert_helper::choose_conversion_path('some_other_custom_format', $descriptions); 00074 $this->assertEqual($path, array()); 00075 00076 // single step conversion 00077 $path = testable_convert_helper::choose_conversion_path('yet_another_crazy_custom_format', $descriptions); 00078 $this->assertEqual($path, array('converter')); 00079 00080 // no conversion needed - this is supposed to be detected by the caller 00081 $path = testable_convert_helper::choose_conversion_path(backup::FORMAT_MOODLE, $descriptions); 00082 $this->assertEqual($path, array()); 00083 00084 // two alternatives 00085 $descriptions = array( 00086 // standard moodle 1.9 -> 2.x converter 00087 'moodle1' => array( 00088 'from' => backup::FORMAT_MOODLE1, 00089 'to' => backup::FORMAT_MOODLE, 00090 'cost' => 10, 00091 ), 00092 // alternative moodle 1.9 -> 2.x converter 00093 'alternative' => array( 00094 'from' => backup::FORMAT_MOODLE1, 00095 'to' => backup::FORMAT_MOODLE, 00096 'cost' => 8, 00097 ) 00098 ); 00099 $path = testable_convert_helper::choose_conversion_path(backup::FORMAT_MOODLE1, $descriptions); 00100 $this->assertEqual($path, array('alternative')); 00101 00102 // complex case 00103 $descriptions = array( 00104 // standard moodle 1.9 -> 2.x converter 00105 'moodle1' => array( 00106 'from' => backup::FORMAT_MOODLE1, 00107 'to' => backup::FORMAT_MOODLE, 00108 'cost' => 10, 00109 ), 00110 // alternative moodle 1.9 -> 2.x converter 00111 'alternative' => array( 00112 'from' => backup::FORMAT_MOODLE1, 00113 'to' => backup::FORMAT_MOODLE, 00114 'cost' => 8, 00115 ), 00116 // custom converter from 1.9 -> custom 'CFv1' format 00117 'cc1' => array( 00118 'from' => backup::FORMAT_MOODLE1, 00119 'to' => 'CFv1', 00120 'cost' => 2, 00121 ), 00122 // custom converter from custom 'CFv1' format -> moodle 2.0 format 00123 'cc2' => array( 00124 'from' => 'CFv1', 00125 'to' => backup::FORMAT_MOODLE, 00126 'cost' => 5, 00127 ), 00128 // custom converter from CFv1 -> CFv2 format 00129 'cc3' => array( 00130 'from' => 'CFv1', 00131 'to' => 'CFv2', 00132 'cost' => 2, 00133 ), 00134 // custom converter from CFv2 -> moodle 2.0 format 00135 'cc4' => array( 00136 'from' => 'CFv2', 00137 'to' => backup::FORMAT_MOODLE, 00138 'cost' => 2, 00139 ), 00140 ); 00141 00142 // ask the helper to find the most effective way 00143 $path = testable_convert_helper::choose_conversion_path(backup::FORMAT_MOODLE1, $descriptions); 00144 $this->assertEqual($path, array('cc1', 'cc3', 'cc4')); 00145 } 00146 }