From eaf8b14e1601f2385a8724830e93603f24a1a1e3 Mon Sep 17 00:00:00 2001 From: php-curl-class Date: Wed, 21 Aug 2013 12:46:30 -0700 Subject: [PATCH] Add POST file path upload test --- tests/helper.inc.php | 9 +++++++++ tests/run.php | 14 ++++++++++++++ tests/server.php | 4 ++++ 3 files changed, 27 insertions(+) diff --git a/tests/helper.inc.php b/tests/helper.inc.php index 91be6f8..eebdf23 100644 --- a/tests/helper.inc.php +++ b/tests/helper.inc.php @@ -14,3 +14,12 @@ class Test { return $this->curl->response; } } + +function get_raw_image() { + // PNG image data, 1 x 1, 1-bit colormap, non-interlaced + ob_start(); + imagepng(imagecreatefromstring(base64_decode('R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7'))); + $raw_image = ob_get_contents(); + ob_end_clean(); + return $raw_image; +} diff --git a/tests/run.php b/tests/run.php index cb8afcd..194a071 100644 --- a/tests/run.php +++ b/tests/run.php @@ -43,6 +43,20 @@ class CurlTest extends PHPUnit_Framework_TestCase { )) === 'post'); } + public function testPostFilePathUpload() { + $tmp_filename = tempnam('/tmp', 'php-curl-class.'); + file_put_contents($tmp_filename, get_raw_image()); + + $test = new Test(); + $this->assertTrue($test->server('POST', array( + 'test' => 'post_file_path_upload', + 'key' => 'image', + 'image' => '@' . $tmp_filename, + )) === 'image/png'); + + unlink($tmp_filename); + } + public function testPut() { $test = new Test(); $this->assertTrue($test->server('PUT', array( diff --git a/tests/server.php b/tests/server.php index f823125..33b78ee 100644 --- a/tests/server.php +++ b/tests/server.php @@ -19,6 +19,10 @@ if ($test == 'http_basic_auth') { )); exit; } +else if ($test === 'post_file_path_upload') { + echo mime_content_type($_FILES[$key]['tmp_name']); + exit; +} header('Content-Type: text/plain');