/**
     * Test for PMA_getHtmlForColumnDefault
     *
     * @return void
     */
    public function testGetHtmlForColumnDefault()
    {
        $cmeta = array(
            'Default' => 'YES',
            'DefaultType' => 'NONE',
            'DefaultValue' => '2222'
        );

        $result = PMA_getHtmlForColumnDefault(
            2, 3, 1, 'TIMESTAMP', true, $cmeta
        );

        $this->assertTag(
            PMA_getTagArray(
                '<select name="field_default_type[2]" id="field_2_2" '
                . 'class="default_type">'
            ),
            $result
        );

        $this->assertTag(
            PMA_getTagArray(
                '<option value="NONE" selected="selected" >',
                array('content' => 'None')
            ),
            $result
        );

        $this->assertTag(
            PMA_getTagArray(
                '<input type="text" name="field_default_value[2]" size="12" '
                . 'value="2222" class="textfield default_value" />'
            ),
            $result
        );
    }
 /**
  * Test for PMA_getSumbitAndResetButtonForActionsPanel
  *
  * @return void
  */
 public function testGetSumbitAndResetButtonForActionsPanel()
 {
     $GLOBALS['cfg']['ShowHint'] = false;
     $result = PMA_getSumbitAndResetButtonForActionsPanel(1, 0);
     $this->assertTag(PMA_getTagArray('<input type="submit" class="control_at_footer" value="Go" ' . 'tabindex="7" id="buttonYes" />'), $result);
     $this->assertTag(PMA_getTagArray('<input type="reset" class="control_at_footer" value="Reset" ' . 'tabindex="8" />'), $result);
 }
 /**
  * Tests for PMA_displayTablesInEditPrivs
  *
  * @return void
  */
 function testPMADisplayTablesInEditPrivs()
 {
     // Setup for the test
     $GLOBALS['dbi']->expects($this->any())->method('fetchRow')->will($this->onConsecutiveCalls(array('t<bl'), array('ab"c')));
     // Test case 1
     $actual = PMA_displayTablesInEditPrivs('testdb', array());
     $this->assertTag(PMA_getTagArray('<input type="hidden" name="dbname" value="testdb"/>'), $actual);
     $this->assertTag(PMA_getTagArray('<label for="text_tablename">', array('content' => 'Add privileges on the following table:')), $actual);
     $this->assertTag(PMA_getTagArray('<input type="text" id="text_tablename" name="tablename" />'), $actual);
     $this->assertTag(PMA_getTagArray('<select name="pred_tablename" class="autosubmit">'), $actual);
     $this->assertTag(PMA_getTagArray('<option value="" selected="selected">', array('content' => 'Use text field:')), $actual);
     // assertTag doesn't seems to work with content having escaped html chars
     $this->assertContains('<option value="t&lt;bl">t&lt;bl</option>', $actual);
     $this->assertContains('<option value="ab&quot;c">ab&quot;c</option>', $actual);
     $this->assertContains('<input type="text" id="text_tablename" name="tablename" />', $actual);
 }
 /**
  * Test for AuthenticationHttp::authSetFails
  *
  * @return void
  *
  * @group medium
  */
 public function testAuthFails()
 {
     $dbi = $this->getMockBuilder('PMA_DatabaseInterface')->disableOriginalConstructor()->getMock();
     $dbi->expects($this->at(0))->method('getError')->will($this->returnValue('error 123'));
     $dbi->expects($this->at(1))->method('getError')->will($this->returnValue('error 321'));
     $dbi->expects($this->at(2))->method('getError')->will($this->returnValue(null));
     $GLOBALS['dbi'] = $dbi;
     $GLOBALS['errno'] = 31;
     ob_start();
     $this->object->authFails();
     $result = ob_get_clean();
     $this->assertTag(PMA_getTagArray('<p>error 123</p>'), $result);
     $this->object = $this->getMockBuilder('AuthenticationHttp')->disableOriginalConstructor()->setMethods(array('authForm'))->getMock();
     $this->object->expects($this->exactly(2))->method('authForm');
     // case 2
     $GLOBALS['cfg']['Server']['host'] = 'host';
     $GLOBALS['errno'] = 1045;
     $this->assertTrue($this->object->authFails());
     // case 3
     $GLOBALS['errno'] = 1043;
     $this->assertTrue($this->object->authFails());
 }
    /**
     * Test for PMA_userprefsAutoloadGetHeader
     *
     * @return void
     */
    public function testUserprefsAutoloadGetHeader()
    {
        $_SESSION['userprefs_autoload'] = false;
        $_REQUEST['prefs_autoload'] = 'hide';

        $this->assertEquals(
            '',
            PMA_userprefsAutoloadGetHeader()
        );

        $this->assertTrue(
            $_SESSION['userprefs_autoload']
        );

        $_REQUEST['prefs_autoload'] = 'nohide';
        $GLOBALS['cfg']['ServerDefault'] = 1;
        $GLOBALS['PMA_PHP_SELF'] = 'phpunit';
        $result = PMA_userprefsAutoloadGetHeader();

        $this->assertTag(
            PMA_getTagArray(
                '<form action="prefs_manage.php" method="post">'
            ),
            $result
        );

        $this->assertTag(
            PMA_getTagArray(
                '<input type="hidden" name="token" value="token"'
            ),
            $result
        );

        $this->assertTag(
            PMA_getTagArray(
                '<input type="hidden" name="json" value="" />'
            ),
            $result
        );

        $this->assertTag(
            PMA_getTagArray(
                '<input type="hidden" name="submit_import" value="1" />'
            ),
            $result
        );

        $this->assertTag(
            PMA_getTagArray(
                '<input type="hidden" name="return_url" value="phpunit?" />'
            ),
            $result
        );
    }
    /**
     * Test for PMA_displayFieldsetBottom()
     *
     * @return void
     */
    public function testDisplayFieldsetBottom()
    {
        if (! PMA_HAS_RUNKIT) {
            $this->markTestSkipped('Cannot modify constant');
        }

        // with PMA_SETUP

        if (!defined('PMA_SETUP')) {
            define('PMA_SETUP', true);
        }

        ob_start();
        PMA_displayFieldsetBottom();
        $result = ob_get_clean();

        $this->assertTag(
            PMA_getTagArray(
                '<td colspan="3" class="lastrow">'
            ),
            $result
        );

        $this->assertTag(
            PMA_getTagArray(
                '<input type="submit" name="submit_save" value="Apply"',
                array(
                    'parent' => array('tag' => 'td')
                )
            ),
            $result
        );

        $this->assertTag(
            PMA_getTagArray(
                '<input type="button" name="submit_reset" value="Reset" />',
                array(
                    'parent' => array('tag' => 'td')
                )
            ),
            $result
        );

        $this->assertContains(
            '</fieldset>',
            $result
        );

        // without PMA_SETUP

        runkit_constant_remove('PMA_SETUP');

        ob_start();
        PMA_displayFieldsetBottom();
        $result = ob_get_clean();

        $this->assertTag(
            PMA_getTagArray(
                '<td colspan="2" class="lastrow">'
            ),
            $result
        );
    }
 /**
  * Test for PMA_getHtmlForInsertEditRow
  *
  * @return void
  */
 public function testGetHtmlForInsertEditRow()
 {
     $o_rows = 0;
     $tabindex = 0;
     $GLOBALS['plugin_scripts'] = array();
     $GLOBALS['cfg']['LongtextDoubleTextarea'] = true;
     $GLOBALS['cfg']['CharEditing'] = true;
     $table_columns = array(array('Field' => 'test', 'Type' => 'longtext', 'Null' => 'Yes', 'pma_type' => 'longtext', 'True_Type' => 'longtext'));
     $actual = PMA_getHtmlForInsertEditRow(array(), $table_columns, array(), array(), false, array(), '', '', '', false, array(), $o_rows, $tabindex, 1, false, 0, array(), 0, 0, 'table', 'db', 0, array(), 0, '', array(), array('wc'));
     $this->assertContains('test', $actual);
     $this->assertTag(PMA_getTagArray('<th>', array('content' => 'Column')), $actual);
     $this->assertTag(PMA_getTagArray('<a>', array('content' => 'Type')), $actual);
     $this->assertTag(PMA_getTagArray('<th>', array('content' => 'Value')), $actual);
     $this->assertTag(PMA_getTagArray('<span class="column_type">', array('content' => 'longtext')), $actual);
     $this->assertTag(PMA_getTagArray('<textarea name="fields[098f6bcd4621d373cade4e832627b4f6]">'), $actual);
 }
 /**
  * Test for AuthenticationConfig::auth
  *
  * @return void
  */
 public function testAuth()
 {
     $restoreInstance = PMA_Response::getInstance();
     // Case 1
     $mockResponse = $this->getMockBuilder('PMA_Response')->disableOriginalConstructor()->setMethods(array('isAjax', 'isSuccess', 'addJSON'))->getMock();
     $mockResponse->expects($this->once())->method('isAjax')->with()->will($this->returnValue(true));
     $mockResponse->expects($this->once())->method('isSuccess')->with(false);
     $mockResponse->expects($this->once())->method('addJSON')->with('message', PMA_Message::error('1<br /><br />[ <a href="https://phpmyadmin.net/" ' . 'class="ajax login-link">Log in</a> ]'));
     $attrInstance = new ReflectionProperty('PMA_Response', '_instance');
     $attrInstance->setAccessible(true);
     $attrInstance->setValue(null, $mockResponse);
     $GLOBALS['conn_error'] = true;
     $GLOBALS['cfg']['PmaAbsoluteUri'] = 'https://phpmyadmin.net/';
     $this->assertTrue($this->object->auth());
     // Case 2
     $mockResponse = $this->getMockBuilder('PMA_Response')->disableOriginalConstructor()->setMethods(array('isAjax', 'isSuccess', 'addJSON'))->getMock();
     $mockResponse->expects($this->once())->method('isAjax')->with()->will($this->returnValue(true));
     $mockResponse->expects($this->once())->method('isSuccess')->with(false);
     $mockResponse->expects($this->once())->method('addJSON')->with('message', PMA_Message::error('Your session has expired. Please log in again.' . '<br /><br />[ <a href="https://phpmyadmin.net/" ' . 'class="ajax login-link">Log in</a> ]'));
     $attrInstance = new ReflectionProperty('PMA_Response', '_instance');
     $attrInstance->setAccessible(true);
     $attrInstance->setValue(null, $mockResponse);
     $GLOBALS['conn_error'] = '';
     $this->assertTrue($this->object->auth());
     // case 3
     $mockResponse = $this->getMockBuilder('PMA_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'] = '******';
     $GLOBALS['pma_auth_server'] = 'localhost';
     // mock footer
     $mockFooter = $this->getMockBuilder('PMA_Footer')->disableOriginalConstructor()->setMethods(array('setMinimal'))->getMock();
     $mockFooter->expects($this->once())->method('setMinimal')->with();
     // mock header
     $mockHeader = $this->getMockBuilder('PMA_Header')->disableOriginalConstructor()->setMethods(array('setBodyId', 'setTitle', 'disableMenu', 'disableWarnings'))->getMock();
     $mockHeader->expects($this->once())->method('setBodyId')->with('loginform');
     $mockHeader->expects($this->once())->method('setTitle')->with('phpMyAdmin');
     $mockHeader->expects($this->once())->method('disableMenu')->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_Response', '_instance');
     $attrInstance->setAccessible(true);
     $attrInstance->setValue(null, $mockResponse);
     $GLOBALS['pmaThemeImage'] = 'test';
     $GLOBALS['conn_error'] = true;
     $GLOBALS['cfg']['Lang'] = 'en';
     $GLOBALS['cfg']['AllowArbitraryServer'] = true;
     $GLOBALS['cfg']['Servers'] = array(1, 2);
     $_SESSION['last_valid_captcha'] = true;
     $GLOBALS['target'] = 'testTarget';
     $GLOBALS['db'] = 'testDb';
     $GLOBALS['table'] = 'testTable';
     file_put_contents('testlogo_right.png', '');
     // mock error handler
     $mockErrorHandler = $this->getMockBuilder('PMA_Error_Handler')->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->assertTag(PMA_getTagArray('<img src="testlogo_right.png" id="imLogo"'), $result);
     $this->assertTag(PMA_getTagArray('<div class="error">'), $result);
     $this->assertTag(PMA_getTagArray('<form method="post" action="index.php" name="login_form" ' . 'class="disableAjax login hide js-show">'), $result);
     $this->assertTag(PMA_getTagArray('<input type="text" name="pma_servername" id="input_servername" ' . 'value="localhost"'), $result);
     $this->assertTag(PMA_getTagArray('<input type="text" name="pma_username" id="input_username" ' . 'value="pmauser" size="24" class="textfield"/>'), $result);
     $this->assertTag(PMA_getTagArray('<input type="password" name="pma_password" id="input_password" ' . 'value="" size="24" class="textfield" />'), $result);
     $this->assertTag(PMA_getTagArray('<select name="server" id="select_server" ' . 'onchange="document.forms[\'login_form\'].' . 'elements[\'pma_servername\'].value = \'\'" >'), $result);
     $this->assertTag(PMA_getTagArray('<input type="hidden" name="target" value="testTarget" />'), $result);
     $this->assertTag(PMA_getTagArray('<input type="hidden" name="db" value="testDb" />'), $result);
     $this->assertTag(PMA_getTagArray('<input type="hidden" name="table" value="testTable" />'), $result);
     @unlink('testlogo_right.png');
     // case 4
     $mockResponse = $this->getMockBuilder('PMA_Response')->disableOriginalConstructor()->setMethods(array('isAjax', 'getFooter', 'getHeader'))->getMock();
     $mockResponse->expects($this->once())->method('isAjax')->with()->will($this->returnValue(false));
     $mockResponse->expects($this->once())->method('getFooter')->with()->will($this->returnValue(new PMA_Footer()));
     $mockResponse->expects($this->once())->method('getHeader')->with()->will($this->returnValue(new PMA_Header()));
     $_REQUEST['old_usr'] = '';
     $GLOBALS['cfg']['LoginCookieRecall'] = false;
     $attrInstance = new ReflectionProperty('PMA_Response', '_instance');
     $attrInstance->setAccessible(true);
     $attrInstance->setValue(null, $mockResponse);
     $GLOBALS['pmaThemeImage'] = 'test';
     $GLOBALS['cfg']['Lang'] = '';
     $GLOBALS['cfg']['AllowArbitraryServer'] = false;
     $GLOBALS['cfg']['Servers'] = array(1);
     $_SESSION['last_valid_captcha'] = false;
     $GLOBALS['cfg']['CaptchaLoginPrivateKey'] = 'testprivkey';
     $GLOBALS['cfg']['CaptchaLoginPublicKey'] = 'testpubkey';
     $GLOBALS['server'] = 0;
     $GLOBALS['error_handler'] = new PMA_Error_Handler();
     ob_start();
     $this->object->auth();
     $result = ob_get_clean();
     // assertions
     $this->assertTag(PMA_getTagArray('<img name="imLogo" id="imLogo" src="testpma_logo.png"'), $result);
     $this->assertTag(PMA_getTagArray('<select name="lang" class="autosubmit" lang="en" dir="ltr" ' . 'id="sel-lang">'), $result);
     $this->assertTag(PMA_getTagArray('<form method="post" action="index.php" name="login_form" ' . 'autocomplete="off" class="disableAjax login hide js-show">'), $result);
     $this->assertTag(PMA_getTagArray('<input type="hidden" name="server" value="0" />'), $result);
     $this->assertContains('src="https://www.google.com/recaptcha/api/challenge?k=testpubkey">', $result);
     $this->assertContains('iframe src="https://www.google.com/recaptcha/api/noscript' . '?k=testpubkey"', $result);
     $this->assertContains('<textarea name="recaptcha_challenge_field" rows="3" cols="40">', $result);
     $this->assertContains('<input type="hidden" name="recaptcha_response_field"', $result);
     $this->assertContains('$("#recaptcha_reload_btn").addClass("disableAjax");', $result);
     $this->assertContains('$("#recaptcha_switch_audio_btn").addClass("disableAjax");', $result);
     $this->assertContains('$("#recaptcha_switch_img_btn").addClass("disableAjax");', $result);
     $attrInstance->setValue(null, $restoreInstance);
 }
 /**
  * Test for PMA_getHtmlForRelationalFieldSelection
  *
  * @return void
  */
 function testGetHtmlForRelationalFieldSelection()
 {
     $db = '';
     $table = '';
     $field = 'foo';
     $foreignData = array();
     $foreignData['disp_row'] = '';
     $fieldkey = 'bar';
     $data = array();
     $_REQUEST['rownumber'] = 1;
     $_REQUEST['foreign_filter'] = '5';
     $result = PMA_getHtmlForRelationalFieldSelection($db, $table, $field, $foreignData, $fieldkey, $data);
     $this->assertTag(PMA_getTagArray('<form class="ajax" ' . 'id="browse_foreign_form" name="browse_foreign_from" ' . 'action="browse_foreigners.php" method="post">'), $result);
     $this->assertTag(PMA_getTagArray('<fieldset>'), $result);
     $this->assertTag(PMA_getTagArray('<input type="hidden" name="field" value="foo" />'), $result);
     $this->assertTag(PMA_getTagArray('<input type="hidden" name="fieldkey" value="bar" />'), $result);
     $this->assertTag(PMA_getTagArray('<input type="hidden" name="rownumber" value="1" />'), $result);
     $this->assertTag(PMA_getTagArray('<span class="formelement">'), $result);
     $this->assertTag(PMA_getTagArray('<label for="input_foreign_filter">', array('content' => 'Search:')), $result);
     $this->assertTag(PMA_getTagArray('<input type="text" name="foreign_filter" ' . 'id="input_foreign_filter" ' . 'value="5" data-old="5" ' . '/>'), $result);
     $this->assertTag(PMA_getTagArray('<input type="submit" name="submit_foreign_filter" value="Go" />'), $result);
     $this->assertTag(PMA_getTagArray('<span class="formelement">', array('content' => '')), $result);
     $this->assertTag(PMA_getTagArray('<table width="100%" id="browse_foreign_table">'), $result);
     $foreignData['disp_row'] = array();
     $foreignData['the_total'] = 5;
     $GLOBALS['cfg']['ShowAll'] = false;
     $result = PMA_getHtmlForRelationalFieldSelection($db, $table, $field, $foreignData, $fieldkey, $data);
     $this->assertTag(PMA_getTagArray('<table width="100%" id="browse_foreign_table">'), $result);
     $this->assertTag(PMA_getTagArray('<th>', array('content' => 'Keyname')), $result);
     $this->assertTag(PMA_getTagArray('<th>', array('content' => 'Description')), $result);
 }