[ Index ] |
PHP Cross Reference of Unnamed Project |
[Summary view] [Print] [Text view]
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 * Moodle environment test. 19 * 20 * @package core 21 * @category phpunit 22 * @copyright 2013 Petr Skoda {@link http://skodak.org} 23 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later 24 */ 25 26 defined('MOODLE_INTERNAL') || die(); 27 28 29 /** 30 * Do standard environment.xml tests. 31 */ 32 class core_environment_testcase extends advanced_testcase { 33 34 /** 35 * Test the environment. 36 */ 37 public function test_environment() { 38 global $CFG; 39 40 require_once($CFG->libdir.'/environmentlib.php'); 41 list($envstatus, $environment_results) = check_moodle_environment(normalize_version($CFG->release), ENV_SELECT_RELEASE); 42 43 $this->assertNotEmpty($envstatus); 44 foreach ($environment_results as $environment_result) { 45 if ($environment_result->part === 'php_setting' 46 and $environment_result->info === 'opcache.enable' 47 and $environment_result->getLevel() === 'optional' 48 and $environment_result->getStatus() === false 49 ) { 50 $this->markTestSkipped('OPCache extension is not necessary for unit testing.'); 51 continue; 52 } 53 $this->assertTrue($environment_result->getStatus(), "Problem detected in environment ($environment_result->part:$environment_result->info), fix all warnings and errors!"); 54 } 55 } 56 57 /** 58 * Test the get_list_of_environment_versions() function. 59 */ 60 public function test_get_list_of_environment_versions() { 61 global $CFG; 62 require_once($CFG->libdir.'/environmentlib.php'); 63 // Build a sample xmlised environment.xml. 64 $xml = <<<END 65 <COMPATIBILITY_MATRIX> 66 <MOODLE version="1.9"> 67 <PHP_EXTENSIONS> 68 <PHP_EXTENSION name="xsl" level="required" /> 69 </PHP_EXTENSIONS> 70 </MOODLE> 71 <MOODLE version="2.5"> 72 <PHP_EXTENSIONS> 73 <PHP_EXTENSION name="xsl" level="required" /> 74 </PHP_EXTENSIONS> 75 </MOODLE> 76 <MOODLE version="2.6"> 77 <PHP_EXTENSIONS> 78 <PHP_EXTENSION name="xsl" level="required" /> 79 </PHP_EXTENSIONS> 80 </MOODLE> 81 <MOODLE version="2.7"> 82 <PHP_EXTENSIONS> 83 <PHP_EXTENSION name="xsl" level="required" /> 84 </PHP_EXTENSIONS> 85 </MOODLE> 86 <PLUGIN name="block_test"> 87 <PHP_EXTENSIONS> 88 <PHP_EXTENSION name="xsl" level="required" /> 89 </PHP_EXTENSIONS> 90 </PLUGIN> 91 </COMPATIBILITY_MATRIX> 92 END; 93 $environemt = xmlize($xml); 94 $versions = get_list_of_environment_versions($environemt); 95 $this->assertCount(5, $versions); 96 $this->assertContains('1.9', $versions); 97 $this->assertContains('2.5', $versions); 98 $this->assertContains('2.6', $versions); 99 $this->assertContains('2.7', $versions); 100 $this->assertContains('all', $versions); 101 } 102 103 /** 104 * Test the environment_verify_plugin() function. 105 */ 106 public function test_verify_plugin() { 107 global $CFG; 108 require_once($CFG->libdir.'/environmentlib.php'); 109 // Build sample xmlised environment file fragments. 110 $plugin1xml = <<<END 111 <PLUGIN name="block_testcase"> 112 <PHP_EXTENSIONS> 113 <PHP_EXTENSION name="xsl" level="required" /> 114 </PHP_EXTENSIONS> 115 </PLUGIN> 116 END; 117 $plugin1 = xmlize($plugin1xml); 118 $plugin2xml = <<<END 119 <PLUGIN> 120 <PHP_EXTENSIONS> 121 <PHP_EXTENSION name="xsl" level="required" /> 122 </PHP_EXTENSIONS> 123 </PLUGIN> 124 END; 125 $plugin2 = xmlize($plugin2xml); 126 $this->assertTrue(environment_verify_plugin('block_testcase', $plugin1['PLUGIN'])); 127 $this->assertFalse(environment_verify_plugin('block_testcase', $plugin2['PLUGIN'])); 128 $this->assertFalse(environment_verify_plugin('mod_someother', $plugin1['PLUGIN'])); 129 $this->assertFalse(environment_verify_plugin('mod_someother', $plugin2['PLUGIN'])); 130 } 131 132 /** 133 * Test the restrict_php_version() function returns true if the current 134 * PHP version is greater than the restricted version 135 */ 136 public function test_restrict_php_version_greater_than_restricted_version() { 137 global $CFG; 138 require_once($CFG->libdir.'/environmentlib.php'); 139 140 $result = new environment_results('php'); 141 $delimiter = '.'; 142 // Get the current PHP version. 143 $currentversion = explode($delimiter, normalize_version(phpversion())); 144 // Lets drop back one major version to ensure we trip the restriction. 145 $currentversion[0]--; 146 $restrictedversion = implode($delimiter, $currentversion); 147 148 // Make sure the status is true before the test to see it flip to false. 149 $result->setStatus(true); 150 151 $this->assertTrue(restrict_php_version($result, $restrictedversion), 152 'restrict_php_version returns true if the current version exceeds the restricted version'); 153 } 154 155 /** 156 * Test the restrict_php_version() function returns true if the current 157 * PHP version is equal to the restricted version 158 */ 159 public function test_restrict_php_version_equal_to_restricted_version() { 160 global $CFG; 161 require_once($CFG->libdir.'/environmentlib.php'); 162 163 $result = new environment_results('php'); 164 // Get the current PHP version. 165 $currentversion = normalize_version(phpversion()); 166 167 // Make sure the status is true before the test to see it flip to false. 168 $result->setStatus(true); 169 170 $this->assertTrue(restrict_php_version($result, $currentversion), 171 'restrict_php_version returns true if the current version is equal to the restricted version'); 172 } 173 174 /** 175 * Test the restrict_php_version() function returns false if the current 176 * PHP version is less than the restricted version 177 */ 178 public function test_restrict_php_version_less_than_restricted_version() { 179 global $CFG; 180 require_once($CFG->libdir.'/environmentlib.php'); 181 182 $result = new environment_results('php'); 183 $delimiter = '.'; 184 // Get the current PHP version. 185 $currentversion = explode($delimiter, normalize_version(phpversion())); 186 // Lets increase the major version to ensure don't trip the restriction. 187 $currentversion[0]++; 188 $restrictedversion = implode($delimiter, $currentversion); 189 190 // Make sure the status is true before the test to see it flip to false. 191 $result->setStatus(true); 192 193 $this->assertFalse(restrict_php_version($result, $restrictedversion), 194 'restrict_php_version returns false if the current version is less than the restricted version'); 195 } 196 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Thu Aug 11 10:00:09 2016 | Cross-referenced by PHPXref 0.7.1 |