@@ -332,23 +332,43 @@ public function testOptionsRequestMethod()
332
332
333
333
public function testDownload ()
334
334
{
335
- $ save_to_path = tempnam ('/tmp ' , 'php-curl-class. ' );
336
- $ file_path = Helper \get_png ();
337
-
338
- $ test = new Test ();
339
- $ test ->curl ->setHeader ('X-DEBUG-TEST ' , 'download_response ' );
340
- $ this ->assertTrue ($ test ->curl ->download (Test::TEST_URL , $ save_to_path ));
341
- $ this ->assertEquals (filesize ($ file_path ), filesize ($ save_to_path ));
342
- $ this ->assertEquals (md5_file ($ file_path ), md5_file ($ save_to_path ));
343
- $ this ->assertEquals (md5_file ($ file_path ), $ test ->curl ->response_headers ['ETag ' ]);
344
-
345
- $ test ->curl ->setHeader ('X-DEBUG-TEST ' , 'get ' );
346
- $ test ->curl ->get (Test::TEST_URL );
347
-
348
- unlink ($ file_path );
349
- unlink ($ save_to_path );
350
- $ this ->assertFalse (file_exists ($ file_path ));
351
- $ this ->assertFalse (file_exists ($ save_to_path ));
335
+ // Upload a file.
336
+ $ upload_file_path = Helper \get_png ();
337
+ $ upload_test = new Test ();
338
+ $ upload_test ->server ('upload_response ' , 'POST ' , array (
339
+ 'image ' => '@ ' . $ upload_file_path ,
340
+ ));
341
+ $ uploaded_file_path = $ upload_test ->curl ->response ;
342
+ $ this ->assertNotEquals ($ upload_file_path , $ uploaded_file_path );
343
+ $ this ->assertEquals (md5_file ($ upload_file_path ), md5_file ($ uploaded_file_path ));
344
+ $ this ->assertEquals (md5_file ($ upload_file_path ), $ upload_test ->curl ->response_headers ['ETag ' ]);
345
+
346
+ // Download the file.
347
+ $ downloaded_file_path = tempnam ('/tmp ' , 'php-curl-class. ' );
348
+ $ download_test = new Test ();
349
+ $ download_test ->curl ->setHeader ('X-DEBUG-TEST ' , 'download_response ' );
350
+ $ this ->assertTrue ($ download_test ->curl ->download (Test::TEST_URL . '? ' . http_build_query (array (
351
+ 'file_path ' => $ uploaded_file_path ,
352
+ )), $ downloaded_file_path ));
353
+ $ this ->assertNotEquals ($ uploaded_file_path , $ downloaded_file_path );
354
+
355
+ $ this ->assertEquals (filesize ($ upload_file_path ), filesize ($ downloaded_file_path ));
356
+ $ this ->assertEquals (md5_file ($ upload_file_path ), md5_file ($ downloaded_file_path ));
357
+ $ this ->assertEquals (md5_file ($ upload_file_path ), $ download_test ->curl ->response_headers ['ETag ' ]);
358
+
359
+ // Ensure successive requests set the appropriate values.
360
+ $ this ->assertEquals ('GET ' , $ download_test ->server ('server ' , 'GET ' , array (
361
+ 'key ' => 'REQUEST_METHOD ' ,
362
+ )));
363
+ $ this ->assertFalse (is_bool ($ download_test ->curl ->response ));
364
+ $ this ->assertFalse (is_bool ($ download_test ->curl ->raw_response ));
365
+
366
+ unlink ($ upload_file_path );
367
+ unlink ($ uploaded_file_path );
368
+ unlink ($ downloaded_file_path );
369
+ $ this ->assertFalse (file_exists ($ upload_file_path ));
370
+ $ this ->assertFalse (file_exists ($ uploaded_file_path ));
371
+ $ this ->assertFalse (file_exists ($ downloaded_file_path ));
352
372
}
353
373
354
374
public function testBasicHttpAuth401Unauthorized ()
0 commit comments