Converting number of Excel column names no longer limited
[phpmyadmin/arisferyanto.git] / test / PMA_headerLocation_test.php
blob649d914888a65ab4eae7460a2fd93c7b92dedf71
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';
23 /**
24 * Test function sending headers.
25 * Warning - these tests set constants, so it can interfere with other tests
26 * If you have runkit extension, then it is possible to back changes made on constants
27 * rest of options can be tested only with apd, when functions header and headers_sent are redefined
28 * rename_function() of header and headers_sent may cause CLI error report in Windows XP (but tests are done correctly)
29 * additional functions which were created during tests must be stored to coverage test e.g.
31 * <code>rename_function('headers_sent', 'headers_sent'.str_replace(array('.', ' '),array('', ''),microtime()));</code>
33 * @package phpMyAdmin-test
36 class PMA_headerLocation_test extends PHPUnit_Extensions_OutputTestCase
39 protected $oldIISvalue;
40 protected $oldSIDvalue;
41 protected $runkitExt;
42 protected $apdExt;
46 public function __construct()
48 parent::__construct();
49 $this->runkitExt = false;
50 if (function_exists("runkit_constant_redefine"))
51 $this->runkitExt = true;
53 $this->apdExt = false;
54 if (function_exists("rename_function"))
55 $this->apdExt = true;
58 if ($this->apdExt && !$GLOBALS['test_header']) {
60 // using apd extension to overriding header and headers_sent functions for test purposes
61 $GLOBALS['test_header'] = 1;
63 // rename_function() of header and headers_sent may cause CLI error report in Windows XP
64 rename_function('header', 'test_header');
65 rename_function('headers_sent', 'test_headers_sent');
67 // solution from: http://unixwars.com/2008/11/29/override_function-in-php/ to overriding more than one function
69 $substs = array(
70 'header' => 'if (isset($GLOBALS["header"])) $GLOBALS["header"] .= $a; else $GLOBALS["header"] = $a;',
71 'headers_sent' => 'return false;'
74 $args = array(
75 'header' => '$a',
76 'headers_sent' => ''
79 foreach ($substs as $func => $ren_func) {
80 if (function_exists("__overridden__"))
81 rename_function("__overridden__", str_replace(array('.', ' '),array('', ''),microtime()));
82 override_function($func, $args[$func], $substs[$func]);
83 rename_function("__overridden__", str_replace(array('.', ' '),array('', ''),microtime()));
89 public function __destruct()
91 // rename_function may causes CLI error report in Windows XP, but nothing more happen
93 if ($this->apdExt && $GLOBALS['test_header']) {
94 $GLOBALS['test_header'] = 0;
96 rename_function('header', 'header'.str_replace(array('.', ' '),array('', ''),microtime()));
97 rename_function('headers_sent', 'headers_sent'.str_replace(array('.', ' '),array('', ''),microtime()));
99 rename_function('test_header', 'header');
100 rename_function('test_headers_sent', 'headers_sent');
104 public function setUp()
106 // cleaning constants
107 if ($this->runkitExt) {
109 $this->oldIISvalue = 'non-defined';
111 if (defined('PMA_IS_IIS')) {
112 $this->oldIISvalue = PMA_IS_IIS;
113 runkit_constant_redefine('PMA_IS_IIS', NULL);
115 else {
116 runkit_constant_add('PMA_IS_IIS', NULL);
120 $this->oldSIDvalue = 'non-defined';
122 if (defined('SID')) {
123 $this->oldSIDvalue = SID;
124 runkit_constant_redefine('SID', NULL);
126 else {
127 runkit_constant_add('SID', NULL);
134 public function tearDown()
136 // cleaning constants
137 if ($this->runkitExt) {
139 if ($this->oldIISvalue != 'non-defined')
140 runkit_constant_redefine('PMA_IS_IIS', $this->oldIISvalue);
141 elseif (defined('PMA_IS_IIS')) {
142 runkit_constant_remove('PMA_IS_IIS');
145 if ($this->oldSIDvalue != 'non-defined')
146 runkit_constant_redefine('SID', $this->oldSIDvalue);
147 elseif (defined('SID')) {
148 runkit_constant_remove('SID');
152 if ($this->apdExt)
153 unset($GLOBALS['header']);
158 public function testSendHeaderLocationWithSidUrlWithQuestionMark()
160 if ($this->runkitExt && $this->apdExt) {
162 runkit_constant_redefine('SID', md5('test_hash'));
164 $testUri = 'http://testurl.com/test.php?test=test';
165 $separator = PMA_get_arg_separator();
167 $header = 'Location: ' . $testUri . $separator . SID;
169 PMA_sendHeaderLocation($testUri); // sets $GLOBALS['header']
170 $this->assertEquals($header, $GLOBALS['header']);
172 } else {
173 $this->markTestSkipped('Cannot redefine constant/function - missing APD or/and runkit extension');
178 public function testSendHeaderLocationWithSidUrlWithoutQuestionMark()
180 if ($this->runkitExt && $this->apdExt) {
182 runkit_constant_redefine('SID', md5('test_hash'));
184 $testUri = 'http://testurl.com/test.php';
185 $separator = PMA_get_arg_separator();
187 $header = 'Location: ' . $testUri . '?' . SID;
189 PMA_sendHeaderLocation($testUri); // sets $GLOBALS['header']
190 $this->assertEquals($header, $GLOBALS['header']);
192 } else {
193 $this->markTestSkipped('Cannot redefine constant/function - missing APD or/and runkit extension');
198 public function testSendHeaderLocationWithoutSidWithIis()
200 if ($this->runkitExt && $this->apdExt) {
202 runkit_constant_redefine('PMA_IS_IIS', true);
203 runkit_constant_add('PMA_COMING_FROM_COOKIE_LOGIN', true);
205 $testUri = 'http://testurl.com/test.php';
206 $separator = PMA_get_arg_separator();
208 $header = 'Refresh: 0; ' . $testUri;
210 PMA_sendHeaderLocation($testUri); // sets $GLOBALS['header']
212 // cleaning constant
213 runkit_constant_remove('PMA_COMING_FROM_COOKIE_LOGIN');
215 $this->assertEquals($header, $GLOBALS['header']);
217 } else {
218 $this->markTestSkipped('Cannot redefine constant/function - missing APD or/and runkit extension');
223 public function testSendHeaderLocationWithoutSidWithoutIis()
225 if ($this->apdExt) {
227 $testUri = 'http://testurl.com/test.php';
228 $header = 'Location: ' . $testUri;
230 PMA_sendHeaderLocation($testUri); // sets $GLOBALS['header']
231 $this->assertEquals($header, $GLOBALS['header']);
233 } else {
234 $this->markTestSkipped('Cannot redefine constant/function - missing APD or/and runkit extension');
239 public function testSendHeaderLocationIisLongUri()
241 if (defined('PMA_IS_IIS') && $this->runkitExt)
242 runkit_constant_redefine('PMA_IS_IIS', true);
243 elseif (!defined('PMA_IS_IIS'))
244 define('PMA_IS_IIS', true);
245 else
246 $this->markTestSkipped('Cannot redefine constant/function - missing APD or/and runkit extension');
249 // over 600 chars
250 $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 $GLOBALS['strGo'] = 'test link';
254 $header = "<html><head><title>- - -</title>\n" .
255 "<meta http-equiv=\"expires\" content=\"0\">\n" .
256 "<meta http-equiv=\"Pragma\" content=\"no-cache\">\n" .
257 "<meta http-equiv=\"Cache-Control\" content=\"no-cache\">\n" .
258 "<meta http-equiv=\"Refresh\" content=\"0;url=" . $testUri . "\">\n" .
259 "<script type=\"text/javascript\">\n".
260 "//<![CDATA[\n" .
261 "setTimeout(\"window.location = unescape('\"" . $testUri . "\"')\", 2000);\n" .
262 "//]]>\n" .
263 "</script>\n" .
264 "</head>\n" .
265 "<body>\n" .
266 "<script type=\"text/javascript\">\n" .
267 "//<![CDATA[\n" .
268 "document.write('<p><a href=\"" . $testUri . "\">" . $GLOBALS['strGo'] . "</a></p>');\n" .
269 "//]]>\n" .
270 "</script></body></html>\n";
273 $this->expectOutputString($header);
275 PMA_sendHeaderLocation($testUri);
279 * other output tests
282 public function testWriteReloadNavigation()
284 $GLOBALS['reload'] = true;
285 $GLOBALS['db'] = 'test_db';
287 $url = './navigation.php?db='.$GLOBALS['db'];
288 $write = PHP_EOL . '<script type="text/javascript">' . PHP_EOL .
289 '//<![CDATA[' . PHP_EOL .
290 'if (typeof(window.parent) != \'undefined\'' . PHP_EOL .
291 ' && typeof(window.parent.frame_navigation) != \'undefined\'' . PHP_EOL .
292 ' && window.parent.goTo) {' . PHP_EOL .
293 ' window.parent.goTo(\'' . $url . '\');' . PHP_EOL .
294 '}' . PHP_EOL .
295 '//]]>' . PHP_EOL .
296 '</script>' . PHP_EOL;
298 $this->expectOutputString($write);
299 PMA_reloadNavigation();
301 $this->assertFalse(isset($GLOBALS['reload']));
302 unset($GLOBALS['db']);