diff --git a/setup/wizard/steps/configuration.php b/setup/wizard/steps/configuration.php index a29c0e5..6f812db 100644 --- a/setup/wizard/steps/configuration.php +++ b/setup/wizard/steps/configuration.php @@ -390,7 +390,7 @@ class configuration extends Step * @access private * @return array Server settings */ - private function getServerInfo() + public function getServerInfo() { $script = $_SERVER['SCRIPT_NAME']; $file_system_root = realpath(SYSTEM_DIR); @@ -432,24 +432,24 @@ class configuration extends Step * @param string $fileSystemRoot The file system root of the installation * @return array The path information */ - private function getPathInfo($fileSystemRoot) + public function getPathInfo($fileSystemRoot, $useRelative = true) { if(isset($this->temp_variables['paths'])) { if ($this->util->isMigration()) { // Check if its an upgrade - $this->readConfigPath(); // Read contents of config-path file as only var Documents are used of old stack + $this->readConfigPath($useRelative); // Read contents of config-path file as only var Documents are used of old stack $this->readInstallation(); // Read values from config.ini of other installation and overwrite config-path's - $dirs = $this->getFromConfigPath(); // Store contents + $dirs = $this->getFromConfigPath($useRelative); // Store contents } else { $dirs = $this->temp_variables['paths']; // Pull from temp } } else { if ($this->util->isMigration()) { // Check if its an upgrade - $this->readConfigPath(); // Read contents of config-path file as only var Documents are used of old stack + $this->readConfigPath($useRelative); // Read contents of config-path file as only var Documents are used of old stack $this->readInstallation(); // Read values from config.ini of other installation } else { - $this->readConfigPath(); // Read contents of config-path file + $this->readConfigPath($useRelative); // Read contents of config-path file } - $dirs = $this->getFromConfigPath(); // Store contents + $dirs = $this->getFromConfigPath($useRelative); // Store contents } $varDirectory = $fileSystemRoot . DS . 'var'; @@ -489,12 +489,12 @@ class configuration extends Step * @param none * @return array The path information */ - private function getFromConfigPath() { + private function getFromConfigPath($useRelative = true) { $configs = array(); if(isset($this->confpaths['configIni'])) { // Simple check to see if any paths were written $configPath = $this->confpaths['configIni']; // Get absolute path } else { - $configPath = $this->readConfigPathIni(); //'${fileSystemRoot}/config/config.ini'; + $configPath = $this->readConfigPathIni($useRelative); //'${fileSystemRoot}/config/config.ini'; } $configs['configFile'] = array('name' => 'Configuration File', 'setting' => 'configFile', 'path' => $configPath, 'create' => false, 'file'=>true); if(isset($this->confpaths['Documents'])) { @@ -573,12 +573,12 @@ class configuration extends Step return true; } - public function readConfigPathIni() { + public function readConfigPathIni($useRelative = true) { if(isset($this->temp_variables['paths']['configFile']['path'])) { if($this->temp_variables['paths']['configFile']['path'] != '') return $this->temp_variables['paths']['configFile']['path']; } - $configPath = $this->getContentPath(); + $configPath = $this->getContentPath($useRelative); if(!$configPath) { return false; } @@ -627,8 +627,8 @@ class configuration extends Step * @param none * @return boolean */ - private function readConfigPath() { - $configPath = $this->getContentPath(); + private function readConfigPath($useRelative = true) { + $configPath = $this->getContentPath($useRelative); if(!$configPath) return false; $data = $this->util->getFileByLine($configPath); $firstline = true; @@ -705,12 +705,24 @@ class configuration extends Step * @param none * @return mixed */ - public function getContentPath() { - $configPath = realpath('../../../config/config-path'); + public function getContentPath($useRelative = true) { + if ($useRelative) { + $configPath = realpath('../../../config/config-path'); if(!file_exists($configPath)) - $configPath = realpath('../../config/config-path'); + $configPath = realpath('../../config/config-path'); + if(!file_exists($configPath)) return false; - return $configPath; + return $configPath; + } else { + //Using absolute config path. From rootPath + $arrServerInfo = $this->getServerInfo(); + $configPath = realpath($arrServerInfo['file_system_root']['value'] . '/config/config-path'); + if(!file_exists($configPath)) + $configPath = realpath($arrServerInfo['file_system_root']['value'] . '/config/config-path'); + + if(!file_exists($configPath)) return false; + return $configPath; + } } public function getCachePath() { diff --git a/setup/wizard/steps/dependencies.php b/setup/wizard/steps/dependencies.php index d29a12b..b16671b 100644 --- a/setup/wizard/steps/dependencies.php +++ b/setup/wizard/steps/dependencies.php @@ -190,7 +190,7 @@ class dependencies extends Step * @access private * @return array The configurations list */ - private function checkPhpConfiguration() + public function checkPhpConfiguration() { $configs = $this->getConfigurations(); $this->temp_variables['php_con'] = 'tick'; @@ -243,11 +243,11 @@ class dependencies extends Step /** * Check that the version of php is correct * - * @author KnowledgeTree Team + * @author KnowledgeTree Team * @access private * @return array Version check result */ - private function checkPhpVersion() + public function checkPhpVersion() { $phpversion = phpversion(); $phpversion5 = version_compare($phpversion, $this->minPHPVersion, '>='); @@ -279,7 +279,7 @@ class dependencies extends Step * @param string $extension * @return boolean */ - private function checkExtension($extension) + public function checkExtension($extension) { if(extension_loaded($extension)){ return true; @@ -334,7 +334,7 @@ class dependencies extends Step * @access private * @return array */ - private function getRequiredExtensions() { + public function getRequiredExtensions() { $ext = array( array('extension' => 'iconv', 'required' => 'no', 'name' => 'IconV', 'details' => 'Used for conversion between character sets.'), array('extension' => 'mysql', 'required' => 'yes', 'name' => 'MySQL', 'details' => 'Used for accessing a MySQL database.'), @@ -357,11 +357,11 @@ class dependencies extends Step /** * Get the recommended configuration settings * - * @author KnowledgeTree Team + * @author KnowledgeTree Team * @access private * @return array */ - private function getConfigurations() + public function getConfigurations() { $conf = array( array('name' => 'Safe Mode', 'configuration' => 'safe_mode', 'recommended' => 'OFF', 'type' => 'bool'), @@ -392,7 +392,7 @@ class dependencies extends Step * @access private * @return array */ - private function getLimits() + public function getLimits() { return array( array('name' => 'Maximum POST size', 'configuration' => 'post_max_size', 'recommended' => '32M', 'type' => 'int'), diff --git a/tests/env.php b/tests/env.php new file mode 100755 index 0000000..e5dc117 --- /dev/null +++ b/tests/env.php @@ -0,0 +1,34 @@ +TestSuite('Unit tests (Environment)'); + + // Test PHP Version + + $this->addFile('env/testPhpVersion.php'); + + // Test PHP Extensions + $this->addFile('env/testPhpExtensions.php'); + + // Test PHP Configurations + $this->addFile('env/testPhpConfigurations.php'); + + // Test System Configurations + $this->addFile('env/testSystemConfigurations.php'); + } +} + +$test = &new UnitTests(); +if (SimpleReporter::inCli()) { + exit ($test->run(new KTTextReporter()) ? 0 : 1); +} + +// pass parameter ?show=all to display all passes +$param = (isset($_REQUEST['show']) && $_REQUEST['show'] == 'all') ? true : false; +$test->run(new KTHtmlReporter($param)); + +?> diff --git a/tests/env/testPhpConfigurations.php b/tests/env/testPhpConfigurations.php new file mode 100755 index 0000000..806f925 --- /dev/null +++ b/tests/env/testPhpConfigurations.php @@ -0,0 +1,353 @@ +oDepends = new dependencies(); + $this->arrConfigRecommended = $this->oDepends->getConfigurations(); + $this->arrConfigLimits = $this->oDepends->getLimits(); + $this->arrConfigActual = $this->oDepends->checkPhpConfiguration(); + } + + /** + * Cleaning up + */ + function tearDown() { + $this->oDepends = null; + } + + function getRecommendedConfig($key) { + foreach ($this->arrConfigRecommended as $conf) { + if ($conf['configuration'] == $key) { + return $conf; + } + } + + foreach ($this->arrConfigLimits as $conf) { + if ($conf['configuration'] == $key) { + return $conf; + } + } + + return false; + } + + + function getActualConfig($key) { + foreach ($this->arrConfigActual as $conf) { + if ($conf['configuration'] == $key) { + return $conf; + } + } + return false; + } + + /** + * Testing safeMode + */ + function testSafeMode() { + $key = 'safe_mode'; + $actualConfig = $this->getActualConfig($key); + $requiredConfig = $this->getRecommendedConfig($key); + $this->assertEqual($actualConfig['setting'], $requiredConfig['recommended']); + } + + /** + * Testing fileUploads + */ + function testFileUploads() { + $key = 'file_uploads'; + $actualConfig = $this->getActualConfig($key); + $requiredConfig = $this->getRecommendedConfig($key); + $this->assertEqual($actualConfig['setting'], $requiredConfig['recommended']); + } + + /** + * Testing magicQuotesGPC + */ + function testMagicQuotesGPC() { + $key = 'magic_quotes_gpc'; + $actualConfig = $this->getActualConfig($key); + $requiredConfig = $this->getRecommendedConfig($key); + $this->assertEqual($actualConfig['setting'], $requiredConfig['recommended']); + } + + /** + * Testing magicQuotesRuntime + */ + function testMagicQuotesRuntime() { + $key = 'magic_quotes_runtime'; + $actualConfig = $this->getActualConfig($key); + $requiredConfig = $this->getRecommendedConfig($key); + $this->assertEqual($actualConfig['setting'], $requiredConfig['recommended']); + } + + /** + * Testing registerGlobals + */ + function testRegisterGlobals() { + $key = 'register_globals'; + $actualConfig = $this->getActualConfig($key); + $requiredConfig = $this->getRecommendedConfig($key); + $this->assertEqual($actualConfig['setting'], $requiredConfig['recommended']); + } + + /** + * Testing outputBuffering + */ + function testOutputBuffering() { + $key = 'output_buffering'; + $actualConfig = $this->getActualConfig($key); + $requiredConfig = $this->getRecommendedConfig($key); + $this->assertEqual($actualConfig['setting'], $requiredConfig['recommended']); + } + + /** + * Testing sessionAutoStart + */ + function testSessionAutoStart() { + $key = 'session.auto_start'; + $actualConfig = $this->getActualConfig($key); + $requiredConfig = $this->getRecommendedConfig($key); + $this->assertEqual($actualConfig['setting'], $requiredConfig['recommended']); + } + + /** + * Testing automaticPrependFile + */ + function testAutomaticPrependFile() { + $key = 'auto_prepend_file'; + $actualConfig = $this->getActualConfig($key); + $requiredConfig = $this->getRecommendedConfig($key); + $this->assertEqual($actualConfig['setting'], $requiredConfig['recommended']); + } + + /** + * Testing automaticAppendFile + */ + function testAutomaticAppendFile() { + $key = 'auto_append_file'; + $actualConfig = $this->getActualConfig($key); + $requiredConfig = $this->getRecommendedConfig($key); + $this->assertEqual($actualConfig['setting'], $requiredConfig['recommended']); + } + + /** + * Testing openBaseDirectory + */ + function testOpenBaseDirectory() { + $key = 'open_basedir'; + $actualConfig = $this->getActualConfig($key); + $requiredConfig = $this->getRecommendedConfig($key); + $this->assertEqual($actualConfig['setting'], $requiredConfig['recommended']); + } + + /** + * Testing defaultMimetype + */ + function testDefaultMimetype() { + $key = 'default_mimetype'; + $actualConfig = $this->getActualConfig($key); + $requiredConfig = $this->getRecommendedConfig($key); + $this->assertEqual($actualConfig['setting'], $requiredConfig['recommended']); + } + + function to_byte($size) { + $res = preg_match_all('/[a-z]/isU', $size, $matches, PREG_PATTERN_ORDER); + $indicator = $matches[0][0]; + if ($indicator == '') return false; + + switch ($indicator) { + case 'B': + return $size; + case 'KB': + return $size * (1024); + case 'K': + return $size * (1024); + case 'M': + return $size * (1024 * 1024); + case 'MB': + return $size * (1024 * 1024); + case 'G': + return $size * (1024 * 1024 * 1024); + case 'GB': + return $size * (1024 * 1024 * 1024); + case 'T': + return $size * (1024 * 1024 * 1024 * 1024); + case 'TB': + return $size * (1024 * 1024 * 1024 * 1024); + case 'P': + return $size * (1024 * 1024 * 1024 * 1024 * 1024); + case 'PB': + return $size * (1024 * 1024 * 1024 * 1024 * 1024); + case 'E': + return $size * (1024 * 1024 * 1024 * 1024 * 1024 * 1024); + case 'EB': + return $size * (1024 * 1024 * 1024 * 1024 * 1024 * 1024); + case 'Z': + return $size * (1024 * 1024 * 1024 * 1024 * 1024 * 1024 * 1024); + case 'ZB': + return $size * (1024 * 1024 * 1024 * 1024 * 1024 * 1024 * 1024); + case 'Y': + return $size * (1024 * 1024 * 1024 * 1024 * 1024 * 1024 * 1024 * 1024); + case 'YB': + return $size * (1024 * 1024 * 1024 * 1024 * 1024 * 1024 * 1024 * 1024); + default: + return $size; + + } + + //return $size ? round($size/pow(1024, ($i = floor(log($size, 1024)))), 2) . $filesizename[$i] : '0 Bytes'; + } + + /** + * Testing maximumPostSize + */ + function testMaximumPostSize() { + $key = 'post_max_size'; + $actualConfig = $this->getActualConfig($key); + $requiredConfig = $this->getRecommendedConfig($key); + + $byteSetting = $this->to_byte($actualConfig['setting']); + $byteRecommended = $this->to_byte($requiredConfig['recommended']); + //Testing that the byte conversion passed + $this->assertNotEqual($byteSetting, false, 'Could Not Convert Actual Setting to Bytes [' . $actualConfig['setting'] . ']'); + $result = ($byteSetting >= $byteRecommended); + $this->assertTrue($result, 'current php.ini conf value for '.$key.' ['.$actualConfig['setting'].'] is too small. The recommended size is ' . $requiredConfig['recommended']); + } + + /** + * Testing maximumUploadSize + */ + function testMaximumUploadSize() { + $key = 'upload_max_filesize'; + $actualConfig = $this->getActualConfig($key); + $requiredConfig = $this->getRecommendedConfig($key); + + $byteSetting = $this->to_byte($actualConfig['setting']); + $byteRecommended = $this->to_byte($requiredConfig['recommended']); + //Testing that the byte conversion passed + $this->assertNotEqual($byteSetting, false, 'Could Not Convert Actual Setting to Bytes [' . $actualConfig['setting'] . ']'); + $result = ($byteSetting >= $byteRecommended); + $this->assertTrue($result, 'current php.ini conf value for '.$key.' ['.$actualConfig['setting'].'] is too small. The recommended size is ' . $requiredConfig['recommended']); + } + + /** + * Testing memoryLimit + */ + function testMemoryLimit() { + $key = 'memory_limit'; + $actualConfig = $this->getActualConfig($key); + $requiredConfig = $this->getRecommendedConfig($key); + + $byteSetting = $this->to_byte($actualConfig['setting']); + $byteRecommended = $this->to_byte($requiredConfig['recommended']); + //Testing that the byte conversion passed + $this->assertNotEqual($byteSetting, false, 'Could Not Convert Actual Setting to Bytes [' . $actualConfig['setting'] . ']'); + $result = ($byteSetting >= $byteRecommended); + $this->assertTrue($result, 'current php.ini conf value for '.$key.' ['.$actualConfig['setting'].'] is too small. The recommended size is ' . $requiredConfig['recommended']); + } + +} +?> \ No newline at end of file diff --git a/tests/env/testPhpExtensions.php b/tests/env/testPhpExtensions.php new file mode 100755 index 0000000..48e5f3e --- /dev/null +++ b/tests/env/testPhpExtensions.php @@ -0,0 +1,153 @@ +oDepends = new dependencies(); + $this->arrRequiredExtensions = $this->oDepends->getRequiredExtensions(); + } + + /** + * Cleaning up + */ + function tearDown() { + $this->oDepends = null; + } + + /** + * Testing extensions + */ + function testExtensions() { + foreach ($this->arrRequiredExtensions as $ext) { + $ext['available'] = 'no'; + if($this->oDepends->checkExtension($ext['extension'])){ + $ext['available'] = 'yes'; + } else { + if($ext['required'] == 'no') { + $errorMsg = '['.$ext['extension'].'] Missing optional extension: '.$ext['name']; + } else { + $errorMsg = '['.$ext['extension'].'] Missing required extension: '.$ext['name']; + } + } + $this->assertEqual($ext['available'], 'yes', $errorMsg); + } + } + + + public function getExtension($key) { + foreach ($this->arrRequiredExtensions as $ext) { + if ($ext['extension'] == $key) { + return $ext; + } + } + return false; + } + + /** + * Testing IconV + */ + function testIconV() { + $key = 'iconv'; + $ext = $this->getExtension($key); + $errorMsg = '['.$ext['extension'].'] Missing optional extension: '.$ext['name']; + $this->assertEqual($this->oDepends->checkExtension($ext['extension']), true, $errorMsg); + } + + /** + * Testing MySQL + */ + function testMySQL() { + $key = 'mysql'; + $ext = $this->getExtension($key); + $errorMsg = '['.$ext['extension'].'] Missing required extension: '.$ext['name']; + $this->assertEqual($this->oDepends->checkExtension($ext['extension']), true, $errorMsg); + } + + /** + * Testing cURL + */ + function testcURL() { + $key = 'curl'; + $ext = $this->getExtension($key); + $errorMsg = '['.$ext['extension'].'] Missing required extension: '.$ext['name']; + $this->assertEqual($this->oDepends->checkExtension($ext['extension']), true, $errorMsg); + } + + /** + * Testing XMLRPC + */ + function testXMLRPC() { + $key = 'xmlrpc'; + $ext = $this->getExtension($key); + $errorMsg = '['.$ext['extension'].'] Missing required extension: '.$ext['name']; + $this->assertEqual($this->oDepends->checkExtension($ext['extension']), true, $errorMsg); + } + + + /** + * Testing Multi Byte Strings + */ + function testMultiByteStrings() { + $key = 'mbstring'; + $ext = $this->getExtension($key); + $errorMsg = '['.$ext['extension'].'] Missing optional extension: '.$ext['name']; + $this->assertEqual($this->oDepends->checkExtension($ext['extension']), true, $errorMsg); + } + + /** + * Testing LDAP + */ + function testLDAP() { + $key = 'ldap'; + $ext = $this->getExtension($key); + $errorMsg = '['.$ext['extension'].'] Missing optional extension: '.$ext['name']; + $this->assertEqual($this->oDepends->checkExtension($ext['extension']), true, $errorMsg); + } + + /** + * Testing JSON + */ + function testJSON() { + $key = 'json'; + $ext = $this->getExtension($key); + $errorMsg = '['.$ext['extension'].'] Missing required extension: '.$ext['name']; + $this->assertEqual($this->oDepends->checkExtension($ext['extension']), true, $errorMsg); + } + + /** + * Testing Open SSL + */ + function testOpenSSL() { + $key = 'openssl'; + $ext = $this->getExtension($key); + $errorMsg = '['.$ext['extension'].'] Missing optional extension: '.$ext['name']; + $this->assertEqual($this->oDepends->checkExtension($ext['extension']), true, $errorMsg); + } + +} +?> \ No newline at end of file diff --git a/tests/env/testPhpVersion.php b/tests/env/testPhpVersion.php new file mode 100755 index 0000000..daafeb9 --- /dev/null +++ b/tests/env/testPhpVersion.php @@ -0,0 +1,52 @@ +oDepends = new dependencies(); + } + + /** + * Cleanup + * + */ + function tearDown() { + $this->oDepends = null; + } + + /** + * Testing PHP Version + */ + function testPhpVersion() + { + $this->phpVersion = $this->oDepends->checkPhpVersion(); + $this->assertEqual($this->phpVersion['class'], 'tick'); + } + +} +?> \ No newline at end of file diff --git a/tests/env/testSystemConfigurations.php b/tests/env/testSystemConfigurations.php new file mode 100644 index 0000000..d759e1e --- /dev/null +++ b/tests/env/testSystemConfigurations.php @@ -0,0 +1,101 @@ +oConfig = new configuration(); + $this->arrServerInfo = $this->oConfig->getServerInfo(); + $this->arrPathInfo = $this->oConfig->getPathInfo($this->arrServerInfo['file_system_root']['value'], false); + } + + /** + * Cleaning up + */ + function tearDown() { + $this->oConfig = null; + } + + /** + * Testing configFile + */ + function testConfigFile() { + $key = 'configFile'; + $this->assertEqual($this->arrPathInfo[$key]['class'], 'tick', $this->arrPathInfo[$key]['msg']); + } + + /** + * Testing documentRoot + */ + function testDocumentRoot() { + $key = 'documentRoot'; + $this->assertEqual($this->arrPathInfo[$key]['class'], 'tick', $this->arrPathInfo[$key]['msg']); + } + + /** + * Testing logDirectory + */ + function testLogDirectory() { + $key = 'logDirectory'; + $this->assertEqual($this->arrPathInfo[$key]['class'], 'tick', $this->arrPathInfo[$key]['msg']); + } + + /** + * Testing tmpDirectory + */ + function testTmpDirectory() { + $key = 'tmpDirectory'; + $this->assertEqual($this->arrPathInfo[$key]['class'], 'tick', $this->arrPathInfo[$key]['msg']); + } + + /** + * Testing cacheDirectory + */ + function testCacheDirectory() { + $key = 'cacheDirectory'; + $this->assertEqual($this->arrPathInfo[$key]['class'], 'tick', $this->arrPathInfo[$key]['msg']); + } + + /** + * Testing uploadDirectory + */ + function testUploadDirectory() { + $key = 'uploadDirectory'; + $this->assertEqual($this->arrPathInfo[$key]['class'], 'tick', $this->arrPathInfo[$key]['msg']); + } + + /** + * Testing varDirectory + */ + function testvarDirectory() { + $key = 'varDirectory'; + $this->assertEqual($this->arrPathInfo[$key]['class'], 'tick', $this->arrPathInfo[$key]['msg']); + } + +} +?> \ No newline at end of file