@@ -14,14 +14,32 @@ private static function callPrivateStatic($obj, string $method, ...$args)
14
14
}
15
15
public function testUriMapping ()
16
16
{
17
- $ uri = static ::callPrivateStatic (UriHelper::class, 'mapReplaceString ' ,
17
+ $ uri = static ::callPrivateStatic (
18
+ UriHelper::class,
19
+ 'mapReplaceString ' ,
18
20
'https://example.com/collection/{id}/{id2} ' ,
19
- ['id ' => 20 , 'id2 ' => 30 ]
21
+ ['id ' => 20 , 'id2 ' => 30 ]
20
22
);
21
23
22
24
$ this ->assertEquals ('https://example.com/collection/20/30 ' , $ uri );
23
25
}
24
26
27
+ public function testEncodeParams ()
28
+ {
29
+ $ ref = new ReflectionClass (UriHelper::class);
30
+ $ method = $ ref ->getMethod ('mixUrlEncodedParams ' );
31
+ $ method ->setAccessible (true );
32
+
33
+ $ this ->assertEquals ('a=1&b=2 ' , $ method ->invokeArgs (null , [
34
+ '' , // encoded_string
35
+ ['a ' => 1 , 'b ' => 2 ] // map
36
+ ]));
37
+ $ this ->assertEquals ('a=1&b%5B0%5D=2&b%5B1%5D=3 ' , $ method ->invokeArgs (null , [
38
+ '' ,
39
+ ['a ' => 1 , 'b ' => [2 , 3 ]]
40
+ ]));
41
+ }
42
+
25
43
public function testGetPathInfo ()
26
44
{
27
45
$ this ->assertEquals ('/some/path ' , UriHelper::getPathInfo ('/some/path ' , '/ ' ));
@@ -37,42 +55,42 @@ public function testGetBaseUrl()
37
55
{
38
56
$ this ->assertEquals (
39
57
'http://localhost/assets/css/style.css ' ,
40
- UriHelper::getBaseUrl ('/assets/css/style.css ' ,[
41
- 'HTTP_HOST ' => 'localhost ' ,
58
+ UriHelper::getBaseUrl ('/assets/css/style.css ' ,[
59
+ 'HTTP_HOST ' => 'localhost ' ,
42
60
'SCRIPT_NAME ' => '/index.php '
43
61
])
44
62
);
45
63
$ this ->assertEquals (
46
64
'https://localhost/assets/css/style.css ' ,
47
- UriHelper::getBaseUrl ('/assets/css/style.css ' ,[
48
- 'HTTP_HOST ' => 'localhost ' ,
49
- 'HTTPS ' => 'on ' ,
65
+ UriHelper::getBaseUrl ('/assets/css/style.css ' ,[
66
+ 'HTTP_HOST ' => 'localhost ' ,
67
+ 'HTTPS ' => 'on ' ,
50
68
'SCRIPT_NAME ' => '/index.php '
51
69
])
52
70
);
53
71
$ this ->assertEquals (
54
72
'https://localhost/public/assets/css/style.css ' ,
55
- UriHelper::getBaseUrl ('/assets/css/style.css ' ,[
56
- 'HTTP_HOST ' => 'localhost ' ,
57
- 'HTTPS ' => 'on ' ,
73
+ UriHelper::getBaseUrl ('/assets/css/style.css ' ,[
74
+ 'HTTP_HOST ' => 'localhost ' ,
75
+ 'HTTPS ' => 'on ' ,
58
76
'SCRIPT_NAME ' => '/public/index.php '
59
77
])
60
78
);
61
79
$ this ->assertEquals (
62
80
'https://localhost/public/assets/css/style.css ' ,
63
- UriHelper::getBaseUrl ('/assets/css/style.css ' ,[
64
- 'HTTPS ' => 'on ' ,
65
- 'SERVER_NAME ' => 'localhost ' ,
66
- 'SERVER_PORT ' => 443 ,
81
+ UriHelper::getBaseUrl ('/assets/css/style.css ' ,[
82
+ 'HTTPS ' => 'on ' ,
83
+ 'SERVER_NAME ' => 'localhost ' ,
84
+ 'SERVER_PORT ' => 443 ,
67
85
'SCRIPT_NAME ' => '/public/index.php '
68
86
])
69
87
);
70
88
$ this ->assertEquals (
71
89
'https://localhost:3000/public/assets/css/style.css ' ,
72
- UriHelper::getBaseUrl ('/assets/css/style.css ' ,[
73
- 'HTTPS ' => 'on ' ,
74
- 'SERVER_NAME ' => 'localhost ' ,
75
- 'SERVER_PORT ' => 3000 ,
90
+ UriHelper::getBaseUrl ('/assets/css/style.css ' ,[
91
+ 'HTTPS ' => 'on ' ,
92
+ 'SERVER_NAME ' => 'localhost ' ,
93
+ 'SERVER_PORT ' => 3000 ,
76
94
'SCRIPT_NAME ' => '/public/index.php '
77
95
])
78
96
);
@@ -90,4 +108,4 @@ public function testGetSiteUrl()
90
108
])
91
109
);
92
110
}
93
- }
111
+ }
0 commit comments