/** * Test for AuthenticationConfig::authFails * * @return void */ public function testAuthFails() { if (!defined('PMA_TEST_HEADERS')) { $this->markTestSkipped('Cannot redefine constant/function - missing runkit extension'); } $this->object = $this->getMockBuilder('AuthenticationCookie')->disableOriginalConstructor()->setMethods(array('auth'))->getMock(); $this->object->expects($this->exactly(5))->method('auth'); $GLOBALS['server'] = 2; $_COOKIE['pmaPass-2'] = 'pass'; // case 1 $GLOBALS['login_without_password_is_forbidden'] = '1'; $this->object->authFails(); $this->assertEquals($GLOBALS['conn_error'], 'Login without a password is forbidden by configuration' . ' (see AllowNoPassword)'); $this->assertEquals($GLOBALS['header'], array('Cache-Control: no-store, no-cache, must-revalidate', 'Pragma: no-cache')); // case 2 $GLOBALS['login_without_password_is_forbidden'] = ''; $GLOBALS['allowDeny_forbidden'] = '1'; $this->object->authFails(); $this->assertEquals($GLOBALS['conn_error'], 'Access denied!'); // case 3 $GLOBALS['allowDeny_forbidden'] = ''; $GLOBALS['no_activity'] = '1'; $GLOBALS['cfg']['LoginCookieValidity'] = 10; $this->object->authFails(); $this->assertEquals($GLOBALS['conn_error'], 'No activity within 10 seconds; please log in again.'); // case 4 $dbi = $this->getMockBuilder('PMA_DatabaseInterface')->disableOriginalConstructor()->getMock(); $dbi->expects($this->at(0))->method('getError')->will($this->returnValue(false)); $dbi->expects($this->at(1))->method('getError')->will($this->returnValue(false)); $GLOBALS['dbi'] = $dbi; $GLOBALS['no_activity'] = ''; $GLOBALS['errno'] = 42; $this->object->authFails(); $this->assertEquals($GLOBALS['conn_error'], '#42 Cannot log in to the MySQL server'); // case 5 unset($GLOBALS['errno']); $this->object->authFails(); $this->assertEquals($GLOBALS['conn_error'], 'Cannot log in to the MySQL server'); }