undefined variables after deleting a user
[phpmyadmin/madhuracj.git] / test / PMA_headerLocation_test.php
blob5d0a02d3b3b2c0be7fc4552d1cc86eb1822747f1
1 <?php
2 /* vim: set expandtab sw=4 ts=4 sts=4: */
3 /**
4 * Test for PMA_sendHeaderLocation
6 * @author Michal Biniek <michal@bystrzyca.pl>
7 * @version $Id$
8 */
10 /**
11 * Tests core.
13 require_once 'PHPUnit/Framework.php';
14 require_once 'PHPUnit/Extensions/OutputTestCase.php';
16 /**
17 * Include to test.
19 require_once './libraries/common.lib.php';
20 require_once './libraries/url_generating.lib.php';
21 require_once './libraries/core.lib.php';
22 require_once './libraries/select_lang.lib.php';
24 /**
25 * Test function sending headers.
26 * Warning - these tests set constants, so it can interfere with other tests
27 * If you have runkit extension, then it is possible to back changes made on constants
28 * rest of options can be tested only with apd, when functions header and headers_sent are redefined
29 * rename_function() of header and headers_sent may cause CLI error report in Windows XP (but tests are done correctly)
30 * additional functions which were created during tests must be stored to coverage test e.g.
32 * <code>rename_function('headers_sent', 'headers_sent'.str_replace(array('.', ' '),array('', ''),microtime()));</code>
34 * @package phpMyAdmin-test
37 class PMA_headerLocation_test extends PHPUnit_Extensions_OutputTestCase
40 protected $oldIISvalue;
41 protected $oldSIDvalue;
42 protected $runkitExt;
43 protected $apdExt;
47 public function __construct()
49 parent::__construct();
50 $this->runkitExt = false;
51 if (function_exists("runkit_constant_redefine"))
52 $this->runkitExt = true;
54 $this->apdExt = false;
55 if (function_exists("rename_function"))
56 $this->apdExt = true;
59 if ($this->apdExt && !$GLOBALS['test_header']) {
61 // using apd extension to overriding header and headers_sent functions for test purposes
62 $GLOBALS['test_header'] = 1;
64 // rename_function() of header and headers_sent may cause CLI error report in Windows XP
65 rename_function('header', 'test_header');
66 rename_function('headers_sent', 'test_headers_sent');
68 // solution from: http://unixwars.com/2008/11/29/override_function-in-php/ to overriding more than one function
70 $substs = array(
71 'header' => 'if (isset($GLOBALS["header"])) $GLOBALS["header"] .= $a; else $GLOBALS["header"] = $a;',
72 'headers_sent' => 'return false;'
75 $args = array(
76 'header' => '$a',
77 'headers_sent' => ''
80 foreach ($substs as $func => $ren_func) {
81 if (function_exists("__overridden__"))
82 rename_function("__overridden__", str_replace(array('.', ' '),array('', ''),microtime()));
83 override_function($func, $args[$func], $substs[$func]);
84 rename_function("__overridden__", str_replace(array('.', ' '),array('', ''),microtime()));
90 public function __destruct()
92 // rename_function may causes CLI error report in Windows XP, but nothing more happen
94 if ($this->apdExt && $GLOBALS['test_header']) {
95 $GLOBALS['test_header'] = 0;
97 rename_function('header', 'header'.str_replace(array('.', ' '),array('', ''),microtime()));
98 rename_function('headers_sent', 'headers_sent'.str_replace(array('.', ' '),array('', ''),microtime()));
100 rename_function('test_header', 'header');
101 rename_function('test_headers_sent', 'headers_sent');
105 public function setUp()
107 // cleaning constants
108 if ($this->runkitExt) {
110 $this->oldIISvalue = 'non-defined';
112 if (defined('PMA_IS_IIS')) {
113 $this->oldIISvalue = PMA_IS_IIS;
114 runkit_constant_redefine('PMA_IS_IIS', NULL);
116 else {
117 runkit_constant_add('PMA_IS_IIS', NULL);
121 $this->oldSIDvalue = 'non-defined';
123 if (defined('SID')) {
124 $this->oldSIDvalue = SID;
125 runkit_constant_redefine('SID', NULL);
127 else {
128 runkit_constant_add('SID', NULL);
135 public function tearDown()
137 // cleaning constants
138 if ($this->runkitExt) {
140 if ($this->oldIISvalue != 'non-defined')
141 runkit_constant_redefine('PMA_IS_IIS', $this->oldIISvalue);
142 elseif (defined('PMA_IS_IIS')) {
143 runkit_constant_remove('PMA_IS_IIS');
146 if ($this->oldSIDvalue != 'non-defined')
147 runkit_constant_redefine('SID', $this->oldSIDvalue);
148 elseif (defined('SID')) {
149 runkit_constant_remove('SID');
153 if ($this->apdExt)
154 unset($GLOBALS['header']);
159 public function testSendHeaderLocationWithSidUrlWithQuestionMark()
161 if ($this->runkitExt && $this->apdExt) {
163 runkit_constant_redefine('SID', md5('test_hash'));
165 $testUri = 'http://testurl.com/test.php?test=test';
166 $separator = PMA_get_arg_separator();
168 $header = 'Location: ' . $testUri . $separator . SID;
170 PMA_sendHeaderLocation($testUri); // sets $GLOBALS['header']
171 $this->assertEquals($header, $GLOBALS['header']);
173 } else {
174 $this->markTestSkipped('Cannot redefine constant/function - missing APD or/and runkit extension');
179 public function testSendHeaderLocationWithSidUrlWithoutQuestionMark()
181 if ($this->runkitExt && $this->apdExt) {
183 runkit_constant_redefine('SID', md5('test_hash'));
185 $testUri = 'http://testurl.com/test.php';
186 $separator = PMA_get_arg_separator();
188 $header = 'Location: ' . $testUri . '?' . SID;
190 PMA_sendHeaderLocation($testUri); // sets $GLOBALS['header']
191 $this->assertEquals($header, $GLOBALS['header']);
193 } else {
194 $this->markTestSkipped('Cannot redefine constant/function - missing APD or/and runkit extension');
199 public function testSendHeaderLocationWithoutSidWithIis()
201 if ($this->runkitExt && $this->apdExt) {
203 runkit_constant_redefine('PMA_IS_IIS', true);
204 runkit_constant_add('PMA_COMING_FROM_COOKIE_LOGIN', true);
206 $testUri = 'http://testurl.com/test.php';
207 $separator = PMA_get_arg_separator();
209 $header = 'Refresh: 0; ' . $testUri;
211 PMA_sendHeaderLocation($testUri); // sets $GLOBALS['header']
213 // cleaning constant
214 runkit_constant_remove('PMA_COMING_FROM_COOKIE_LOGIN');
216 $this->assertEquals($header, $GLOBALS['header']);
218 } else {
219 $this->markTestSkipped('Cannot redefine constant/function - missing APD or/and runkit extension');
224 public function testSendHeaderLocationWithoutSidWithoutIis()
226 if ($this->apdExt) {
228 $testUri = 'http://testurl.com/test.php';
229 $header = 'Location: ' . $testUri;
231 PMA_sendHeaderLocation($testUri); // sets $GLOBALS['header']
232 $this->assertEquals($header, $GLOBALS['header']);
234 } else {
235 $this->markTestSkipped('Cannot redefine constant/function - missing APD or/and runkit extension');
240 public function testSendHeaderLocationIisLongUri()
242 if (defined('PMA_IS_IIS') && $this->runkitExt)
243 runkit_constant_redefine('PMA_IS_IIS', true);
244 elseif (!defined('PMA_IS_IIS'))
245 define('PMA_IS_IIS', true);
246 else
247 $this->markTestSkipped('Cannot redefine constant/function - missing APD or/and runkit extension');
250 // over 600 chars
251 $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';
252 $testUri_html = htmlspecialchars($testUri);
253 $testUri_js = PMA_escapeJsString($testUri);
255 $GLOBALS['strGo'] = 'test link';
257 $header = "<html><head><title>- - -</title>\n" .
258 "<meta http-equiv=\"expires\" content=\"0\">\n" .
259 "<meta http-equiv=\"Pragma\" content=\"no-cache\">\n" .
260 "<meta http-equiv=\"Cache-Control\" content=\"no-cache\">\n" .
261 "<meta http-equiv=\"Refresh\" content=\"0;url=" . $testUri_html . "\">\n" .
262 "<script type=\"text/javascript\">\n".
263 "//<![CDATA[\n" .
264 "setTimeout(\"window.location = unescape('\"" . $testUri_js . "\"')\", 2000);\n" .
265 "//]]>\n" .
266 "</script>\n" .
267 "</head>\n" .
268 "<body>\n" .
269 "<script type=\"text/javascript\">\n" .
270 "//<![CDATA[\n" .
271 "document.write('<p><a href=\"" . $testUri_html . "\">" . $GLOBALS['strGo'] . "</a></p>');\n" .
272 "//]]>\n" .
273 "</script></body></html>\n";
276 $this->expectOutputString($header);
278 PMA_sendHeaderLocation($testUri);
282 * other output tests
285 public function testWriteReloadNavigation()
287 $GLOBALS['reload'] = true;
288 $GLOBALS['db'] = 'test_db';
290 $url = './navigation.php?db='.$GLOBALS['db'] . '&lang=en-utf-8&convcharset=utf-8';
291 $write = PHP_EOL . '<script type="text/javascript">' . PHP_EOL .
292 '//<![CDATA[' . PHP_EOL .
293 'if (typeof(window.parent) != \'undefined\'' . PHP_EOL .
294 ' && typeof(window.parent.frame_navigation) != \'undefined\'' . PHP_EOL .
295 ' && window.parent.goTo) {' . PHP_EOL .
296 ' window.parent.goTo(\'' . $url . '\');' . PHP_EOL .
297 '}' . PHP_EOL .
298 '//]]>' . PHP_EOL .
299 '</script>' . PHP_EOL;
301 $this->expectOutputString($write);
302 PMA_reloadNavigation();
304 $this->assertFalse(isset($GLOBALS['reload']));
305 unset($GLOBALS['db']);