20
20
package php
21
21
22
22
import (
23
+ "fmt"
23
24
"net/http"
24
25
"testing"
25
26
@@ -33,6 +34,7 @@ type PHPFPMSuite struct{}
33
34
var _ = Suite (& PHPFPMSuite {})
34
35
35
36
func (s * PHPFPMSuite ) TestGenerateEnv (c * C ) {
37
+
36
38
testdataDir := "testdata"
37
39
tests := []struct {
38
40
uri string
@@ -182,6 +184,83 @@ func (s *PHPFPMSuite) TestGenerateEnv(c *C) {
182
184
"SCRIPT_NAME" : "/index.php" ,
183
185
},
184
186
},
187
+ {
188
+ passthru : "/index.php" ,
189
+ uri : "/subdirectory" ,
190
+ expected : map [string ]string {
191
+ "PATH_INFO" : "" ,
192
+ "REQUEST_URI" : "/subdirectory" ,
193
+ "QUERY_STRING" : "" ,
194
+ "SCRIPT_FILENAME" : testdataDir + "/public/subdirectory/index.php" ,
195
+ "SCRIPT_NAME" : "/subdirectory/index.php" ,
196
+ },
197
+ },
198
+ {
199
+ passthru : "/index.php" ,
200
+ uri : "/subdirectory/" ,
201
+ expected : map [string ]string {
202
+ "PATH_INFO" : "/" ,
203
+ "REQUEST_URI" : "/subdirectory/" ,
204
+ "QUERY_STRING" : "" ,
205
+ "SCRIPT_FILENAME" : testdataDir + "/public/subdirectory/index.php" ,
206
+ "SCRIPT_NAME" : "/subdirectory/index.php" ,
207
+ },
208
+ },
209
+ {
210
+ passthru : "/index.php" ,
211
+ uri : "/subdirectory/unknown.php" ,
212
+ expected : map [string ]string {
213
+ "PATH_INFO" : "/unknown.php" ,
214
+ "REQUEST_URI" : "/subdirectory/unknown.php" ,
215
+ "QUERY_STRING" : "" ,
216
+ "SCRIPT_FILENAME" : testdataDir + "/public/subdirectory/index.php" ,
217
+ "SCRIPT_NAME" : "/subdirectory/index.php" ,
218
+ },
219
+ },
220
+ {
221
+ passthru : "/index.php" ,
222
+ uri : "/subdirectory/unknown.php/" ,
223
+ expected : map [string ]string {
224
+ "PATH_INFO" : "/unknown.php/" ,
225
+ "REQUEST_URI" : "/subdirectory/unknown.php/" ,
226
+ "QUERY_STRING" : "" ,
227
+ "SCRIPT_FILENAME" : testdataDir + "/public/subdirectory/index.php" ,
228
+ "SCRIPT_NAME" : "/subdirectory/index.php" ,
229
+ },
230
+ },
231
+ {
232
+ passthru : "/index.php" ,
233
+ uri : "/subdirectory/index.php/foo" ,
234
+ expected : map [string ]string {
235
+ "PATH_INFO" : "/foo" ,
236
+ "REQUEST_URI" : "/subdirectory/index.php/foo" ,
237
+ "QUERY_STRING" : "" ,
238
+ "SCRIPT_FILENAME" : testdataDir + "/public/subdirectory/index.php" ,
239
+ "SCRIPT_NAME" : "/subdirectory/index.php" ,
240
+ },
241
+ },
242
+ {
243
+ passthru : "/index.php" ,
244
+ uri : "/subdirectory/subdirectory/" ,
245
+ expected : map [string ]string {
246
+ "PATH_INFO" : "/" ,
247
+ "REQUEST_URI" : "/subdirectory/subdirectory/" ,
248
+ "QUERY_STRING" : "" ,
249
+ "SCRIPT_FILENAME" : testdataDir + "/public/subdirectory/subdirectory/index.php" ,
250
+ "SCRIPT_NAME" : "/subdirectory/subdirectory/index.php" ,
251
+ },
252
+ },
253
+ {
254
+ passthru : "/index.php" ,
255
+ uri : "///subdirectory" ,
256
+ expected : map [string ]string {
257
+ "PATH_INFO" : "" ,
258
+ "REQUEST_URI" : "///subdirectory" ,
259
+ "QUERY_STRING" : "" ,
260
+ "SCRIPT_FILENAME" : testdataDir + "/public/subdirectory/index.php" ,
261
+ "SCRIPT_NAME" : "/subdirectory/index.php" ,
262
+ },
263
+ },
185
264
}
186
265
for _ , test := range tests {
187
266
process := & Server {
@@ -190,14 +269,15 @@ func (s *PHPFPMSuite) TestGenerateEnv(c *C) {
190
269
passthru : test .passthru ,
191
270
}
192
271
req , err := http .NewRequest ("GET" , test .uri , nil )
272
+ fmt .Println ("test" , req .URL .Path , "test" , test .uri )
193
273
c .Assert (err , IsNil )
194
274
195
275
req .RequestURI = test .uri
196
276
env := process .generateEnv (req )
197
277
for k , v := range test .expected {
198
278
vv , ok := env [k ]
199
279
c .Assert (ok , Equals , true )
200
- c .Assert (vv , DeepEquals , v )
280
+ c .Assert (vv , DeepEquals , v , Commentf ( "#test uri: \" %s \" varName: \" %s \" " , test . uri , k ) )
201
281
}
202
282
}
203
283
}
0 commit comments