/** * Test for PMA_getUserGroupForUser * * @return void */ public function testPMAGetUserGroupForUser() { $username = "******"; $hostname = "pma_hostname"; $GLOBALS['cfgRelation']['menuswork'] = true; $dbi_old = $GLOBALS['dbi']; $dbi = $this->getMockBuilder('PMA\libraries\DatabaseInterface') ->disableOriginalConstructor() ->getMock(); $expected_userGroup = "pma_usergroup"; $dbi->expects($this->any())->method('fetchValue') ->will($this->returnValue($expected_userGroup)); $dbi->expects($this->any()) ->method('escapeString') ->will($this->returnArgument(0)); $GLOBALS['dbi'] = $dbi; $returned_userGroup = PMA_getUserGroupForUser($username); $this->assertEquals( $expected_userGroup, $returned_userGroup ); $GLOBALS['dbi'] = $dbi_old; }
/** * Get the HTML snippet for change user login information * * @param string $username username * @param string $hostname host name * * @return string HTML snippet */ function PMA_getChangeLoginInformationHtmlForm($username, $hostname) { $choices = array('4' => __('… keep the old one.'), '1' => __('… delete the old one from the user tables.'), '2' => __('… revoke all active privileges from ' . 'the old one and delete it afterwards.'), '3' => __('… delete the old one from the user tables ' . 'and reload the privileges afterwards.')); $html_output = '<form action="server_privileges.php" ' . 'onsubmit="return checkAddUser(this);" ' . 'method="post" class="copyUserForm submenu-item">' . "\n" . URL::getHiddenInputs('', '') . '<input type="hidden" name="old_username" ' . 'value="' . htmlspecialchars($username) . '" />' . "\n" . '<input type="hidden" name="old_hostname" ' . 'value="' . htmlspecialchars($hostname) . '" />' . "\n"; $usergroup = PMA_getUserGroupForUser($username); if ($usergroup !== null) { $html_output .= '<input type="hidden" name="old_usergroup" ' . 'value="' . htmlspecialchars($usergroup) . '" />' . "\n"; } $html_output .= '<fieldset id="fieldset_change_copy_user">' . "\n" . '<legend data-submenu-label="' . __('Login Information') . '">' . "\n" . __('Change login information / Copy user account') . '</legend>' . "\n" . PMA_getHtmlForLoginInformationFields('change', $username, $hostname); $html_output .= '<fieldset id="fieldset_mode">' . "\n" . ' <legend>' . __('Create a new user account with the same privileges and …') . '</legend>' . "\n"; $html_output .= Util::getRadioFields('mode', $choices, '4', true); $html_output .= '</fieldset>' . "\n" . '</fieldset>' . "\n"; $html_output .= '<fieldset id="fieldset_change_copy_user_footer" ' . 'class="tblFooters">' . "\n" . '<input type="hidden" name="change_copy" value="1" />' . "\n" . '<input type="submit" value="' . __('Go') . '" />' . "\n" . '</fieldset>' . "\n" . '</form>' . "\n"; return $html_output; }