summaryrefslogtreecommitdiffstats
path: root/application/tests/test_api_v1.php
diff options
context:
space:
mode:
authorFlorian Pritz <bluewind@xinu.at>2015-02-06 12:42:08 +0100
committerFlorian Pritz <bluewind@xinu.at>2015-02-06 12:42:08 +0100
commit5b225c751d60d79916da4a7db761f823e12148de (patch)
tree1cf1231f8fb7e69bc1921fb52cd819ac6dfa3f08 /application/tests/test_api_v1.php
parentf5cab9d96aec1464978b556f2ca02e79b2c4d8d8 (diff)
Add more tests
Signed-off-by: Florian Pritz <bluewind@xinu.at>
Diffstat (limited to 'application/tests/test_api_v1.php')
-rw-r--r--application/tests/test_api_v1.php44
1 files changed, 44 insertions, 0 deletions
diff --git a/application/tests/test_api_v1.php b/application/tests/test_api_v1.php
index 387e3fe6c..9f415abbd 100644
--- a/application/tests/test_api_v1.php
+++ b/application/tests/test_api_v1.php
@@ -115,4 +115,48 @@ class test_api_v1 extends Test {
$this->t->ok(empty($ret["data"]["multipaste_items"]), "multipaste_items key exists and empty");
$this->t->is($ret["data"]["total_size"], 0, "total_size = 0 since no uploads");
}
+
+ public function test_delete_canDeleteUploaded()
+ {
+ $ret = $this->CallAPI("POST", "$this->server/api/1.0.0/file/upload", array(
+ "apikey" => $this->apikeys[2],
+ "file[1]" => curl_file_create("data/tests/small-file"),
+ ));
+ $this->expectSuccess("upload file", $ret);
+
+ $id = $ret["data"]["ids"][0];
+
+ $ret = $this->CallAPI("POST", "$this->server/api/1.0.0/file/delete", array(
+ "apikey" => $this->apikeys[2],
+ "ids[1]" => $id,
+ ));
+ $this->expectSuccess("delete uploaded file", $ret);
+
+ $this->t->ok(empty($ret["data"]["errors"]), "no errors");
+ $this->t->is_deeply(array($id => array("id" => $id)), $ret["data"]["deleted"], "deleted wanted ID");
+ $this->t->is($ret["data"]["total_count"], 1, "total_count correct");
+ $this->t->is($ret["data"]["deleted_count"], 1, "deleted_count correct");
+ }
+
+ public function test_delete_errorIfNotOwner()
+ {
+ $ret = $this->CallAPI("POST", "$this->server/api/1.0.0/file/upload", array(
+ "apikey" => $this->apikeys[2],
+ "file[1]" => curl_file_create("data/tests/small-file"),
+ ));
+ $this->expectSuccess("upload file", $ret);
+
+ $id = $ret["data"]["ids"][0];
+
+ $ret = $this->CallAPI("POST", "$this->server/api/1.0.0/file/delete", array(
+ "apikey" => $this->apikeys[1],
+ "ids[1]" => $id,
+ ));
+ $this->expectSuccess("delete file of someone else", $ret);
+
+ $this->t->ok(empty($ret["data"]["deleted"]), "not deleted");
+ $this->t->is_deeply(array($id => array("id" => $id, "reason" => "wrong owner")), $ret["data"]["errors"], "error wanted ID");
+ $this->t->is($ret["data"]["total_count"], 1, "total_count correct");
+ $this->t->is($ret["data"]["deleted_count"], 0, "deleted_count correct");
+ }
}