|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* Test - request function |
|
4
|
|
|
* @package fwolflib |
|
5
|
|
|
* @subpackage func.test |
|
6
|
|
|
* @copyright Copyright 2004-2012, Fwolf |
|
7
|
|
|
* @author Fwolf <[email protected]> |
|
8
|
|
|
* @since 2008-05-08 |
|
9
|
|
|
*/ |
|
10
|
|
|
|
|
11
|
|
|
// Define like this, so test can run both under eclipse and web alone. |
|
12
|
|
|
// {{{ |
|
13
|
|
|
if (! defined('SIMPLE_TEST')) { |
|
14
|
|
|
define('SIMPLE_TEST', 'simpletest/'); |
|
15
|
|
|
require_once(SIMPLE_TEST . 'autorun.php'); |
|
16
|
|
|
} |
|
17
|
|
|
// Then set output encoding |
|
18
|
|
|
//header('Content-Type: text/html; charset=utf-8'); |
|
19
|
|
|
// }}} |
|
20
|
|
|
|
|
21
|
|
|
// Require library define file which need test |
|
22
|
|
|
require_once('fwolflib/func/request.php'); |
|
23
|
|
|
|
|
24
|
|
|
class TestFuncRequest extends UnitTestCase { |
|
25
|
|
|
|
|
26
|
|
|
function TestGetParam() { |
|
|
|
|
|
|
27
|
|
|
$_GET = array('a' => 1); |
|
28
|
|
|
$x = GetParam(); |
|
|
|
|
|
|
29
|
|
|
$y = '?a=1'; |
|
30
|
|
|
$this->assertEqual($x, $y); |
|
31
|
|
|
|
|
32
|
|
|
$_GET = array('a' => 1); |
|
33
|
|
|
$x = GetParam('b', 2); |
|
|
|
|
|
|
34
|
|
|
$y = '?a=1&b=2'; |
|
35
|
|
|
$this->assertEqual($x, $y); |
|
36
|
|
|
|
|
37
|
|
|
$_GET = array('a' => 1, 'b' => '', 'c' => 3); |
|
38
|
|
|
$x = GetParam(array('a' => 2, 1 => 'a'), array('b', 'c')); |
|
|
|
|
|
|
39
|
|
|
$y = '?a=2&1=a'; |
|
40
|
|
|
$this->assertEqual($x, $y); |
|
41
|
|
|
|
|
42
|
|
|
$_GET = array('a' => 1, 'b' => '', 'c' => 3); |
|
43
|
|
|
$x = GetParam(array('a' => 2, 1 => 'a'), 'b'); |
|
|
|
|
|
|
44
|
|
|
$y = '?a=2&c=3&1=a'; |
|
45
|
|
|
$this->assertEqual($x, $y); |
|
46
|
|
|
|
|
47
|
|
|
} // end of func TestGetParam |
|
48
|
|
|
|
|
49
|
|
|
|
|
50
|
|
|
function TestGetUrlPlan() { |
|
|
|
|
|
|
51
|
|
|
$url = 'http://www.google.com/?a=https://something'; |
|
52
|
|
|
$this->assertEqual(GetUrlPlan($url), 'http'); |
|
|
|
|
|
|
53
|
|
|
|
|
54
|
|
|
$url = 'https://www.fwolf.com/'; |
|
55
|
|
|
$this->assertEqual(GetUrlPlan($url), 'https'); |
|
|
|
|
|
|
56
|
|
|
|
|
57
|
|
|
$url = 'ftp://domain.tld/'; |
|
58
|
|
|
$this->assertEqual(GetUrlPlan($url), 'ftp'); |
|
|
|
|
|
|
59
|
|
|
|
|
60
|
|
|
$url = ''; |
|
61
|
|
|
$this->assertPattern('/https?/i', GetUrlPlan($url)); |
|
|
|
|
|
|
62
|
|
|
} // end of func TestGetUrlPlan |
|
63
|
|
|
|
|
64
|
|
|
} // end of class TestFuncRequest |
|
65
|
|
|
|
|
66
|
|
|
|
|
67
|
|
|
// Change output charset in this way. |
|
68
|
|
|
// {{{ |
|
69
|
|
|
$s_url = GetSelfUrl(false); |
|
|
|
|
|
|
70
|
|
|
$s_url = substr($s_url, strrpos($s_url, '/') + 1); |
|
71
|
|
|
if ('request.test.php' == $s_url) { |
|
72
|
|
|
$test = new TestFuncRequest(); |
|
73
|
|
|
$test->run(new HtmlReporter('utf-8')); |
|
74
|
|
|
} |
|
75
|
|
|
// }}} |
|
76
|
|
|
?> |
|
|
|
|
|
|
77
|
|
|
|
Adding explicit visibility (
private,protected, orpublic) is generally recommend to communicate to other developers how, and from where this method is intended to be used.