diff options
-rw-r--r-- | libraries/config/ConfigFile.class.php | 12 | ||||
-rw-r--r-- | libraries/config/Form.class.php | 13 | ||||
-rw-r--r-- | libraries/config/FormDisplay.class.php | 8 | ||||
-rw-r--r-- | libraries/config/Validator.class.php | 11 | ||||
-rw-r--r-- | libraries/core.lib.php | 4 | ||||
-rw-r--r-- | libraries/user_preferences.lib.php | 1 | ||||
-rw-r--r-- | setup/config.php | 5 | ||||
-rw-r--r-- | setup/lib/ConfigGenerator.class.php | 18 | ||||
-rw-r--r-- | test/classes/config/PMA_Form_test.php | 32 | ||||
-rw-r--r-- | test/classes/plugin/auth/PMA_AuthenticationCookie_test.php | 3 | ||||
-rw-r--r-- | test/libraries/PMA_ConfigFile_test.php | 116 | ||||
-rw-r--r-- | test/libraries/PMA_SetupIndex_test.php | 4 |
12 files changed, 143 insertions, 84 deletions
diff --git a/libraries/config/ConfigFile.class.php b/libraries/config/ConfigFile.class.php index f145fa0c76..51b0245cbc 100644 --- a/libraries/config/ConfigFile.class.php +++ b/libraries/config/ConfigFile.class.php @@ -73,7 +73,8 @@ class ConfigFile /** * Constructor * - * @param array $base_config base configuration read from {@link PMA_Config::$base_config}, + * @param array $base_config base configuration read from + * {@link PMA_Config::$base_config}, * use only when not in PMA Setup */ public function __construct(array $base_config = null) @@ -209,7 +210,8 @@ class ConfigFile $remove_path = $value === $default_value; if ($this->_isInSetup) { // remove if it has a default value or is empty - $remove_path = $remove_path || (empty($value) && empty($default_value)); + $remove_path = $remove_path + || (empty($value) && empty($default_value)); } else { // get original config values not overwritten by user // preferences to allow for overwriting options set in @@ -218,8 +220,10 @@ class ConfigFile $canonical_path, $this->_baseCfg ); - // remove if it has a default value and base config (config.inc.php) uses default value - $remove_path = $remove_path && ($instance_default_value === $default_value); + // remove if it has a default value and base config (config.inc.php) + // uses default value + $remove_path = $remove_path + && ($instance_default_value === $default_value); } if ($remove_path) { PMA_arrayRemove($path, $_SESSION[$this->_id]); diff --git a/libraries/config/Form.class.php b/libraries/config/Form.class.php index f8d26ef0dd..b8b55bcc8a 100644 --- a/libraries/config/Form.class.php +++ b/libraries/config/Form.class.php @@ -53,13 +53,14 @@ class Form /** * Constructor, reads default config values * - * @param string $form_name Form name - * @param array $form Form data - * @param ConfigFile $cf Config file instance - * @param int $index arbitrary index, stored in Form::$index + * @param string $form_name Form name + * @param array $form Form data + * @param ConfigFile $cf Config file instance + * @param int $index arbitrary index, stored in Form::$index */ - public function __construct($form_name, array $form, ConfigFile $cf, $index = null) - { + public function __construct( + $form_name, array $form, ConfigFile $cf, $index = null + ) { $this->index = $index; $this->_configFile = $cf; $this->loadForm($form_name, $form); diff --git a/libraries/config/FormDisplay.class.php b/libraries/config/FormDisplay.class.php index db2f884a64..74e326a2f5 100644 --- a/libraries/config/FormDisplay.class.php +++ b/libraries/config/FormDisplay.class.php @@ -124,7 +124,9 @@ class FormDisplay */ public function registerForm($form_name, array $form, $server_id = null) { - $this->_forms[$form_name] = new Form($form_name, $form, $this->_configFile, $server_id); + $this->_forms[$form_name] = new Form( + $form_name, $form, $this->_configFile, $server_id + ); $this->_isValidated = false; foreach ($this->_forms[$form_name]->fields as $path) { $work_path = $server_id === null @@ -182,7 +184,9 @@ class FormDisplay } // run validation - $errors = PMA_Validator::validate($this->_configFile, $paths, $values, false); + $errors = PMA_Validator::validate( + $this->_configFile, $paths, $values, false + ); // change error keys from canonical paths to work paths if (is_array($errors) && count($errors) > 0) { diff --git a/libraries/config/Validator.class.php b/libraries/config/Validator.class.php index 0a885689bc..e6a958880f 100644 --- a/libraries/config/Validator.class.php +++ b/libraries/config/Validator.class.php @@ -26,6 +26,7 @@ class PMA_Validator * Returns validator list * * @param ConfigFile $cf Config file instance + * * @return array */ public static function getValidators(ConfigFile $cf) @@ -49,7 +50,8 @@ class PMA_Validator for ($i = 1; $i < count($uv); $i++) { if (substr($uv[$i], 0, 6) == 'value:') { $uv[$i] = PMA_arrayRead( - substr($uv[$i], 6), $GLOBALS['PMA_Config']->base_settings + substr($uv[$i], 6), + $GLOBALS['PMA_Config']->base_settings ); } } @@ -72,7 +74,7 @@ class PMA_Validator * cleanup in HTML documen * o false - when no validators match name(s) given by $validator_id * - * @param ConfigFile $cf Config file instance + * @param ConfigFile $cf Config file instance * @param string|array $validator_id ID of validator(s) to run * @param array &$values Values to validate * @param bool $isPostSource tells whether $values are directly from @@ -80,8 +82,9 @@ class PMA_Validator * * @return bool|array */ - public static function validate(ConfigFile $cf, $validator_id, &$values, $isPostSource) - { + public static function validate( + ConfigFile $cf, $validator_id, &$values, $isPostSource + ) { // find validators $validator_id = (array) $validator_id; $validators = static::getValidators($cf); diff --git a/libraries/core.lib.php b/libraries/core.lib.php index c58ad31a4f..d27788d333 100644 --- a/libraries/core.lib.php +++ b/libraries/core.lib.php @@ -659,8 +659,8 @@ function PMA_downloadHeader($filename, $mimetype, $length = 0, $no_cache = true) * $path is a string describing position of an element in an associative array, * eg. Servers/1/host refers to $array[Servers][1][host] * - * @param string $path path in the arry - * @param array $array the array + * @param string $path path in the arry + * @param array $array the array * * @return mixed array element or $default */ diff --git a/libraries/user_preferences.lib.php b/libraries/user_preferences.lib.php index 3974c628a0..4b979145ad 100644 --- a/libraries/user_preferences.lib.php +++ b/libraries/user_preferences.lib.php @@ -13,6 +13,7 @@ if (! defined('PHPMYADMIN')) { * Common initialization for user preferences modification pages * * @param ConfigFile $cf Config file instance + * * @return void */ function PMA_userprefsPageInit(ConfigFile $cf) diff --git a/setup/config.php b/setup/config.php index 9074ebe5ac..ffe65915ed 100644 --- a/setup/config.php +++ b/setup/config.php @@ -45,7 +45,10 @@ if (PMA_ifSetOr($_POST['submit_clear'], '')) { // // Save generated config file on the server // - file_put_contents($config_file_path, ConfigGenerator::getConfigFile($GLOBALS['ConfigFile'])); + file_put_contents( + $config_file_path, + ConfigGenerator::getConfigFile($GLOBALS['ConfigFile']) + ); header('HTTP/1.1 303 See Other'); header('Location: index.php?action_done=config_saved'); exit; diff --git a/setup/lib/ConfigGenerator.class.php b/setup/lib/ConfigGenerator.class.php index d734cbc755..279c071ac0 100644 --- a/setup/lib/ConfigGenerator.class.php +++ b/setup/lib/ConfigGenerator.class.php @@ -17,11 +17,14 @@ class ConfigGenerator * Creates config file * * @param ConfigFile $cf Config file instance + * * @return string */ public static function getConfigFile(ConfigFile $cf) { - $crlf = (isset($_SESSION['eol']) && $_SESSION['eol'] == 'win') ? "\r\n" : "\n"; + $crlf = (isset($_SESSION['eol']) && $_SESSION['eol'] == 'win') + ? "\r\n" + : "\n"; $c = $cf->getConfig(); // header @@ -38,7 +41,9 @@ class ConfigGenerator if ($cf->getServerCount() > 0) { $ret .= "/* Servers configuration */$crlf\$i = 0;" . $crlf . $crlf; foreach ($c['Servers'] as $id => $server) { - $ret .= '/* Server: ' . strtr($cf->getServerName($id) . " [$id] ", '*/', '-') . "*/" . $crlf + $ret .= '/* Server: ' + . strtr($cf->getServerName($id) . " [$id] ", '*/', '-') + . "*/" . $crlf . '$i++;' . $crlf; foreach ($server as $k => $v) { $k = preg_replace('/[^A-Za-z0-9_]/', '_', $k); @@ -88,17 +93,20 @@ class ConfigGenerator private static function _getVarExport($var_name, $var_value, $crlf) { if (!is_array($var_value) || empty($var_value)) { - return "\$cfg['$var_name'] = " . var_export($var_value, true) . ';' . $crlf; + return "\$cfg['$var_name'] = " + . var_export($var_value, true) . ';' . $crlf; } $ret = ''; if (self::_isZeroBasedArray($var_value)) { - $ret = "\$cfg['$var_name'] = " . self::_exportZeroBasedArray($var_value, $crlf) + $ret = "\$cfg['$var_name'] = " + . self::_exportZeroBasedArray($var_value, $crlf) . ';' . $crlf; } else { // string keys: $cfg[key][subkey] = value foreach ($var_value as $k => $v) { $k = preg_replace('/[^A-Za-z0-9_]/', '_', $k); - $ret .= "\$cfg['$var_name']['$k'] = " . var_export($v, true) . ';' . $crlf; + $ret .= "\$cfg['$var_name']['$k'] = " + . var_export($v, true) . ';' . $crlf; } } return $ret; diff --git a/test/classes/config/PMA_Form_test.php b/test/classes/config/PMA_Form_test.php index dc8caed31e..27e981fc1a 100644 --- a/test/classes/config/PMA_Form_test.php +++ b/test/classes/config/PMA_Form_test.php @@ -38,12 +38,14 @@ class PMA_Form_Test extends PHPUnit_Framework_TestCase $GLOBALS['PMA_Config'] = new PMA_Config(); $GLOBALS['PMA_Config']->enableBc(); $GLOBALS['server'] = 0; - $this->object = new Form('pma_form_name', array('pma_form1','pma_form2'), new ConfigFile(), 1); + $this->object = new Form( + 'pma_form_name', array('pma_form1','pma_form2'), new ConfigFile(), 1 + ); } /** * tearDown for test cases - * + * * @return void */ protected function tearDown() @@ -53,7 +55,7 @@ class PMA_Form_Test extends PHPUnit_Framework_TestCase /** * Test for Form::__constructor - * + * * @return void */ public function testContructor() @@ -74,7 +76,7 @@ class PMA_Form_Test extends PHPUnit_Framework_TestCase /** * Test for Form::getOptionType - * + * * @return void */ public function testGetOptionType() @@ -98,11 +100,11 @@ class PMA_Form_Test extends PHPUnit_Framework_TestCase /** * Test for Form::getOptionValueList - * + * * @return void */ public function testGetOptionValueList() - { + { $this->assertEquals( array('NHibernate C# DO', 'NHibernate XML'), $this->object->getOptionValueList("Export/codegen_format") @@ -110,8 +112,8 @@ class PMA_Form_Test extends PHPUnit_Framework_TestCase $this->assertEquals( array( - 'auto' => 'auto', - '1' => 1, + 'auto' => 'auto', + '1' => 1, '0' => 0 ), $this->object->getOptionValueList("OBGzip") @@ -119,8 +121,8 @@ class PMA_Form_Test extends PHPUnit_Framework_TestCase $this->assertEquals( array( - 'none' => 'Nowhere', - 'left' => 'Left', + 'none' => 'Nowhere', + 'left' => 'Left', 'right' => 'Right', 'both' => "Both" ), @@ -130,7 +132,7 @@ class PMA_Form_Test extends PHPUnit_Framework_TestCase /** * Test for Form::_readFormPathsCallback - * + * * @return void */ public function testReadFormPathsCallBack() @@ -182,7 +184,7 @@ class PMA_Form_Test extends PHPUnit_Framework_TestCase /** * Test for Form::readFormPaths - * + * * @return void */ public function testReadFormPaths() @@ -228,7 +230,7 @@ class PMA_Form_Test extends PHPUnit_Framework_TestCase preg_match("/^\:group\:end\:(\d+)$/", $key, $matches); $digit = $matches[1]; - + $this->assertEquals( "foo/bar/:group:end:" . $digit, $result[':group:end:' . $digit] @@ -237,7 +239,7 @@ class PMA_Form_Test extends PHPUnit_Framework_TestCase /** * Test for Form::readTypes - * + * * @return void */ public function testReadTypes() @@ -271,7 +273,7 @@ class PMA_Form_Test extends PHPUnit_Framework_TestCase /** * Test for Form::loadForm - * + * * @return void */ public function testLoadForm() diff --git a/test/classes/plugin/auth/PMA_AuthenticationCookie_test.php b/test/classes/plugin/auth/PMA_AuthenticationCookie_test.php index 412da0769f..8d9b2669e1 100644 --- a/test/classes/plugin/auth/PMA_AuthenticationCookie_test.php +++ b/test/classes/plugin/auth/PMA_AuthenticationCookie_test.php @@ -903,7 +903,8 @@ class PMA_AuthenticationCookie_Test extends PHPUnit_Framework_TestCase isset($_COOKIE['pmaServer-2']) ); - // target can be "phpunit" or "ide-phpunut.php", depending on testing environment + // target can be "phpunit" or "ide-phpunut.php", + // depending on testing environment $this->assertStringStartsWith( 'Location: http://phpmyadmin.net/index.php?target=', $GLOBALS['header'][0] diff --git a/test/libraries/PMA_ConfigFile_test.php b/test/libraries/PMA_ConfigFile_test.php index b43f961a11..1220491b88 100644 --- a/test/libraries/PMA_ConfigFile_test.php +++ b/test/libraries/PMA_ConfigFile_test.php @@ -91,7 +91,9 @@ class PMA_ConfigFile_Test extends PHPUnit_Framework_TestCase ); // Validate default value used in tests - $default_value = $this->object->getDefault(self::SIMPLE_KEY_WITH_DEFAULT_VALUE); + $default_value = $this->object->getDefault( + self::SIMPLE_KEY_WITH_DEFAULT_VALUE + ); $this->assertNotNull($default_value); } @@ -103,7 +105,9 @@ class PMA_ConfigFile_Test extends PHPUnit_Framework_TestCase */ public function testPersistentKeys() { - $default_simple_value = $this->object->getDefault(self::SIMPLE_KEY_WITH_DEFAULT_VALUE); + $default_simple_value = $this->object->getDefault( + self::SIMPLE_KEY_WITH_DEFAULT_VALUE + ); $default_host = $this->object->getDefault('Servers/1/host'); $default_config = array( self::SIMPLE_KEY_WITH_DEFAULT_VALUE => $default_simple_value, @@ -113,14 +117,16 @@ class PMA_ConfigFile_Test extends PHPUnit_Framework_TestCase /** * Case 1: set default value, key should not be persisted */ - $this->object->set(self::SIMPLE_KEY_WITH_DEFAULT_VALUE, $default_simple_value); + $this->object->set( + self::SIMPLE_KEY_WITH_DEFAULT_VALUE, $default_simple_value + ); $this->object->set('Servers/1/host', $default_host); $this->object->set('Servers/2/host', $default_host); $this->assertEmpty($this->object->getConfig()); /** - * Case 2: persistent keys should be always present in flat array, even if not explicitly set - * (unless they are Server entries) + * Case 2: persistent keys should be always present in flat array, + * even if not explicitly set (unless they are Server entries) */ $this->object->setPersistKeys(array_keys($default_config)); $this->object->resetConfigData(); @@ -131,7 +137,8 @@ class PMA_ConfigFile_Test extends PHPUnit_Framework_TestCase ); /** - * Case 3: persistent keys should be always saved, even if set to default values + * Case 3: persistent keys should be always saved, + * even if set to default values */ $this->object->set('Servers/2/host', $default_host); $this->assertEquals( @@ -182,9 +189,12 @@ class PMA_ConfigFile_Test extends PHPUnit_Framework_TestCase */ public function testConfigReadMapping() { - $this->object->setCfgUpdateReadMapping(array( + $this->object->setCfgUpdateReadMapping( + array( 'Servers/value1' => 'Servers/1/value1', - 'Servers/value2' => 'Servers/1/value2')); + 'Servers/value2' => 'Servers/1/value2' + ) + ); $this->object->set('Servers/1/passthrough1', 1); $this->object->set('Servers/1/passthrough2', 2); $this->object->updateWithGlobalConfig(array('Servers/value1' => 3)); @@ -290,7 +300,9 @@ class PMA_ConfigFile_Test extends PHPUnit_Framework_TestCase */ public function testConfigFileSetInSetup() { - $default_value = $this->object->getDefault(self::SIMPLE_KEY_WITH_DEFAULT_VALUE); + $default_value = $this->object->getDefault( + self::SIMPLE_KEY_WITH_DEFAULT_VALUE + ); // default values are not written $this->object->set(self::SIMPLE_KEY_WITH_DEFAULT_VALUE, $default_value); @@ -305,17 +317,23 @@ class PMA_ConfigFile_Test extends PHPUnit_Framework_TestCase */ public function testConfigFileSetInUserPreferences() { - $default_value = $this->object->getDefault(self::SIMPLE_KEY_WITH_DEFAULT_VALUE); + $default_value = $this->object->getDefault( + self::SIMPLE_KEY_WITH_DEFAULT_VALUE + ); // values are not written when they are the same as in config.inc.php - $this->object = new ConfigFile(array(self::SIMPLE_KEY_WITH_DEFAULT_VALUE => $default_value)); + $this->object = new ConfigFile( + array(self::SIMPLE_KEY_WITH_DEFAULT_VALUE => $default_value) + ); $this->object->set(self::SIMPLE_KEY_WITH_DEFAULT_VALUE, $default_value); $this->assertEmpty($this->object->getConfig()); - // but if config.inc.php differs from config.default.php, allow to overwrite with - // value from config.default.php + // but if config.inc.php differs from config.default.php, + // allow to overwrite with value from config.default.php $config_inc_php_value = $default_value . 'suffix'; - $this->object = new ConfigFile(array(self::SIMPLE_KEY_WITH_DEFAULT_VALUE => $config_inc_php_value)); + $this->object = new ConfigFile( + array(self::SIMPLE_KEY_WITH_DEFAULT_VALUE => $config_inc_php_value) + ); $this->object->set(self::SIMPLE_KEY_WITH_DEFAULT_VALUE, $default_value); $this->assertEquals( array(self::SIMPLE_KEY_WITH_DEFAULT_VALUE => $default_value), @@ -333,11 +351,17 @@ class PMA_ConfigFile_Test extends PHPUnit_Framework_TestCase { $flat_default_config = $this->object->getFlatDefaultConfig(); - $default_value = $this->object->getDefault(self::SIMPLE_KEY_WITH_DEFAULT_VALUE); - $this->assertEquals($default_value, $flat_default_config[self::SIMPLE_KEY_WITH_DEFAULT_VALUE]); + $default_value = $this->object->getDefault( + self::SIMPLE_KEY_WITH_DEFAULT_VALUE + ); + $this->assertEquals( + $default_value, $flat_default_config[self::SIMPLE_KEY_WITH_DEFAULT_VALUE] + ); $localhost_value = $this->object->getDefault('Servers/1/host'); - $this->assertEquals($localhost_value, $flat_default_config['Servers/1/host']); + $this->assertEquals( + $localhost_value, $flat_default_config['Servers/1/host'] + ); $cfg = array(); include './libraries/config.default.php'; @@ -398,11 +422,13 @@ class PMA_ConfigFile_Test extends PHPUnit_Framework_TestCase $this->assertEquals( $cfg_db['Servers'][1]['port'], - $this->object->getDbEntry('Servers/1/port')); + $this->object->getDbEntry('Servers/1/port') + ); $this->assertNull($this->object->getDbEntry('no such key')); $this->assertEquals( array(1), - $this->object->getDbEntry('no such key', array(1))); + $this->object->getDbEntry('no such key', array(1)) + ); } /** @@ -476,37 +502,41 @@ class PMA_ConfigFile_Test extends PHPUnit_Framework_TestCase $this->object->getServerDSN(1) ); - $this->object->updateWithGlobalConfig(array( - 'Servers' => array( - 1 => array( - "extension" => "mysqli", - "auth_type" => "config", - "user" => "testUser", - "connect_type" => "tcp", - "host" => "example.com", - "port" => "21" + $this->object->updateWithGlobalConfig( + array( + 'Servers' => array( + 1 => array( + "extension" => "mysqli", + "auth_type" => "config", + "user" => "testUser", + "connect_type" => "tcp", + "host" => "example.com", + "port" => "21" + ) ) ) - )); + ); $this->assertEquals( "mysqli://testUser:***@example.com:21", $this->object->getServerDSN(1) ); - $this->object->updateWithGlobalConfig(array( - 'Servers' => array( - 1 => array( - "extension" => "mysql", - "auth_type" => "config", - "user" => "testUser", - "connect_type" => "socket", - "host" => "example.com", - "port" => "21", - "nopassword" => "yes", - "socket" => "123" + $this->object->updateWithGlobalConfig( + array( + 'Servers' => array( + 1 => array( + "extension" => "mysql", + "auth_type" => "config", + "user" => "testUser", + "connect_type" => "socket", + "host" => "example.com", + "port" => "21", + "nopassword" => "yes", + "socket" => "123" + ) ) ) - )); + ); $this->assertEquals( "mysql://testUser@123", $this->object->getServerDSN(1) @@ -560,7 +590,9 @@ class PMA_ConfigFile_Test extends PHPUnit_Framework_TestCase { $this->object->setPersistKeys(array(self::SIMPLE_KEY_WITH_DEFAULT_VALUE)); $this->object->set('Array/test', array('x', 'y')); - $default_value = $this->object->getDefault(self::SIMPLE_KEY_WITH_DEFAULT_VALUE); + $default_value = $this->object->getDefault( + self::SIMPLE_KEY_WITH_DEFAULT_VALUE + ); $this->assertEquals( array( diff --git a/test/libraries/PMA_SetupIndex_test.php b/test/libraries/PMA_SetupIndex_test.php index d0eb64b2c0..73777561cf 100644 --- a/test/libraries/PMA_SetupIndex_test.php +++ b/test/libraries/PMA_SetupIndex_test.php @@ -9,8 +9,8 @@ /* * Include to test */ -include_once 'libraries/php-gettext/gettext.inc'; -include_once 'libraries/sanitizing.lib.php'; +require_once 'libraries/php-gettext/gettext.inc'; +require_once 'libraries/sanitizing.lib.php'; require_once 'libraries/config/config_functions.lib.php'; require_once 'libraries/config/ConfigFile.class.php'; require_once 'libraries/core.lib.php'; |