summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--application/tests/Test.php22
-rw-r--r--application/tests/test_api_v1.php19
-rw-r--r--data/tests/message1.binbin0 -> 64 bytes
-rw-r--r--data/tests/message2.bin1
4 files changed, 34 insertions, 8 deletions
diff --git a/application/tests/Test.php b/application/tests/Test.php
index b9f401bdf..c11cd0cc4 100644
--- a/application/tests/Test.php
+++ b/application/tests/Test.php
@@ -43,6 +43,19 @@ abstract class Test {
// Source: http://stackoverflow.com/a/9802854/953022
protected function CallAPI($method, $url, $data = false)
{
+ $result = $this->SendHTTPRequest($method, $url, $data);
+
+ $json = json_decode($result, true);
+ if ($json === NULL) {
+ $this->t->fail("json decode");
+ $this->diagReply($result);
+ }
+
+ return $json;
+ }
+
+ protected function SendHTTPRequest($method, $url, $data = false)
+ {
$curl = curl_init();
switch ($method) {
@@ -70,14 +83,7 @@ abstract class Test {
$result = curl_exec($curl);
curl_close($curl);
-
- $json = json_decode($result, true);
- if ($json === NULL) {
- $this->t->fail("json decode");
- $this->diagReply($result);
- }
-
- return $json;
+ return $result;
}
protected function excpectStatus($testname, $reply, $status)
diff --git a/application/tests/test_api_v1.php b/application/tests/test_api_v1.php
index b39d5d44c..378f741de 100644
--- a/application/tests/test_api_v1.php
+++ b/application/tests/test_api_v1.php
@@ -245,6 +245,25 @@ class test_api_v1 extends Test {
$this->t->ok(!empty($ret["data"]["urls"]), "got URLs");
}
+ public function test_upload_uploadFileSameMD5()
+ {
+ $apikey = $this->createUserAndApikey();
+ $ret = $this->CallEndpoint("POST", "file/upload", array(
+ "apikey" => $apikey,
+ "file[1]" => curl_file_create("data/tests/message1.bin"),
+ "file[2]" => curl_file_create("data/tests/message2.bin"),
+ ));
+ $this->expectSuccess("upload file", $ret);
+
+ $this->t->ok(!empty($ret["data"]["ids"]), "got IDs");
+ $this->t->ok(!empty($ret["data"]["urls"]), "got URLs");
+
+ foreach ($ret["data"]["urls"] as $url) {
+ $data[] = $this->SendHTTPRequest("GET", $url, '');
+ }
+ $this->t->ok($data[0] !== $data[1], 'Returned file contents should differ');
+ }
+
public function test_upload_uploadNothing()
{
$apikey = $this->createUserAndApikey();
diff --git a/data/tests/message1.bin b/data/tests/message1.bin
new file mode 100644
index 000000000..2df129a78
--- /dev/null
+++ b/data/tests/message1.bin
Binary files differ
diff --git a/data/tests/message2.bin b/data/tests/message2.bin
new file mode 100644
index 000000000..dfaf4d1e9
--- /dev/null
+++ b/data/tests/message2.bin
@@ -0,0 +1 @@
+MÉhÿã\ •rÔw{r‡Óo§²ÜV·J=Àx>{•¯¿¢¨(KónŽKU³_Bu“ØIgm ÑÕ]ƒ`û_þ¢ \ No newline at end of file