AuthenticationCookieTest::testAuthError PHP Метод

testAuthError() публичный Метод

Test for PMA\libraries\plugins\auth\AuthenticationConfig::auth
public testAuthError ( ) : void
Результат void
    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('<img src="testlogo_right.png" id="imLogo"', $result);
        $this->assertContains('<div class="error">', $result);
        $this->assertContains('<form method="post" action="index.php" name="login_form" ' . 'class="disableAjax login hide js-show">', $result);
        $this->assertContains('<input type="text" name="pma_servername" id="input_servername" ' . 'value="localhost"', $result);
        $this->assertContains('<input type="text" name="pma_username" id="input_username" ' . 'value="pmauser" size="24" class="textfield"/>', $result);
        $this->assertContains('<input type="password" name="pma_password" id="input_password" ' . 'value="" size="24" class="textfield" />', $result);
        $this->assertContains('<select name="server" id="select_server" ' . 'onchange="document.forms[\'login_form\'].' . 'elements[\'pma_servername\'].value = \'\'" >', $result);
        $this->assertContains('<input type="hidden" name="target" value="testTarget" />', $result);
        $this->assertContains('<input type="hidden" name="db" value="testDb" />', $result);
        $this->assertContains('<input type="hidden" name="table" value="testTable" />', $result);
        @unlink('testlogo_right.png');
        $attrInstance->setValue($restoreInstance);
    }