object = new AuthenticationCookie(); $GLOBALS['PMA_PHP_SELF'] = '/phpmyadmin/'; $GLOBALS['cfg']['Server']['DisableIS'] = false; $GLOBALS['conn_error'] = null; } /** * tearDown for test cases */ protected function tearDown(): void { parent::tearDown(); unset($this->object); } /** * @group medium */ public function testAuthErrorAJAX(): void { $mockResponse = $this->mockResponse(); $mockResponse->expects($this->once()) ->method('isAjax') ->with() ->will($this->returnValue(true)); $mockResponse->expects($this->once()) ->method('setRequestStatus') ->with(false); $mockResponse->expects($this->once()) ->method('addJSON') ->with('redirect_flag', '1'); $GLOBALS['conn_error'] = true; $this->assertTrue( $this->object->showLoginForm() ); } private function getAuthErrorMockResponse(): void { $mockResponse = $this->mockResponse(); $mockResponse->expects($this->once()) ->method('isAjax') ->with() ->will($this->returnValue(false)); // mock footer $mockFooter = $this->getMockBuilder(Footer::class) ->disableOriginalConstructor() ->onlyMethods(['setMinimal']) ->getMock(); $mockFooter->expects($this->once()) ->method('setMinimal') ->with(); // mock header $mockHeader = $this->getMockBuilder(Header::class) ->disableOriginalConstructor() ->onlyMethods( [ 'setBodyId', 'setTitle', 'disableMenuAndConsole', 'disableWarnings', ] ) ->getMock(); $mockHeader->expects($this->once()) ->method('setBodyId') ->with('loginform'); $mockHeader->expects($this->once()) ->method('setTitle') ->with('phpMyAdmin'); $mockHeader->expects($this->once()) ->method('disableMenuAndConsole') ->with(); $mockHeader->expects($this->once()) ->method('disableWarnings') ->with(); // set mocked headers and footers $mockResponse->expects($this->once()) ->method('getFooter') ->with() ->will($this->returnValue($mockFooter)); $mockResponse->expects($this->once()) ->method('getHeader') ->with() ->will($this->returnValue($mockHeader)); $GLOBALS['cfg']['Servers'] = [ 1, 2, ]; // mock error handler $mockErrorHandler = $this->getMockBuilder(ErrorHandler::class) ->disableOriginalConstructor() ->onlyMethods(['hasDisplayErrors']) ->getMock(); $mockErrorHandler->expects($this->once()) ->method('hasDisplayErrors') ->with() ->will($this->returnValue(true)); $GLOBALS['errorHandler'] = $mockErrorHandler; } /** * @group medium */ public function testAuthError(): void { $_REQUEST = []; ResponseRenderer::getInstance()->setAjax(false); $_REQUEST['old_usr'] = ''; $GLOBALS['cfg']['LoginCookieRecall'] = true; $GLOBALS['cfg']['blowfish_secret'] = str_repeat('a', 32); $this->object->user = 'pmauser'; $GLOBALS['pma_auth_server'] = 'localhost'; $GLOBALS['conn_error'] = true; $GLOBALS['cfg']['Lang'] = 'en'; $GLOBALS['cfg']['AllowArbitraryServer'] = true; $GLOBALS['cfg']['CaptchaApi'] = ''; $GLOBALS['cfg']['CaptchaRequestParam'] = ''; $GLOBALS['cfg']['CaptchaResponseParam'] = ''; $GLOBALS['cfg']['CaptchaLoginPrivateKey'] = ''; $GLOBALS['cfg']['CaptchaLoginPublicKey'] = ''; $GLOBALS['db'] = 'testDb'; $GLOBALS['table'] = 'testTable'; $GLOBALS['cfg']['Servers'] = [1, 2]; $GLOBALS['errorHandler'] = new ErrorHandler(); ob_start(); $this->object->showLoginForm(); $result = ob_get_clean(); $this->assertIsString($result); $this->assertStringContainsString(' id="imLogo"', $result); $this->assertStringContainsString('