|
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 00018 00026 if (!defined('MOODLE_INTERNAL')) { 00027 die('Direct access to this script is forbidden.'); 00028 } 00029 require_once($CFG->libdir.'/componentlib.class.php'); 00030 00031 class componentlib_test extends UnitTestCase { 00032 00033 public function test_component_installer() { 00034 global $CFG; 00035 00036 $ci = new component_installer('http://download.moodle.org', 'unittest', 'downloadtests.zip'); 00037 $this->assertTrue($ci->check_requisites()); 00038 00039 $destpath = $CFG->dataroot.'/downloadtests'; 00040 00041 //carefully remove component files to enforce fresh installation 00042 @unlink($destpath.'/'.'downloadtests.md5'); 00043 @unlink($destpath.'/'.'test.html'); 00044 @unlink($destpath.'/'.'test.jpg'); 00045 @rmdir($destpath); 00046 00047 $this->assertEqual(COMPONENT_NEEDUPDATE, $ci->need_upgrade()); 00048 00049 $status = $ci->install(); 00050 $this->assertEqual(COMPONENT_INSTALLED, $status); 00051 $this->assertEqual('9e94f74b3efb1ff6cf075dc6b2abf15c', $ci->get_component_md5()); 00052 00053 //it's already installed, so Moodle should detect it's up to date 00054 $this->assertEqual(COMPONENT_UPTODATE, $ci->need_upgrade()); 00055 $status = $ci->install(); 00056 $this->assertEqual(COMPONENT_UPTODATE, $status); 00057 00058 //check if correct files were downloaded 00059 $this->assertEqual('2af180e813dc3f446a9bb7b6af87ce24', md5_file($destpath.'/'.'test.jpg')); 00060 $this->assertEqual('47250a973d1b88d9445f94db4ef2c97a', md5_file($destpath.'/'.'test.html')); 00061 } 00062 00066 public function test_lang_installer() { 00067 00068 // test the manipulation with the download queue 00069 $installer = new testable_lang_installer(); 00070 $this->assertFalse($installer->protected_is_queued()); 00071 $installer->protected_add_to_queue('cs'); 00072 $installer->protected_add_to_queue(array('cs', 'sk')); 00073 $this->assertTrue($installer->protected_is_queued()); 00074 $this->assertTrue($installer->protected_is_queued('cs')); 00075 $this->assertTrue($installer->protected_is_queued('sk')); 00076 $this->assertFalse($installer->protected_is_queued('de_kids')); 00077 $installer->set_queue('de_kids'); 00078 $this->assertFalse($installer->protected_is_queued('cs')); 00079 $this->assertFalse($installer->protected_is_queued('sk')); 00080 $this->assertFalse($installer->protected_is_queued('de')); 00081 $this->assertFalse($installer->protected_is_queued('de_du')); 00082 $this->assertTrue($installer->protected_is_queued('de_kids')); 00083 $installer->set_queue(array('cs', 'de_kids')); 00084 $this->assertTrue($installer->protected_is_queued('cs')); 00085 $this->assertFalse($installer->protected_is_queued('sk')); 00086 $this->assertFalse($installer->protected_is_queued('de')); 00087 $this->assertFalse($installer->protected_is_queued('de_du')); 00088 $this->assertTrue($installer->protected_is_queued('de_kids')); 00089 $installer->set_queue(array()); 00090 $this->assertFalse($installer->protected_is_queued()); 00091 unset($installer); 00092 00093 // install a set of lang packs 00094 $installer = new testable_lang_installer(array('cs', 'de_kids', 'xx')); 00095 $result = $installer->run(); 00096 $this->assertEqual($result['cs'], lang_installer::RESULT_UPTODATE); 00097 $this->assertEqual($result['de_kids'], lang_installer::RESULT_INSTALLED); 00098 $this->assertEqual($result['xx'], lang_installer::RESULT_DOWNLOADERROR); 00099 // the following two were automatically added to the queue 00100 $this->assertEqual($result['de_du'], lang_installer::RESULT_INSTALLED); 00101 $this->assertEqual($result['de'], lang_installer::RESULT_UPTODATE); 00102 00103 // exception throwing 00104 $installer = new testable_lang_installer(array('yy')); 00105 $this->expectException('lang_installer_exception'); 00106 $installer->run(); 00107 } 00108 } 00109 00117 class testable_lang_installer extends lang_installer { 00118 00122 public function protected_is_queued($langcode = '') { 00123 return $this->is_queued($langcode); 00124 } 00125 00129 public function protected_add_to_queue($langcodes) { 00130 return $this->add_to_queue($langcodes); 00131 } 00132 00143 protected function install_language_pack($langcode) { 00144 00145 switch ($langcode) { 00146 case 'de_du': 00147 case 'de_kids': 00148 return self::RESULT_INSTALLED; 00149 00150 case 'cs': 00151 case 'de': 00152 return self::RESULT_UPTODATE; 00153 00154 case 'xx': 00155 return self::RESULT_DOWNLOADERROR; 00156 00157 default: 00158 throw new lang_installer_exception('testing-unknown-exception', $langcode); 00159 } 00160 } 00161 00167 protected function get_parent_language($langcode) { 00168 00169 switch ($langcode) { 00170 case 'de_kids': 00171 return 'de_du'; 00172 case 'de_du': 00173 return 'de'; 00174 default: 00175 return ''; 00176 } 00177 } 00178 }