PMA\libraries\plugins\auth\AuthenticationCookie::logOut PHP Method

logOut() public method

Perform logout
public logOut ( ) : void
return void
    public function logOut()
    {
        // -> delete password cookie(s)
        if ($GLOBALS['cfg']['LoginCookieDeleteAll']) {
            foreach ($GLOBALS['cfg']['Servers'] as $key => $val) {
                $GLOBALS['PMA_Config']->removeCookie('pmaAuth-' . $key);
                if (isset($_COOKIE['pmaAuth-' . $key])) {
                    unset($_COOKIE['pmaAuth-' . $key]);
                }
            }
        } else {
            $GLOBALS['PMA_Config']->removeCookie('pmaAuth-' . $GLOBALS['server']);
            if (isset($_COOKIE['pmaAuth-' . $GLOBALS['server']])) {
                unset($_COOKIE['pmaAuth-' . $GLOBALS['server']]);
            }
        }
        parent::logOut();
    }

Usage Example

 /**
  * Test for PMA\libraries\plugins\auth\AuthenticationConfig::authCheck
  *
  * @return void
  */
 public function testLogout()
 {
     $restoreInstance = PMA\libraries\Response::getInstance();
     $mockResponse = $this->getMockBuilder('PMA\\libraries\\Response')->disableOriginalConstructor()->setMethods(array('isAjax', 'headersSent', 'header'))->getMock();
     $mockResponse->expects($this->any())->method('headersSent')->with()->will($this->returnValue(false));
     $mockResponse->expects($this->once())->method('header')->with('Location: /phpmyadmin/index.php');
     $attrInstance = new ReflectionProperty('PMA\\libraries\\Response', '_instance');
     $attrInstance->setAccessible(true);
     $attrInstance->setValue($mockResponse);
     $GLOBALS['cfg']['CaptchaLoginPrivateKey'] = '';
     $GLOBALS['cfg']['CaptchaLoginPublicKey'] = '';
     $GLOBALS['cfg']['LoginCookieDeleteAll'] = false;
     $GLOBALS['cfg']['Servers'] = array(1);
     $GLOBALS['server'] = 1;
     $_COOKIE['pmaAuth-1'] = 'test';
     $this->object->logOut();
     $this->assertFalse(isset($_COOKIE['pmaAuth-1']));
     $attrInstance->setValue($restoreInstance);
 }