summaryrefslogtreecommitdiffstats
path: root/application/test/tests/api_v2/common.php
diff options
context:
space:
mode:
authorFlorian Pritz <bluewind@xinu.at>2016-10-08 14:50:07 +0200
committerFlorian Pritz <bluewind@xinu.at>2016-11-05 19:44:15 +0100
commit83f45f1fdf9cf89a0f3dac99221cc6e770e94dc0 (patch)
tree7502c8a8e68a490c964a264705ea685f00c3cd01 /application/test/tests/api_v2/common.php
parent485dad44e7927cf63d8ff0851fc77a08eb5b193b (diff)
Parallelize some API tests
Signed-off-by: Florian Pritz <bluewind@xinu.at>
Diffstat (limited to 'application/test/tests/api_v2/common.php')
-rw-r--r--application/test/tests/api_v2/common.php60
1 files changed, 60 insertions, 0 deletions
diff --git a/application/test/tests/api_v2/common.php b/application/test/tests/api_v2/common.php
new file mode 100644
index 000000000..dbef3cc9c
--- /dev/null
+++ b/application/test/tests/api_v2/common.php
@@ -0,0 +1,60 @@
+<?php
+/*
+ * Copyright 2015 Florian "Bluewind" Pritz <bluewind@server-speed.net>
+ *
+ * Licensed under AGPLv3
+ * (see COPYING for full license text)
+ *
+ */
+
+namespace test\tests\api_v2;
+
+class common extends \test\Test {
+
+ protected $userCounter = null;
+
+ public function __construct()
+ {
+ parent::__construct();
+
+ $CI =& get_instance();
+ $CI->load->model("muser");
+ $CI->load->model("mfile");
+ }
+
+ protected function uploadFile($apikey, $file)
+ {
+ $ret = $this->CallAPI("POST", "$this->server_url/api/v2.0.0/file/upload", array(
+ "apikey" => $apikey,
+ "file[1]" => curl_file_create($file),
+ ));
+ $this->expectSuccess("upload file", $ret);
+ return $ret;
+ }
+
+ protected function createUser($counter)
+ {
+ $CI =& get_instance();
+ $CI->muser->add_user("apiv2testuser$counter", "testpass$counter",
+ "testuser$counter@testsuite.local", NULL);
+ return $CI->db->insert_id();
+ }
+
+ protected function createApikey($userid, $access_level = "apikey")
+ {
+ return \service\user::create_apikey($userid, "", $access_level);
+ }
+
+ protected function createUserAndApikey($access_level = "apikey")
+ {
+ assert($this->userCounter !== null);
+ $this->userCounter++;
+ $userid = $this->createUser($this->userCounter);
+ return $this->createApikey($userid, $access_level);
+ }
+
+ protected function callEndpoint($verb, $endpoint, $data)
+ {
+ return $this->CallAPI($verb, "$this->server_url/api/v2.0.0/$endpoint", $data);
+ }
+}