enableBc(); $GLOBALS['server'] = 0; $GLOBALS['text_dir'] = 'ltr'; $GLOBALS['db'] = 'db'; $GLOBALS['table'] = 'table'; $_POST['pma_password'] = ''; $this->object = new AuthenticationCookie(); $GLOBALS['PMA_PHP_SELF'] = '/phpmyadmin/'; } /** * tearDown for test cases * * @return void */ public function tearDown() { parent::tearDown(); unset($this->object); } /** * Test for PhpMyAdmin\Plugins\Auth\AuthenticationConfig::showLoginForm * * @return void * @group medium */ public function testAuthErrorAJAX() { $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() { $mockResponse = $this->mockResponse(); $mockResponse->expects($this->once()) ->method('isAjax') ->with() ->will($this->returnValue(false)); // mock footer $mockFooter = $this->getMockBuilder('PhpMyAdmin\Footer') ->disableOriginalConstructor() ->setMethods(array('setMinimal')) ->getMock(); $mockFooter->expects($this->once()) ->method('setMinimal') ->with(); // mock header $mockHeader = $this->getMockBuilder('PhpMyAdmin\Header') ->disableOriginalConstructor() ->setMethods( array( '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['pmaThemeImage'] = 'test'; $GLOBALS['cfg']['Servers'] = array(1, 2); // mock error handler $mockErrorHandler = $this->getMockBuilder('PhpMyAdmin\ErrorHandler') ->disableOriginalConstructor() ->setMethods(array('hasDisplayErrors', 'dispErrors')) ->getMock(); $mockErrorHandler->expects($this->once()) ->method('hasDisplayErrors') ->with() ->will($this->returnValue(true)); $mockErrorHandler->expects($this->once()) ->method('dispErrors') ->with(); $GLOBALS['error_handler'] = $mockErrorHandler; } /** * Test for PhpMyAdmin\Plugins\Auth\AuthenticationConfig::showLoginForm * * @return void * @group medium */ public function testAuthError() { $this->getAuthErrorMockResponse(); $_REQUEST['old_usr'] = ''; $GLOBALS['cfg']['LoginCookieRecall'] = true; $GLOBALS['cfg']['blowfish_secret'] = 'secret'; $this->object->user = 'pmauser'; $GLOBALS['pma_auth_server'] = 'localhost'; $GLOBALS['conn_error'] = true; $GLOBALS['cfg']['Lang'] = 'en'; $GLOBALS['cfg']['AllowArbitraryServer'] = true; $GLOBALS['cfg']['CaptchaLoginPrivateKey'] = ''; $GLOBALS['cfg']['CaptchaLoginPublicKey'] = ''; $GLOBALS['target'] = 'testTarget'; $GLOBALS['db'] = 'testDb'; $GLOBALS['table'] = 'testTable'; ob_start(); $this->object->showLoginForm(); $result = ob_get_clean(); // assertions $this->assertContains( ' id="imLogo"', $result ); $this->assertContains( '