|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
use PHPUnit\Framework\TestCase; |
|
4
|
|
|
|
|
5
|
|
|
class FunctionUserAgentTest extends TestCase |
|
6
|
|
|
{ |
|
7
|
|
|
|
|
8
|
|
|
public static function setUpBeforeClass() |
|
9
|
|
|
{ |
|
10
|
|
|
require_once CORE_FUNCTIONS_PATH . 'function_user_agent.php'; |
|
11
|
|
|
} |
|
12
|
|
|
|
|
13
|
|
|
public function testLoopBack() |
|
14
|
|
|
{ |
|
15
|
|
|
$this->assertEquals('127.0.0.1', get_ip()); |
|
16
|
|
|
} |
|
17
|
|
|
|
|
18
|
|
|
public function testServerRemoteAddr() |
|
19
|
|
|
{ |
|
20
|
|
|
$ip = '182.23.24.56'; |
|
21
|
|
|
$_SERVER['REMOTE_ADDR'] = $ip; |
|
22
|
|
|
$this->assertEquals($ip, get_ip()); |
|
23
|
|
|
} |
|
24
|
|
|
|
|
25
|
|
|
public function testServerHttpClientIp() |
|
26
|
|
|
{ |
|
27
|
|
|
$ip = '192.168.24.1'; |
|
28
|
|
|
$_SERVER['HTTP_CLIENT_IP'] = $ip; |
|
29
|
|
|
$this->assertEquals($ip, get_ip()); |
|
30
|
|
|
} |
|
31
|
|
|
|
|
32
|
|
|
public function testServerHttpXForwardedFor() |
|
33
|
|
|
{ |
|
34
|
|
|
$ip = '172.18.2.1'; |
|
35
|
|
|
$_SERVER['HTTP_X_FORWARDED_FOR'] = $ip; |
|
36
|
|
|
$this->assertEquals($ip, get_ip()); |
|
37
|
|
|
} |
|
38
|
|
|
|
|
39
|
|
|
public function testServerHttpXForwarded() |
|
40
|
|
|
{ |
|
41
|
|
|
|
|
42
|
|
|
$ip = '12.18.2.1'; |
|
43
|
|
|
$_SERVER['HTTP_X_FORWARDED'] = $ip; |
|
44
|
|
|
$this->assertEquals($ip, get_ip()); |
|
45
|
|
|
} |
|
46
|
|
|
|
|
47
|
|
|
public function testServerHttpForwardedFor() |
|
48
|
|
|
{ |
|
49
|
|
|
$ip = '198.180.2.1'; |
|
50
|
|
|
$_SERVER['HTTP_FORWARDED_FOR'] = $ip; |
|
51
|
|
|
$this->assertEquals($ip, get_ip()); |
|
52
|
|
|
} |
|
53
|
|
|
|
|
54
|
|
|
public function testServerHttpForwarded() |
|
55
|
|
|
{ |
|
56
|
|
|
$ip = '220.200.2.1'; |
|
57
|
|
|
$_SERVER['HTTP_FORWARDED'] = $ip; |
|
58
|
|
|
$this->assertEquals($ip, get_ip()); |
|
59
|
|
|
} |
|
60
|
|
|
|
|
61
|
|
|
public function testManyIp() |
|
62
|
|
|
{ |
|
63
|
|
|
$ips = '20.200.2.1, 192.168.34.4'; |
|
64
|
|
|
$ip = '20.200.2.1'; |
|
65
|
|
|
$_SERVER['REMOTE_ADDR'] = $ips; |
|
66
|
|
|
$this->assertEquals($ip, get_ip()); |
|
67
|
|
|
} |
|
68
|
|
|
|
|
69
|
|
|
} |