Welcome to mirror list, hosted at ThFree Co, Russian Federation.

PMA_headerLocation_test.php « core « libraries « test - github.com/phpmyadmin/phpmyadmin.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 012ba6174b44b0e49c9371ba6ff747cc8a89664f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
<?php
/* vim: set expandtab sw=4 ts=4 sts=4: */
/**
 * Test for PMA_sendHeaderLocation
 *
 * @package PhpMyAdmin-test
 */

/*
 * Include to test.
 */
require_once 'libraries/Util.class.php';
require_once 'libraries/vendor_config.php';
require_once 'libraries/core.lib.php';
require_once 'libraries/js_escape.lib.php';
require_once 'libraries/select_lang.lib.php';
require_once 'libraries/sanitizing.lib.php';
require_once 'libraries/Config.class.php';
require_once 'libraries/url_generating.lib.php';
require_once 'libraries/Theme.class.php';
require_once 'libraries/Table.class.php';
require_once 'libraries/php-gettext/gettext.inc';
require_once 'libraries/Response.class.php';

/**
 * Test function sending headers.
 * Warning - these tests set constants, so it can interfere with other tests
 * If you have runkit extension, then it is possible to back changes made on
 * constants rest of options can be tested only with apd, when functions header
 * and headers_sent are redefined rename_function() of header and headers_sent
 * may cause CLI error report in Windows XP (but tests are done correctly)
 * additional functions which were created during tests must be stored to
 * coverage test e.g.
 *
 * <code>
 * rename_function(
 *     'headers_sent',
 *     'headers_sent'.str_replace(array('.', ' '),array('', ''),microtime())
 * );
 * </code>
 *
 * @package PhpMyAdmin-test
 */

class PMA_HeaderLocation_Test extends PHPUnit_Framework_TestCase
{

    protected $oldIISvalue;
    protected $oldSIDvalue;
    protected $runkitExt;
    protected $apdExt;

    /**
     * Set up
     *
     * @return void
     */
    public function setUp()
    {
        //session_start();

        // cleaning constants
        if (PMA_HAS_RUNKIT) {

            $this->oldIISvalue = 'non-defined';

            $defined_constants = get_defined_constants(true);
            $user_defined_constants = $defined_constants['user'];
            if (array_key_exists('PMA_IS_IIS', $user_defined_constants)) {
                $this->oldIISvalue = PMA_IS_IIS;
                runkit_constant_redefine('PMA_IS_IIS', null);
            } else {
                runkit_constant_add('PMA_IS_IIS', null);
            }

            $this->oldSIDvalue = 'non-defined';

            if (array_key_exists('SID', $user_defined_constants)) {
                $this->oldSIDvalue = SID;
                runkit_constant_redefine('SID', null);
            } else {
                runkit_constant_add('SID', null);
            }

        }
        $_SESSION['PMA_Theme'] = PMA_Theme::load('./themes/pmahomme');
        $GLOBALS['server'] = 0;
        $GLOBALS['PMA_Config'] = new PMA_Config();
        $GLOBALS['PMA_Config']->enableBc();
    }

    /**
     * Tear down
     *
     * @return void
     */
    public function tearDown()
    {
        //session_destroy();

        // cleaning constants
        if (PMA_HAS_RUNKIT) {

            if ($this->oldIISvalue != 'non-defined') {
                runkit_constant_redefine('PMA_IS_IIS', $this->oldIISvalue);
            } elseif (defined('PMA_IS_IIS')) {
                runkit_constant_remove('PMA_IS_IIS');
            }

            if ($this->oldSIDvalue != 'non-defined') {
                runkit_constant_redefine('SID', $this->oldSIDvalue);
            } elseif (defined('SID')) {
                runkit_constant_remove('SID');
            }
        }
    }

    /**
     * Test for PMA_sendHeaderLocation
     *
     * @return void
     */
    public function testSendHeaderLocationWithSidUrlWithQuestionMark()
    {
        if (defined('PMA_TEST_HEADERS')) {

            runkit_constant_redefine('SID', md5('test_hash'));

            $testUri = 'http://testurl.com/test.php?test=test';
            $separator = PMA_URL_getArgSeparator();

            $header = array('Location: ' . $testUri . $separator . SID);

            /* sets $GLOBALS['header'] */
            PMA_sendHeaderLocation($testUri);

            $this->assertEquals($header, $GLOBALS['header']);

        } else {
            $this->markTestSkipped(
                'Cannot redefine constant/function - missing runkit extension'
            );
        }

    }

    /**
     * Test for PMA_sendHeaderLocation
     *
     * @return void
     */
    public function testSendHeaderLocationWithSidUrlWithoutQuestionMark()
    {
        if (defined('PMA_TEST_HEADERS')) {

            runkit_constant_redefine('SID', md5('test_hash'));

            $testUri = 'http://testurl.com/test.php';

            $header = array('Location: ' . $testUri . '?' . SID);

            PMA_sendHeaderLocation($testUri);            // sets $GLOBALS['header']
            $this->assertEquals($header, $GLOBALS['header']);

        } else {
            $this->markTestSkipped(
                'Cannot redefine constant/function - missing runkit extension'
            );
        }

    }

    /**
     * Test for PMA_sendHeaderLocation
     *
     * @return void
     */
    public function testSendHeaderLocationWithoutSidWithIis()
    {
        if (defined('PMA_TEST_HEADERS')) {

            runkit_constant_redefine('PMA_IS_IIS', true);

            $testUri = 'http://testurl.com/test.php';

            $header = array('Location: ' . $testUri);
            PMA_sendHeaderLocation($testUri); // sets $GLOBALS['header']
            $this->assertEquals($header, $GLOBALS['header']);

            //reset $GLOBALS['header'] for the next assertion
            unset($GLOBALS['header']);

            $header = array('Refresh: 0; ' . $testUri);
            PMA_sendHeaderLocation($testUri, true); // sets $GLOBALS['header']
            $this->assertEquals($header, $GLOBALS['header']);

        } else {
            $this->markTestSkipped(
                'Cannot redefine constant/function - missing runkit extension'
            );
        }

    }

    /**
     * Test for PMA_sendHeaderLocation
     *
     * @return void
     */
    public function testSendHeaderLocationWithoutSidWithoutIis()
    {
        if (defined('PMA_TEST_HEADERS')) {

            $testUri = 'http://testurl.com/test.php';
            $header = array('Location: ' . $testUri);

            PMA_sendHeaderLocation($testUri);            // sets $GLOBALS['header']
            $this->assertEquals($header, $GLOBALS['header']);

        } else {
            $this->markTestSkipped(
                'Cannot redefine constant/function - missing runkit extension'
            );
        }

    }

    /**
     * Test for PMA_sendHeaderLocation
     *
     * @return void
     */
    public function testSendHeaderLocationIisLongUri()
    {
        if (defined('PMA_IS_IIS') && PMA_HAS_RUNKIT) {
            runkit_constant_redefine('PMA_IS_IIS', true);
        } elseif (!defined('PMA_IS_IIS')) {
            define('PMA_IS_IIS', true);
        } else {
            $this->markTestSkipped(
                'Cannot redefine constant/function - missing runkit extension'
            );
        }

        // over 600 chars
        $testUri = 'http://testurl.com/test.php?testlonguri=over600chars&test=test'
            . '&test=test&test=test&test=test&test=test&test=test&test=test'
            . '&test=test&test=test&test=test&test=test&test=test&test=test'
            . '&test=test&test=test&test=test&test=test&test=test&test=test'
            . '&test=test&test=test&test=test&test=test&test=test&test=test'
            . '&test=test&test=test&test=test&test=test&test=test&test=test'
            . '&test=test&test=test&test=test&test=test&test=test&test=test'
            . '&test=test&test=test&test=test&test=test&test=test&test=test'
            . '&test=test&test=test&test=test&test=test&test=test&test=test'
            . '&test=test&test=test&test=test&test=test&test=test&test=test'
            . '&test=test&test=test';
        $testUri_html = htmlspecialchars($testUri);
        $testUri_js = PMA_escapeJsString($testUri);

        $header =    "<html><head><title>- - -</title>\n" .
                    "<meta http-equiv=\"expires\" content=\"0\">\n" .
                    "<meta http-equiv=\"Pragma\" content=\"no-cache\">\n" .
                    "<meta http-equiv=\"Cache-Control\" content=\"no-cache\">\n" .
                    "<meta http-equiv=\"Refresh\" content=\"0;url=" . $testUri_html
                    . "\">\n" .
                    "<script type=\"text/javascript\">\n" .
                    "//<![CDATA[\n" .
                    "setTimeout(\"window.location = unescape('\"" . $testUri_js
                    . "\"')\", 2000);\n" .
                    "//]]>\n" .
                    "</script>\n" .
                    "</head>\n" .
                    "<body>\n" .
                    "<script type=\"text/javascript\">\n" .
                    "//<![CDATA[\n" .
                    "document.write('<p><a href=\"" . $testUri_html . "\">"
                    . __('Go') . "</a></p>');\n" .
                    "//]]>\n" .
                    "</script></body></html>\n";

        $this->expectOutputString($header);

        PMA_sendHeaderLocation($testUri);
    }
}
?>