diff options
author | uckelman <uckelman@nomic.net> | 2010-05-09 15:21:32 +0000 |
---|---|---|
committer | uckelman <uckelman@nomic.net> | 2010-05-09 15:21:32 +0000 |
commit | 7ca349f02b85dcb4a5569d21a31c90b34e52ab93 (patch) | |
tree | 6758bcf040880b9a3fa9d6d0c5d73f215a539cc5 | |
parent | 6c7844689eeb86bd1676380fea88bf395b599d47 (diff) |
Added test.
git-svn-id: https://vassalengine.svn.sourceforge.net/svnroot/vassalengine/site-src/trunk@6807 67b53d14-2c14-4ace-a08f-0dab2b34000c
-rw-r--r-- | src/HTTP_POST_multipart.php | 12 | ||||
-rw-r--r-- | test/HTTP_POST_multipartTest.php | 34 |
2 files changed, 44 insertions, 2 deletions
diff --git a/src/HTTP_POST_multipart.php b/src/HTTP_POST_multipart.php index 7ccc36a..a4ce2a4 100644 --- a/src/HTTP_POST_multipart.php +++ b/src/HTTP_POST_multipart.php @@ -6,15 +6,23 @@ class HTTP_POST_multipart { protected $_parts = array(); - public function addData($name, $bytes) { + public function addData($name, $data) { + if ($name === null) throw new Exception('name is null'); + if ($data === null) throw new Exception('data is null'); + $this->_parts[] = array( 'name' => $name, - 'data' => $bytes + 'data' => $data ); } public function addFile($name, $filename, $mimetype, $charset, $encoding, $data) { + if ($name === null) throw new Exception('name is null'); + if ($filename === null) throw new Exception('filename is null'); + if ($mimetype === null) throw new Exception('mimetype is null'); + if ($data === null) throw new Exception('data is null'); + $this->_parts[] = array( 'name' => $name, 'filename' => $filename, diff --git a/test/HTTP_POST_multipartTest.php b/test/HTTP_POST_multipartTest.php new file mode 100644 index 0000000..373848c --- /dev/null +++ b/test/HTTP_POST_multipartTest.php @@ -0,0 +1,34 @@ +<?php + +require_once('PHPUnit/Framework.php'); +require_once('src/HTTP_POST_multipart.php'); + +class HTTP_POST_multipartTest extends PHPUnit_Framework_TestCase { + + public static function setUpBeforeClass() { + # Set all methods to be public so we can test them + $class = new ReflectionClass('HTTP_POST_multipart'); + foreach ($class->getMethods() as $method) { + $method->setAccessible(true); + } + } + + /** + * @dataProvider providerBuildDataPart + */ + public function testBuildDataPart($name, $data, $expected, $ex) { + if ($ex) $this->setExpectedException($ex); + $poster = new HTTP_POST_multipart(); + $this->assertEquals($expected, $poster->buildDataPart($name, $data)); + } + + public function providerBuildDataPart() { + return array( + array(null, null, 'Exception'), + array('foo', 1, "Content-Disposition: form-data; name=\"foo\"\r\n\r\n1\r\n") + ); + } + +} + +?> |