-
-
Notifications
You must be signed in to change notification settings - Fork 88
/
Copy pathRequestFactory.scriptPath.phpt
163 lines (114 loc) · 4.06 KB
/
RequestFactory.scriptPath.phpt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
<?php
/**
* Test: Nette\Http\RequestFactory scriptPath detection.
*/
declare(strict_types=1);
use Nette\Http\RequestFactory;
use Tester\Assert;
require __DIR__ . '/../bootstrap.php';
$factory = new RequestFactory;
test('script path detection from REQUEST_URI and SCRIPT_NAME', function () use ($factory) {
$_SERVER = [
'REQUEST_URI' => '/projects/modules-usage/www/',
'SCRIPT_NAME' => '/projects/modules-usage/www/index.php',
];
Assert::same('/projects/modules-usage/www/', $factory->fromGlobals()->getUrl()->getScriptPath());
});
test('URL-encoded path normalization in script path', function () use ($factory) {
$_SERVER = [
'REQUEST_URI' => '/projects/modules-usage/%77%77%77/',
'SCRIPT_NAME' => '/projects/modules-usage/www/index.php',
];
Assert::same('/projects/modules-usage/www/', $factory->fromGlobals()->getUrl()->getScriptPath());
});
test('nested path detection with script in subdirectory', function () use ($factory) {
$_SERVER = [
'REQUEST_URI' => '/projects/modules-usage/www/default/add-item',
'SCRIPT_NAME' => '/projects/modules-usage/www/index.php',
];
Assert::same('/projects/modules-usage/www/', $factory->fromGlobals()->getUrl()->getScriptPath());
});
test('script path when REQUEST_URI matches SCRIPT_NAME exactly', function () use ($factory) {
$_SERVER = [
'REQUEST_URI' => '/www/index.php',
'SCRIPT_NAME' => '/www/index.php',
];
Assert::same('/www/index.php', $factory->fromGlobals()->getUrl()->getScriptPath());
});
test('directory-like SCRIPT_NAME handling', function () use ($factory) {
$_SERVER = [
'REQUEST_URI' => '/www/',
'SCRIPT_NAME' => '/www/',
];
Assert::same('/www/', $factory->fromGlobals()->getUrl()->getScriptPath());
});
test('path truncation to script directory', function () use ($factory) {
$_SERVER = [
'REQUEST_URI' => '/test/in',
'SCRIPT_NAME' => '/test/index.php',
];
Assert::same('/test/', $factory->fromGlobals()->getUrl()->getScriptPath());
});
test('double slash normalization in script path', function () use ($factory) {
$_SERVER = [
'REQUEST_URI' => '/test//',
'SCRIPT_NAME' => '/test/index.php',
];
Assert::same('/test/', $factory->fromGlobals()->getUrl()->getScriptPath());
});
test('exact match of REQUEST_URI and SCRIPT_NAME as directory', function () use ($factory) {
$_SERVER = [
'REQUEST_URI' => '/sign/in/',
'SCRIPT_NAME' => '/sign/in/',
];
Assert::same('/sign/in/', $factory->fromGlobals()->getUrl()->getScriptPath());
});
test('mismatched directory levels between URI and script', function () use ($factory) {
$_SERVER = [
'REQUEST_URI' => '/configuration/',
'SCRIPT_NAME' => '/configuration/www/index.php',
];
Assert::same('/configuration/', $factory->fromGlobals()->getUrl()->getScriptPath());
});
test('case sensitivity in script path components', function () use ($factory) {
$_SERVER = [
'REQUEST_URI' => '/blog/WWW/',
'SCRIPT_NAME' => '/blog/www/index.php',
];
Assert::same('/blog/WWW/', $factory->fromGlobals()->getUrl()->getScriptPath());
});
test('Windows-style SCRIPT_NAME handling', function () use ($factory) {
$_SERVER = [
'REQUEST_URI' => '/',
'SCRIPT_NAME' => 'c:\index.php',
];
Assert::same('/', $factory->fromGlobals()->getUrl()->getScriptPath());
});
test('missing REQUEST_URI fallback', function () use ($factory) {
$_SERVER = [
'REQUEST_URI' => null,
'SCRIPT_NAME' => 'c:\index.php',
];
Assert::same('/', $factory->fromGlobals()->getUrl()->getScriptPath());
});
test('missing SCRIPT_NAME fallback', function () use ($factory) {
$_SERVER = [
'REQUEST_URI' => '/',
'SCRIPT_NAME' => null,
];
Assert::same('/', $factory->fromGlobals()->getUrl()->getScriptPath());
});
test('complete absence of URI and script data', function () use ($factory) {
$_SERVER = [
'REQUEST_URI' => null,
'SCRIPT_NAME' => null,
];
Assert::same('/', $factory->fromGlobals()->getUrl()->getScriptPath());
});
test('root script path detection with deep URI', function () use ($factory) {
$_SERVER = [
'REQUEST_URI' => '/documents/show/5474',
'SCRIPT_NAME' => '/index.php',
];
Assert::same('/', $factory->fromGlobals()->getUrl()->getScriptPath());
});