enableBc();
$GLOBALS['server'] = 0;
$GLOBALS['text_dir'] = 'ltr';
$GLOBALS['db'] = 'db';
$GLOBALS['table'] = 'table';
$this->object = new AuthenticationCookie();
$_SESSION['PMA_Theme'] = Theme::load('./themes/pmahomme');
$_SESSION['PMA_Theme'] = new Theme();
$GLOBALS['PMA_PHP_SELF'] = '/phpmyadmin/';
}
/**
* tearDown for test cases
*
* @return void
*/
public function tearDown()
{
unset($this->object);
}
/**
* Test for PMA\libraries\plugins\auth\AuthenticationConfig::auth
*
* @return void
* @group medium
*/
public function testAuthErrorAJAX()
{
$restoreInstance = PMA\libraries\Response::getInstance();
$mockResponse = $this->getMockBuilder('PMA\libraries\Response')
->disableOriginalConstructor()
->setMethods(array('isAjax', 'setRequestStatus', 'addJSON'))
->getMock();
$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'
);
$attrInstance = new ReflectionProperty('PMA\libraries\Response', '_instance');
$attrInstance->setAccessible(true);
$attrInstance->setValue($mockResponse);
$GLOBALS['conn_error'] = true;
$this->assertTrue(
$this->object->auth()
);
$attrInstance->setValue($restoreInstance);
}
/**
* Test for PMA\libraries\plugins\auth\AuthenticationConfig::auth
*
* @return void
* @group medium
*/
public function testAuthError()
{
$restoreInstance = PMA\libraries\Response::getInstance();
$mockResponse = $this->getMockBuilder('PMA\libraries\Response')
->disableOriginalConstructor()
->setMethods(array('isAjax', 'getFooter', 'getHeader'))
->getMock();
$mockResponse->expects($this->once())
->method('isAjax')
->with()
->will($this->returnValue(false));
$_REQUEST['old_usr'] = '';
$GLOBALS['cfg']['LoginCookieRecall'] = true;
$GLOBALS['cfg']['blowfish_secret'] = 'secret';
$GLOBALS['PHP_AUTH_USER'] = 'pmauser';
$GLOBALS['pma_auth_server'] = 'localhost';
// mock footer
$mockFooter = $this->getMockBuilder('PMA\libraries\Footer')
->disableOriginalConstructor()
->setMethods(array('setMinimal'))
->getMock();
$mockFooter->expects($this->once())
->method('setMinimal')
->with();
// mock header
$mockHeader = $this->getMockBuilder('PMA\libraries\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));
$attrInstance = new ReflectionProperty('PMA\libraries\Response', '_instance');
$attrInstance->setAccessible(true);
$attrInstance->setValue($mockResponse);
$GLOBALS['pmaThemeImage'] = 'test';
$GLOBALS['conn_error'] = true;
$GLOBALS['cfg']['Lang'] = 'en';
$GLOBALS['cfg']['AllowArbitraryServer'] = true;
$GLOBALS['cfg']['Servers'] = array(1, 2);
$GLOBALS['cfg']['CaptchaLoginPrivateKey'] = '';
$GLOBALS['cfg']['CaptchaLoginPublicKey'] = '';
$GLOBALS['target'] = 'testTarget';
$GLOBALS['db'] = 'testDb';
$GLOBALS['table'] = 'testTable';
file_put_contents('testlogo_right.png', '');
// mock error handler
$mockErrorHandler = $this->getMockBuilder('PMA\libraries\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;
ob_start();
$this->object->auth();
$result = ob_get_clean();
// assertions
$this->assertContains(
'assertContains(
'