Commit 8a3c37cb0ae2c624f5ec47d316a20225ae45b5ed
1 parent
597bdf82
Update Pear Libraries
PT:1182700 Added Unit Tests for checking that the environment is properly configured in tests/env.php Updated by: Charl Joseph Mert Reviewed by Jarret Jordaan
Showing
7 changed files
with
730 additions
and
25 deletions
setup/wizard/steps/configuration.php
| ... | ... | @@ -390,7 +390,7 @@ class configuration extends Step |
| 390 | 390 | * @access private |
| 391 | 391 | * @return array Server settings |
| 392 | 392 | */ |
| 393 | - private function getServerInfo() | |
| 393 | + public function getServerInfo() | |
| 394 | 394 | { |
| 395 | 395 | $script = $_SERVER['SCRIPT_NAME']; |
| 396 | 396 | $file_system_root = realpath(SYSTEM_DIR); |
| ... | ... | @@ -432,24 +432,24 @@ class configuration extends Step |
| 432 | 432 | * @param string $fileSystemRoot The file system root of the installation |
| 433 | 433 | * @return array The path information |
| 434 | 434 | */ |
| 435 | - private function getPathInfo($fileSystemRoot) | |
| 435 | + public function getPathInfo($fileSystemRoot, $useRelative = true) | |
| 436 | 436 | { |
| 437 | 437 | if(isset($this->temp_variables['paths'])) { |
| 438 | 438 | if ($this->util->isMigration()) { // Check if its an upgrade |
| 439 | - $this->readConfigPath(); // Read contents of config-path file as only var Documents are used of old stack | |
| 439 | + $this->readConfigPath($useRelative); // Read contents of config-path file as only var Documents are used of old stack | |
| 440 | 440 | $this->readInstallation(); // Read values from config.ini of other installation and overwrite config-path's |
| 441 | - $dirs = $this->getFromConfigPath(); // Store contents | |
| 441 | + $dirs = $this->getFromConfigPath($useRelative); // Store contents | |
| 442 | 442 | } else { |
| 443 | 443 | $dirs = $this->temp_variables['paths']; // Pull from temp |
| 444 | 444 | } |
| 445 | 445 | } else { |
| 446 | 446 | if ($this->util->isMigration()) { // Check if its an upgrade |
| 447 | - $this->readConfigPath(); // Read contents of config-path file as only var Documents are used of old stack | |
| 447 | + $this->readConfigPath($useRelative); // Read contents of config-path file as only var Documents are used of old stack | |
| 448 | 448 | $this->readInstallation(); // Read values from config.ini of other installation |
| 449 | 449 | } else { |
| 450 | - $this->readConfigPath(); // Read contents of config-path file | |
| 450 | + $this->readConfigPath($useRelative); // Read contents of config-path file | |
| 451 | 451 | } |
| 452 | - $dirs = $this->getFromConfigPath(); // Store contents | |
| 452 | + $dirs = $this->getFromConfigPath($useRelative); // Store contents | |
| 453 | 453 | } |
| 454 | 454 | $varDirectory = $fileSystemRoot . DS . 'var'; |
| 455 | 455 | |
| ... | ... | @@ -489,12 +489,12 @@ class configuration extends Step |
| 489 | 489 | * @param none |
| 490 | 490 | * @return array The path information |
| 491 | 491 | */ |
| 492 | - private function getFromConfigPath() { | |
| 492 | + private function getFromConfigPath($useRelative = true) { | |
| 493 | 493 | $configs = array(); |
| 494 | 494 | if(isset($this->confpaths['configIni'])) { // Simple check to see if any paths were written |
| 495 | 495 | $configPath = $this->confpaths['configIni']; // Get absolute path |
| 496 | 496 | } else { |
| 497 | - $configPath = $this->readConfigPathIni(); //'${fileSystemRoot}/config/config.ini'; | |
| 497 | + $configPath = $this->readConfigPathIni($useRelative); //'${fileSystemRoot}/config/config.ini'; | |
| 498 | 498 | } |
| 499 | 499 | $configs['configFile'] = array('name' => 'Configuration File', 'setting' => 'configFile', 'path' => $configPath, 'create' => false, 'file'=>true); |
| 500 | 500 | if(isset($this->confpaths['Documents'])) { |
| ... | ... | @@ -573,12 +573,12 @@ class configuration extends Step |
| 573 | 573 | return true; |
| 574 | 574 | } |
| 575 | 575 | |
| 576 | - public function readConfigPathIni() { | |
| 576 | + public function readConfigPathIni($useRelative = true) { | |
| 577 | 577 | if(isset($this->temp_variables['paths']['configFile']['path'])) { |
| 578 | 578 | if($this->temp_variables['paths']['configFile']['path'] != '') |
| 579 | 579 | return $this->temp_variables['paths']['configFile']['path']; |
| 580 | 580 | } |
| 581 | - $configPath = $this->getContentPath(); | |
| 581 | + $configPath = $this->getContentPath($useRelative); | |
| 582 | 582 | if(!$configPath) { |
| 583 | 583 | return false; |
| 584 | 584 | } |
| ... | ... | @@ -627,8 +627,8 @@ class configuration extends Step |
| 627 | 627 | * @param none |
| 628 | 628 | * @return boolean |
| 629 | 629 | */ |
| 630 | - private function readConfigPath() { | |
| 631 | - $configPath = $this->getContentPath(); | |
| 630 | + private function readConfigPath($useRelative = true) { | |
| 631 | + $configPath = $this->getContentPath($useRelative); | |
| 632 | 632 | if(!$configPath) return false; |
| 633 | 633 | $data = $this->util->getFileByLine($configPath); |
| 634 | 634 | $firstline = true; |
| ... | ... | @@ -705,12 +705,24 @@ class configuration extends Step |
| 705 | 705 | * @param none |
| 706 | 706 | * @return mixed |
| 707 | 707 | */ |
| 708 | - public function getContentPath() { | |
| 709 | - $configPath = realpath('../../../config/config-path'); | |
| 708 | + public function getContentPath($useRelative = true) { | |
| 709 | + if ($useRelative) { | |
| 710 | + $configPath = realpath('../../../config/config-path'); | |
| 710 | 711 | if(!file_exists($configPath)) |
| 711 | - $configPath = realpath('../../config/config-path'); | |
| 712 | + $configPath = realpath('../../config/config-path'); | |
| 713 | + | |
| 712 | 714 | if(!file_exists($configPath)) return false; |
| 713 | - return $configPath; | |
| 715 | + return $configPath; | |
| 716 | + } else { | |
| 717 | + //Using absolute config path. From rootPath | |
| 718 | + $arrServerInfo = $this->getServerInfo(); | |
| 719 | + $configPath = realpath($arrServerInfo['file_system_root']['value'] . '/config/config-path'); | |
| 720 | + if(!file_exists($configPath)) | |
| 721 | + $configPath = realpath($arrServerInfo['file_system_root']['value'] . '/config/config-path'); | |
| 722 | + | |
| 723 | + if(!file_exists($configPath)) return false; | |
| 724 | + return $configPath; | |
| 725 | + } | |
| 714 | 726 | } |
| 715 | 727 | |
| 716 | 728 | public function getCachePath() { | ... | ... |
setup/wizard/steps/dependencies.php
| ... | ... | @@ -190,7 +190,7 @@ class dependencies extends Step |
| 190 | 190 | * @access private |
| 191 | 191 | * @return array The configurations list |
| 192 | 192 | */ |
| 193 | - private function checkPhpConfiguration() | |
| 193 | + public function checkPhpConfiguration() | |
| 194 | 194 | { |
| 195 | 195 | $configs = $this->getConfigurations(); |
| 196 | 196 | $this->temp_variables['php_con'] = 'tick'; |
| ... | ... | @@ -243,11 +243,11 @@ class dependencies extends Step |
| 243 | 243 | /** |
| 244 | 244 | * Check that the version of php is correct |
| 245 | 245 | * |
| 246 | - * @author KnowledgeTree Team | |
| 246 | + * @author KnowledgeTree Team | |
| 247 | 247 | * @access private |
| 248 | 248 | * @return array Version check result |
| 249 | 249 | */ |
| 250 | - private function checkPhpVersion() | |
| 250 | + public function checkPhpVersion() | |
| 251 | 251 | { |
| 252 | 252 | $phpversion = phpversion(); |
| 253 | 253 | $phpversion5 = version_compare($phpversion, $this->minPHPVersion, '>='); |
| ... | ... | @@ -279,7 +279,7 @@ class dependencies extends Step |
| 279 | 279 | * @param string $extension |
| 280 | 280 | * @return boolean |
| 281 | 281 | */ |
| 282 | - private function checkExtension($extension) | |
| 282 | + public function checkExtension($extension) | |
| 283 | 283 | { |
| 284 | 284 | if(extension_loaded($extension)){ |
| 285 | 285 | return true; |
| ... | ... | @@ -334,7 +334,7 @@ class dependencies extends Step |
| 334 | 334 | * @access private |
| 335 | 335 | * @return array |
| 336 | 336 | */ |
| 337 | - private function getRequiredExtensions() { | |
| 337 | + public function getRequiredExtensions() { | |
| 338 | 338 | $ext = array( |
| 339 | 339 | array('extension' => 'iconv', 'required' => 'no', 'name' => 'IconV', 'details' => 'Used for conversion between character sets.'), |
| 340 | 340 | array('extension' => 'mysql', 'required' => 'yes', 'name' => 'MySQL', 'details' => 'Used for accessing a MySQL database.'), |
| ... | ... | @@ -357,11 +357,11 @@ class dependencies extends Step |
| 357 | 357 | /** |
| 358 | 358 | * Get the recommended configuration settings |
| 359 | 359 | * |
| 360 | - * @author KnowledgeTree Team | |
| 360 | + * @author KnowledgeTree Team | |
| 361 | 361 | * @access private |
| 362 | 362 | * @return array |
| 363 | 363 | */ |
| 364 | - private function getConfigurations() | |
| 364 | + public function getConfigurations() | |
| 365 | 365 | { |
| 366 | 366 | $conf = array( |
| 367 | 367 | array('name' => 'Safe Mode', 'configuration' => 'safe_mode', 'recommended' => 'OFF', 'type' => 'bool'), |
| ... | ... | @@ -392,7 +392,7 @@ class dependencies extends Step |
| 392 | 392 | * @access private |
| 393 | 393 | * @return array |
| 394 | 394 | */ |
| 395 | - private function getLimits() | |
| 395 | + public function getLimits() | |
| 396 | 396 | { |
| 397 | 397 | return array( |
| 398 | 398 | array('name' => 'Maximum POST size', 'configuration' => 'post_max_size', 'recommended' => '32M', 'type' => 'int'), | ... | ... |
tests/env.php
0 → 100755
| 1 | +<?php | |
| 2 | + | |
| 3 | +require_once('test.php'); | |
| 4 | + | |
| 5 | +class UnitTests extends TestSuite { | |
| 6 | + function UnitTests() { | |
| 7 | + | |
| 8 | + $this->TestSuite('Unit tests (Environment)'); | |
| 9 | + | |
| 10 | + // Test PHP Version | |
| 11 | + | |
| 12 | + $this->addFile('env/testPhpVersion.php'); | |
| 13 | + | |
| 14 | + // Test PHP Extensions | |
| 15 | + $this->addFile('env/testPhpExtensions.php'); | |
| 16 | + | |
| 17 | + // Test PHP Configurations | |
| 18 | + $this->addFile('env/testPhpConfigurations.php'); | |
| 19 | + | |
| 20 | + // Test System Configurations | |
| 21 | + $this->addFile('env/testSystemConfigurations.php'); | |
| 22 | + } | |
| 23 | +} | |
| 24 | + | |
| 25 | +$test = &new UnitTests(); | |
| 26 | +if (SimpleReporter::inCli()) { | |
| 27 | + exit ($test->run(new KTTextReporter()) ? 0 : 1); | |
| 28 | +} | |
| 29 | + | |
| 30 | +// pass parameter ?show=all to display all passes | |
| 31 | +$param = (isset($_REQUEST['show']) && $_REQUEST['show'] == 'all') ? true : false; | |
| 32 | +$test->run(new KTHtmlReporter($param)); | |
| 33 | + | |
| 34 | +?> | ... | ... |
tests/env/testPhpConfigurations.php
0 → 100755
| 1 | +<?php | |
| 2 | +require_once (KT_DIR . '/tests/test.php'); | |
| 3 | +require_once (KT_DIR . '/setup/wizard/installUtil.php'); | |
| 4 | +require_once (KT_DIR . '/setup/wizard/step.php'); | |
| 5 | +require_once (KT_DIR . '/setup/wizard/steps/dependencies.php'); | |
| 6 | + | |
| 7 | +/** | |
| 8 | + * These are the unit tests for the KT environment | |
| 9 | + * | |
| 10 | + * This test can be run at any time to ensure the environment meets the requirements | |
| 11 | + * to properly run knowledgetree e.g. http://localhost/tests/env.php | |
| 12 | + * | |
| 13 | + */ | |
| 14 | +class EnvPhpConfigTestCase extends KTUnitTestCase { | |
| 15 | + | |
| 16 | + /** | |
| 17 | + * @var oDepends | |
| 18 | + */ | |
| 19 | + var $oDepends; | |
| 20 | + | |
| 21 | + /** | |
| 22 | + * @var arrConfigActual | |
| 23 | + */ | |
| 24 | + var $arrConfigActual; | |
| 25 | + | |
| 26 | + /** | |
| 27 | + * @var arrConfigRecommended | |
| 28 | + */ | |
| 29 | + var $arrConfigRecommended; | |
| 30 | + | |
| 31 | + /** | |
| 32 | + * @var safeMode | |
| 33 | + */ | |
| 34 | + var $safeMode; | |
| 35 | + | |
| 36 | + /** | |
| 37 | + * @var fileUploads | |
| 38 | + */ | |
| 39 | + var $fileUploads; | |
| 40 | + | |
| 41 | + /** | |
| 42 | + * @var magicQuotesGPC | |
| 43 | + */ | |
| 44 | + var $magicQuotesGPC; | |
| 45 | + | |
| 46 | + /** | |
| 47 | + * @var magicQuotesRuntime | |
| 48 | + */ | |
| 49 | + var $magicQuotesRuntime; | |
| 50 | + | |
| 51 | + /** | |
| 52 | + * @var registerGlobals | |
| 53 | + */ | |
| 54 | + var $registerGlobals; | |
| 55 | + | |
| 56 | + /** | |
| 57 | + * @var outputBuffering | |
| 58 | + */ | |
| 59 | + var $outputBuffering; | |
| 60 | + | |
| 61 | + /** | |
| 62 | + * @var sessionAutoStart | |
| 63 | + */ | |
| 64 | + var $sessionAutoStart; | |
| 65 | + | |
| 66 | + /** | |
| 67 | + * @var automaticPrependFile | |
| 68 | + */ | |
| 69 | + var $automaticPrependFile; | |
| 70 | + | |
| 71 | + /** | |
| 72 | + * @var automaticAppendFile | |
| 73 | + */ | |
| 74 | + var $automaticAppendFile; | |
| 75 | + | |
| 76 | + /** | |
| 77 | + * @var openBaseDirectory | |
| 78 | + */ | |
| 79 | + var $openBaseDirectory; | |
| 80 | + | |
| 81 | + /** | |
| 82 | + * @var defaultMimetype | |
| 83 | + */ | |
| 84 | + var $defaultMimetype; | |
| 85 | + | |
| 86 | + /** | |
| 87 | + * @var maximumPostSize | |
| 88 | + */ | |
| 89 | + var $maximumPostSize; | |
| 90 | + | |
| 91 | + /** | |
| 92 | + * @var maximumUploadSize | |
| 93 | + */ | |
| 94 | + var $maximumUploadSize; | |
| 95 | + | |
| 96 | + /** | |
| 97 | + * @var memoryLimit | |
| 98 | + */ | |
| 99 | + var $memoryLimit; | |
| 100 | + | |
| 101 | + | |
| 102 | + /** | |
| 103 | + * Setup the php configs to initialize the system checks. | |
| 104 | + * | |
| 105 | + */ | |
| 106 | + function setUp() { | |
| 107 | + $this->oDepends = new dependencies(); | |
| 108 | + $this->arrConfigRecommended = $this->oDepends->getConfigurations(); | |
| 109 | + $this->arrConfigLimits = $this->oDepends->getLimits(); | |
| 110 | + $this->arrConfigActual = $this->oDepends->checkPhpConfiguration(); | |
| 111 | + } | |
| 112 | + | |
| 113 | + /** | |
| 114 | + * Cleaning up | |
| 115 | + */ | |
| 116 | + function tearDown() { | |
| 117 | + $this->oDepends = null; | |
| 118 | + } | |
| 119 | + | |
| 120 | + function getRecommendedConfig($key) { | |
| 121 | + foreach ($this->arrConfigRecommended as $conf) { | |
| 122 | + if ($conf['configuration'] == $key) { | |
| 123 | + return $conf; | |
| 124 | + } | |
| 125 | + } | |
| 126 | + | |
| 127 | + foreach ($this->arrConfigLimits as $conf) { | |
| 128 | + if ($conf['configuration'] == $key) { | |
| 129 | + return $conf; | |
| 130 | + } | |
| 131 | + } | |
| 132 | + | |
| 133 | + return false; | |
| 134 | + } | |
| 135 | + | |
| 136 | + | |
| 137 | + function getActualConfig($key) { | |
| 138 | + foreach ($this->arrConfigActual as $conf) { | |
| 139 | + if ($conf['configuration'] == $key) { | |
| 140 | + return $conf; | |
| 141 | + } | |
| 142 | + } | |
| 143 | + return false; | |
| 144 | + } | |
| 145 | + | |
| 146 | + /** | |
| 147 | + * Testing safeMode | |
| 148 | + */ | |
| 149 | + function testSafeMode() { | |
| 150 | + $key = 'safe_mode'; | |
| 151 | + $actualConfig = $this->getActualConfig($key); | |
| 152 | + $requiredConfig = $this->getRecommendedConfig($key); | |
| 153 | + $this->assertEqual($actualConfig['setting'], $requiredConfig['recommended']); | |
| 154 | + } | |
| 155 | + | |
| 156 | + /** | |
| 157 | + * Testing fileUploads | |
| 158 | + */ | |
| 159 | + function testFileUploads() { | |
| 160 | + $key = 'file_uploads'; | |
| 161 | + $actualConfig = $this->getActualConfig($key); | |
| 162 | + $requiredConfig = $this->getRecommendedConfig($key); | |
| 163 | + $this->assertEqual($actualConfig['setting'], $requiredConfig['recommended']); | |
| 164 | + } | |
| 165 | + | |
| 166 | + /** | |
| 167 | + * Testing magicQuotesGPC | |
| 168 | + */ | |
| 169 | + function testMagicQuotesGPC() { | |
| 170 | + $key = 'magic_quotes_gpc'; | |
| 171 | + $actualConfig = $this->getActualConfig($key); | |
| 172 | + $requiredConfig = $this->getRecommendedConfig($key); | |
| 173 | + $this->assertEqual($actualConfig['setting'], $requiredConfig['recommended']); | |
| 174 | + } | |
| 175 | + | |
| 176 | + /** | |
| 177 | + * Testing magicQuotesRuntime | |
| 178 | + */ | |
| 179 | + function testMagicQuotesRuntime() { | |
| 180 | + $key = 'magic_quotes_runtime'; | |
| 181 | + $actualConfig = $this->getActualConfig($key); | |
| 182 | + $requiredConfig = $this->getRecommendedConfig($key); | |
| 183 | + $this->assertEqual($actualConfig['setting'], $requiredConfig['recommended']); | |
| 184 | + } | |
| 185 | + | |
| 186 | + /** | |
| 187 | + * Testing registerGlobals | |
| 188 | + */ | |
| 189 | + function testRegisterGlobals() { | |
| 190 | + $key = 'register_globals'; | |
| 191 | + $actualConfig = $this->getActualConfig($key); | |
| 192 | + $requiredConfig = $this->getRecommendedConfig($key); | |
| 193 | + $this->assertEqual($actualConfig['setting'], $requiredConfig['recommended']); | |
| 194 | + } | |
| 195 | + | |
| 196 | + /** | |
| 197 | + * Testing outputBuffering | |
| 198 | + */ | |
| 199 | + function testOutputBuffering() { | |
| 200 | + $key = 'output_buffering'; | |
| 201 | + $actualConfig = $this->getActualConfig($key); | |
| 202 | + $requiredConfig = $this->getRecommendedConfig($key); | |
| 203 | + $this->assertEqual($actualConfig['setting'], $requiredConfig['recommended']); | |
| 204 | + } | |
| 205 | + | |
| 206 | + /** | |
| 207 | + * Testing sessionAutoStart | |
| 208 | + */ | |
| 209 | + function testSessionAutoStart() { | |
| 210 | + $key = 'session.auto_start'; | |
| 211 | + $actualConfig = $this->getActualConfig($key); | |
| 212 | + $requiredConfig = $this->getRecommendedConfig($key); | |
| 213 | + $this->assertEqual($actualConfig['setting'], $requiredConfig['recommended']); | |
| 214 | + } | |
| 215 | + | |
| 216 | + /** | |
| 217 | + * Testing automaticPrependFile | |
| 218 | + */ | |
| 219 | + function testAutomaticPrependFile() { | |
| 220 | + $key = 'auto_prepend_file'; | |
| 221 | + $actualConfig = $this->getActualConfig($key); | |
| 222 | + $requiredConfig = $this->getRecommendedConfig($key); | |
| 223 | + $this->assertEqual($actualConfig['setting'], $requiredConfig['recommended']); | |
| 224 | + } | |
| 225 | + | |
| 226 | + /** | |
| 227 | + * Testing automaticAppendFile | |
| 228 | + */ | |
| 229 | + function testAutomaticAppendFile() { | |
| 230 | + $key = 'auto_append_file'; | |
| 231 | + $actualConfig = $this->getActualConfig($key); | |
| 232 | + $requiredConfig = $this->getRecommendedConfig($key); | |
| 233 | + $this->assertEqual($actualConfig['setting'], $requiredConfig['recommended']); | |
| 234 | + } | |
| 235 | + | |
| 236 | + /** | |
| 237 | + * Testing openBaseDirectory | |
| 238 | + */ | |
| 239 | + function testOpenBaseDirectory() { | |
| 240 | + $key = 'open_basedir'; | |
| 241 | + $actualConfig = $this->getActualConfig($key); | |
| 242 | + $requiredConfig = $this->getRecommendedConfig($key); | |
| 243 | + $this->assertEqual($actualConfig['setting'], $requiredConfig['recommended']); | |
| 244 | + } | |
| 245 | + | |
| 246 | + /** | |
| 247 | + * Testing defaultMimetype | |
| 248 | + */ | |
| 249 | + function testDefaultMimetype() { | |
| 250 | + $key = 'default_mimetype'; | |
| 251 | + $actualConfig = $this->getActualConfig($key); | |
| 252 | + $requiredConfig = $this->getRecommendedConfig($key); | |
| 253 | + $this->assertEqual($actualConfig['setting'], $requiredConfig['recommended']); | |
| 254 | + } | |
| 255 | + | |
| 256 | + function to_byte($size) { | |
| 257 | + $res = preg_match_all('/[a-z]/isU', $size, $matches, PREG_PATTERN_ORDER); | |
| 258 | + $indicator = $matches[0][0]; | |
| 259 | + if ($indicator == '') return false; | |
| 260 | + | |
| 261 | + switch ($indicator) { | |
| 262 | + case 'B': | |
| 263 | + return $size; | |
| 264 | + case 'KB': | |
| 265 | + return $size * (1024); | |
| 266 | + case 'K': | |
| 267 | + return $size * (1024); | |
| 268 | + case 'M': | |
| 269 | + return $size * (1024 * 1024); | |
| 270 | + case 'MB': | |
| 271 | + return $size * (1024 * 1024); | |
| 272 | + case 'G': | |
| 273 | + return $size * (1024 * 1024 * 1024); | |
| 274 | + case 'GB': | |
| 275 | + return $size * (1024 * 1024 * 1024); | |
| 276 | + case 'T': | |
| 277 | + return $size * (1024 * 1024 * 1024 * 1024); | |
| 278 | + case 'TB': | |
| 279 | + return $size * (1024 * 1024 * 1024 * 1024); | |
| 280 | + case 'P': | |
| 281 | + return $size * (1024 * 1024 * 1024 * 1024 * 1024); | |
| 282 | + case 'PB': | |
| 283 | + return $size * (1024 * 1024 * 1024 * 1024 * 1024); | |
| 284 | + case 'E': | |
| 285 | + return $size * (1024 * 1024 * 1024 * 1024 * 1024 * 1024); | |
| 286 | + case 'EB': | |
| 287 | + return $size * (1024 * 1024 * 1024 * 1024 * 1024 * 1024); | |
| 288 | + case 'Z': | |
| 289 | + return $size * (1024 * 1024 * 1024 * 1024 * 1024 * 1024 * 1024); | |
| 290 | + case 'ZB': | |
| 291 | + return $size * (1024 * 1024 * 1024 * 1024 * 1024 * 1024 * 1024); | |
| 292 | + case 'Y': | |
| 293 | + return $size * (1024 * 1024 * 1024 * 1024 * 1024 * 1024 * 1024 * 1024); | |
| 294 | + case 'YB': | |
| 295 | + return $size * (1024 * 1024 * 1024 * 1024 * 1024 * 1024 * 1024 * 1024); | |
| 296 | + default: | |
| 297 | + return $size; | |
| 298 | + | |
| 299 | + } | |
| 300 | + | |
| 301 | + //return $size ? round($size/pow(1024, ($i = floor(log($size, 1024)))), 2) . $filesizename[$i] : '0 Bytes'; | |
| 302 | + } | |
| 303 | + | |
| 304 | + /** | |
| 305 | + * Testing maximumPostSize | |
| 306 | + */ | |
| 307 | + function testMaximumPostSize() { | |
| 308 | + $key = 'post_max_size'; | |
| 309 | + $actualConfig = $this->getActualConfig($key); | |
| 310 | + $requiredConfig = $this->getRecommendedConfig($key); | |
| 311 | + | |
| 312 | + $byteSetting = $this->to_byte($actualConfig['setting']); | |
| 313 | + $byteRecommended = $this->to_byte($requiredConfig['recommended']); | |
| 314 | + //Testing that the byte conversion passed | |
| 315 | + $this->assertNotEqual($byteSetting, false, 'Could Not Convert Actual Setting to Bytes [' . $actualConfig['setting'] . ']'); | |
| 316 | + $result = ($byteSetting >= $byteRecommended); | |
| 317 | + $this->assertTrue($result, 'current php.ini conf value for '.$key.' ['.$actualConfig['setting'].'] is too small. The recommended size is ' . $requiredConfig['recommended']); | |
| 318 | + } | |
| 319 | + | |
| 320 | + /** | |
| 321 | + * Testing maximumUploadSize | |
| 322 | + */ | |
| 323 | + function testMaximumUploadSize() { | |
| 324 | + $key = 'upload_max_filesize'; | |
| 325 | + $actualConfig = $this->getActualConfig($key); | |
| 326 | + $requiredConfig = $this->getRecommendedConfig($key); | |
| 327 | + | |
| 328 | + $byteSetting = $this->to_byte($actualConfig['setting']); | |
| 329 | + $byteRecommended = $this->to_byte($requiredConfig['recommended']); | |
| 330 | + //Testing that the byte conversion passed | |
| 331 | + $this->assertNotEqual($byteSetting, false, 'Could Not Convert Actual Setting to Bytes [' . $actualConfig['setting'] . ']'); | |
| 332 | + $result = ($byteSetting >= $byteRecommended); | |
| 333 | + $this->assertTrue($result, 'current php.ini conf value for '.$key.' ['.$actualConfig['setting'].'] is too small. The recommended size is ' . $requiredConfig['recommended']); | |
| 334 | + } | |
| 335 | + | |
| 336 | + /** | |
| 337 | + * Testing memoryLimit | |
| 338 | + */ | |
| 339 | + function testMemoryLimit() { | |
| 340 | + $key = 'memory_limit'; | |
| 341 | + $actualConfig = $this->getActualConfig($key); | |
| 342 | + $requiredConfig = $this->getRecommendedConfig($key); | |
| 343 | + | |
| 344 | + $byteSetting = $this->to_byte($actualConfig['setting']); | |
| 345 | + $byteRecommended = $this->to_byte($requiredConfig['recommended']); | |
| 346 | + //Testing that the byte conversion passed | |
| 347 | + $this->assertNotEqual($byteSetting, false, 'Could Not Convert Actual Setting to Bytes [' . $actualConfig['setting'] . ']'); | |
| 348 | + $result = ($byteSetting >= $byteRecommended); | |
| 349 | + $this->assertTrue($result, 'current php.ini conf value for '.$key.' ['.$actualConfig['setting'].'] is too small. The recommended size is ' . $requiredConfig['recommended']); | |
| 350 | + } | |
| 351 | + | |
| 352 | +} | |
| 353 | +?> | |
| 0 | 354 | \ No newline at end of file | ... | ... |
tests/env/testPhpExtensions.php
0 → 100755
| 1 | +<?php | |
| 2 | +require_once (KT_DIR . '/tests/test.php'); | |
| 3 | +require_once (KT_DIR . '/setup/wizard/installUtil.php'); | |
| 4 | +require_once (KT_DIR . '/setup/wizard/step.php'); | |
| 5 | +require_once (KT_DIR . '/setup/wizard/steps/dependencies.php'); | |
| 6 | + | |
| 7 | +/** | |
| 8 | + * These are the unit tests for the KT environment | |
| 9 | + * | |
| 10 | + * This test can be run at any time to ensure the environment meets the requirements | |
| 11 | + * to properly run knowledgetree e.g. http://localhost/tests/env.php | |
| 12 | + * | |
| 13 | + */ | |
| 14 | +class EnvPhpExtensionsTestCase extends KTUnitTestCase { | |
| 15 | + | |
| 16 | + /** | |
| 17 | + * @var oDepends | |
| 18 | + */ | |
| 19 | + var $oDepends; | |
| 20 | + | |
| 21 | + /** | |
| 22 | + * @var arrConfigActual | |
| 23 | + */ | |
| 24 | + var $arrRequiredExtensions; | |
| 25 | + | |
| 26 | + /** | |
| 27 | + * Setup the php configs to initialize the system checks. | |
| 28 | + * | |
| 29 | + */ | |
| 30 | + function setUp() { | |
| 31 | + $this->oDepends = new dependencies(); | |
| 32 | + $this->arrRequiredExtensions = $this->oDepends->getRequiredExtensions(); | |
| 33 | + } | |
| 34 | + | |
| 35 | + /** | |
| 36 | + * Cleaning up | |
| 37 | + */ | |
| 38 | + function tearDown() { | |
| 39 | + $this->oDepends = null; | |
| 40 | + } | |
| 41 | + | |
| 42 | + /** | |
| 43 | + * Testing extensions | |
| 44 | + */ | |
| 45 | + function testExtensions() { | |
| 46 | + foreach ($this->arrRequiredExtensions as $ext) { | |
| 47 | + $ext['available'] = 'no'; | |
| 48 | + if($this->oDepends->checkExtension($ext['extension'])){ | |
| 49 | + $ext['available'] = 'yes'; | |
| 50 | + } else { | |
| 51 | + if($ext['required'] == 'no') { | |
| 52 | + $errorMsg = '['.$ext['extension'].'] Missing optional extension: '.$ext['name']; | |
| 53 | + } else { | |
| 54 | + $errorMsg = '['.$ext['extension'].'] Missing required extension: '.$ext['name']; | |
| 55 | + } | |
| 56 | + } | |
| 57 | + $this->assertEqual($ext['available'], 'yes', $errorMsg); | |
| 58 | + } | |
| 59 | + } | |
| 60 | + | |
| 61 | + | |
| 62 | + public function getExtension($key) { | |
| 63 | + foreach ($this->arrRequiredExtensions as $ext) { | |
| 64 | + if ($ext['extension'] == $key) { | |
| 65 | + return $ext; | |
| 66 | + } | |
| 67 | + } | |
| 68 | + return false; | |
| 69 | + } | |
| 70 | + | |
| 71 | + /** | |
| 72 | + * Testing IconV | |
| 73 | + */ | |
| 74 | + function testIconV() { | |
| 75 | + $key = 'iconv'; | |
| 76 | + $ext = $this->getExtension($key); | |
| 77 | + $errorMsg = '['.$ext['extension'].'] Missing optional extension: '.$ext['name']; | |
| 78 | + $this->assertEqual($this->oDepends->checkExtension($ext['extension']), true, $errorMsg); | |
| 79 | + } | |
| 80 | + | |
| 81 | + /** | |
| 82 | + * Testing MySQL | |
| 83 | + */ | |
| 84 | + function testMySQL() { | |
| 85 | + $key = 'mysql'; | |
| 86 | + $ext = $this->getExtension($key); | |
| 87 | + $errorMsg = '['.$ext['extension'].'] Missing required extension: '.$ext['name']; | |
| 88 | + $this->assertEqual($this->oDepends->checkExtension($ext['extension']), true, $errorMsg); | |
| 89 | + } | |
| 90 | + | |
| 91 | + /** | |
| 92 | + * Testing cURL | |
| 93 | + */ | |
| 94 | + function testcURL() { | |
| 95 | + $key = 'curl'; | |
| 96 | + $ext = $this->getExtension($key); | |
| 97 | + $errorMsg = '['.$ext['extension'].'] Missing required extension: '.$ext['name']; | |
| 98 | + $this->assertEqual($this->oDepends->checkExtension($ext['extension']), true, $errorMsg); | |
| 99 | + } | |
| 100 | + | |
| 101 | + /** | |
| 102 | + * Testing XMLRPC | |
| 103 | + */ | |
| 104 | + function testXMLRPC() { | |
| 105 | + $key = 'xmlrpc'; | |
| 106 | + $ext = $this->getExtension($key); | |
| 107 | + $errorMsg = '['.$ext['extension'].'] Missing required extension: '.$ext['name']; | |
| 108 | + $this->assertEqual($this->oDepends->checkExtension($ext['extension']), true, $errorMsg); | |
| 109 | + } | |
| 110 | + | |
| 111 | + | |
| 112 | + /** | |
| 113 | + * Testing Multi Byte Strings | |
| 114 | + */ | |
| 115 | + function testMultiByteStrings() { | |
| 116 | + $key = 'mbstring'; | |
| 117 | + $ext = $this->getExtension($key); | |
| 118 | + $errorMsg = '['.$ext['extension'].'] Missing optional extension: '.$ext['name']; | |
| 119 | + $this->assertEqual($this->oDepends->checkExtension($ext['extension']), true, $errorMsg); | |
| 120 | + } | |
| 121 | + | |
| 122 | + /** | |
| 123 | + * Testing LDAP | |
| 124 | + */ | |
| 125 | + function testLDAP() { | |
| 126 | + $key = 'ldap'; | |
| 127 | + $ext = $this->getExtension($key); | |
| 128 | + $errorMsg = '['.$ext['extension'].'] Missing optional extension: '.$ext['name']; | |
| 129 | + $this->assertEqual($this->oDepends->checkExtension($ext['extension']), true, $errorMsg); | |
| 130 | + } | |
| 131 | + | |
| 132 | + /** | |
| 133 | + * Testing JSON | |
| 134 | + */ | |
| 135 | + function testJSON() { | |
| 136 | + $key = 'json'; | |
| 137 | + $ext = $this->getExtension($key); | |
| 138 | + $errorMsg = '['.$ext['extension'].'] Missing required extension: '.$ext['name']; | |
| 139 | + $this->assertEqual($this->oDepends->checkExtension($ext['extension']), true, $errorMsg); | |
| 140 | + } | |
| 141 | + | |
| 142 | + /** | |
| 143 | + * Testing Open SSL | |
| 144 | + */ | |
| 145 | + function testOpenSSL() { | |
| 146 | + $key = 'openssl'; | |
| 147 | + $ext = $this->getExtension($key); | |
| 148 | + $errorMsg = '['.$ext['extension'].'] Missing optional extension: '.$ext['name']; | |
| 149 | + $this->assertEqual($this->oDepends->checkExtension($ext['extension']), true, $errorMsg); | |
| 150 | + } | |
| 151 | + | |
| 152 | +} | |
| 153 | +?> | |
| 0 | 154 | \ No newline at end of file | ... | ... |
tests/env/testPhpVersion.php
0 → 100755
| 1 | +<?php | |
| 2 | +require_once (KT_DIR . '/tests/test.php'); | |
| 3 | +require_once (KT_DIR . '/setup/wizard/installUtil.php'); | |
| 4 | +require_once (KT_DIR . '/setup/wizard/step.php'); | |
| 5 | +require_once (KT_DIR . '/setup/wizard/steps/dependencies.php'); | |
| 6 | + | |
| 7 | +/** | |
| 8 | + * These are the unit tests for the KT environment | |
| 9 | + * | |
| 10 | + * This test can be run at any time to ensure the environment meets the requirements | |
| 11 | + * to properly run knowledgetree e.g. http://localhost/tests/env.php | |
| 12 | + * | |
| 13 | + */ | |
| 14 | +class EnvPhpVersionTestCase extends KTUnitTestCase { | |
| 15 | + | |
| 16 | + /** | |
| 17 | + * @var oDepends | |
| 18 | + */ | |
| 19 | + var $oDepends; | |
| 20 | + | |
| 21 | + /** | |
| 22 | + * @var phpVersion | |
| 23 | + */ | |
| 24 | + var $phpVersion; | |
| 25 | + | |
| 26 | + /** | |
| 27 | + * Setup | |
| 28 | + * | |
| 29 | + */ | |
| 30 | + function setUp() { | |
| 31 | + $this->oDepends = new dependencies(); | |
| 32 | + } | |
| 33 | + | |
| 34 | + /** | |
| 35 | + * Cleanup | |
| 36 | + * | |
| 37 | + */ | |
| 38 | + function tearDown() { | |
| 39 | + $this->oDepends = null; | |
| 40 | + } | |
| 41 | + | |
| 42 | + /** | |
| 43 | + * Testing PHP Version | |
| 44 | + */ | |
| 45 | + function testPhpVersion() | |
| 46 | + { | |
| 47 | + $this->phpVersion = $this->oDepends->checkPhpVersion(); | |
| 48 | + $this->assertEqual($this->phpVersion['class'], 'tick'); | |
| 49 | + } | |
| 50 | + | |
| 51 | +} | |
| 52 | +?> | |
| 0 | 53 | \ No newline at end of file | ... | ... |
tests/env/testSystemConfigurations.php
0 → 100644
| 1 | +<?php | |
| 2 | +require_once (KT_DIR . '/tests/test.php'); | |
| 3 | +require_once (KT_DIR . '/setup/wizard/installUtil.php'); | |
| 4 | +require_once (KT_DIR . '/setup/wizard/step.php'); | |
| 5 | +require_once (KT_DIR . '/setup/wizard/steps/configuration.php'); | |
| 6 | + | |
| 7 | +/** | |
| 8 | + * These are the unit tests for the KT environment | |
| 9 | + * | |
| 10 | + * This test can be run at any time to ensure the environment meets the requirements | |
| 11 | + * to properly run knowledgetree e.g. http://localhost/tests/env.php | |
| 12 | + * | |
| 13 | + */ | |
| 14 | +class EnvPhpSystemTestCase extends KTUnitTestCase { | |
| 15 | + | |
| 16 | + /** | |
| 17 | + * @var oConfig | |
| 18 | + */ | |
| 19 | + var $oConfig; | |
| 20 | + | |
| 21 | + /** | |
| 22 | + * @var memoryLimit | |
| 23 | + */ | |
| 24 | + var $arrServerInfo; | |
| 25 | + | |
| 26 | + | |
| 27 | + /** | |
| 28 | + * Setup the php configs to initialize the system checks. | |
| 29 | + * | |
| 30 | + */ | |
| 31 | + function setUp() { | |
| 32 | + $this->oConfig = new configuration(); | |
| 33 | + $this->arrServerInfo = $this->oConfig->getServerInfo(); | |
| 34 | + $this->arrPathInfo = $this->oConfig->getPathInfo($this->arrServerInfo['file_system_root']['value'], false); | |
| 35 | + } | |
| 36 | + | |
| 37 | + /** | |
| 38 | + * Cleaning up | |
| 39 | + */ | |
| 40 | + function tearDown() { | |
| 41 | + $this->oConfig = null; | |
| 42 | + } | |
| 43 | + | |
| 44 | + /** | |
| 45 | + * Testing configFile | |
| 46 | + */ | |
| 47 | + function testConfigFile() { | |
| 48 | + $key = 'configFile'; | |
| 49 | + $this->assertEqual($this->arrPathInfo[$key]['class'], 'tick', $this->arrPathInfo[$key]['msg']); | |
| 50 | + } | |
| 51 | + | |
| 52 | + /** | |
| 53 | + * Testing documentRoot | |
| 54 | + */ | |
| 55 | + function testDocumentRoot() { | |
| 56 | + $key = 'documentRoot'; | |
| 57 | + $this->assertEqual($this->arrPathInfo[$key]['class'], 'tick', $this->arrPathInfo[$key]['msg']); | |
| 58 | + } | |
| 59 | + | |
| 60 | + /** | |
| 61 | + * Testing logDirectory | |
| 62 | + */ | |
| 63 | + function testLogDirectory() { | |
| 64 | + $key = 'logDirectory'; | |
| 65 | + $this->assertEqual($this->arrPathInfo[$key]['class'], 'tick', $this->arrPathInfo[$key]['msg']); | |
| 66 | + } | |
| 67 | + | |
| 68 | + /** | |
| 69 | + * Testing tmpDirectory | |
| 70 | + */ | |
| 71 | + function testTmpDirectory() { | |
| 72 | + $key = 'tmpDirectory'; | |
| 73 | + $this->assertEqual($this->arrPathInfo[$key]['class'], 'tick', $this->arrPathInfo[$key]['msg']); | |
| 74 | + } | |
| 75 | + | |
| 76 | + /** | |
| 77 | + * Testing cacheDirectory | |
| 78 | + */ | |
| 79 | + function testCacheDirectory() { | |
| 80 | + $key = 'cacheDirectory'; | |
| 81 | + $this->assertEqual($this->arrPathInfo[$key]['class'], 'tick', $this->arrPathInfo[$key]['msg']); | |
| 82 | + } | |
| 83 | + | |
| 84 | + /** | |
| 85 | + * Testing uploadDirectory | |
| 86 | + */ | |
| 87 | + function testUploadDirectory() { | |
| 88 | + $key = 'uploadDirectory'; | |
| 89 | + $this->assertEqual($this->arrPathInfo[$key]['class'], 'tick', $this->arrPathInfo[$key]['msg']); | |
| 90 | + } | |
| 91 | + | |
| 92 | + /** | |
| 93 | + * Testing varDirectory | |
| 94 | + */ | |
| 95 | + function testvarDirectory() { | |
| 96 | + $key = 'varDirectory'; | |
| 97 | + $this->assertEqual($this->arrPathInfo[$key]['class'], 'tick', $this->arrPathInfo[$key]['msg']); | |
| 98 | + } | |
| 99 | + | |
| 100 | +} | |
| 101 | +?> | |
| 0 | 102 | \ No newline at end of file | ... | ... |