|
@@ -0,0 +1,117 @@
|
|
1
|
+<?php
|
|
2
|
+$host = "https://api.vdm.rthoni.com/";
|
|
3
|
+$key = "demo42";
|
|
4
|
+
|
|
5
|
+header("Content-Type: text/plain");
|
|
6
|
+
|
|
7
|
+$token = "";
|
|
8
|
+function error($http)
|
|
9
|
+{
|
|
10
|
+ echo "[ KO ] ";
|
|
11
|
+ var_dump($http);
|
|
12
|
+ die();
|
|
13
|
+}
|
|
14
|
+
|
|
15
|
+function check_error($http)
|
|
16
|
+{
|
|
17
|
+ if ($http->responseCode != 200)
|
|
18
|
+ error($http);
|
|
19
|
+ return json_decode($http->body);
|
|
20
|
+}
|
|
21
|
+
|
|
22
|
+function api_post($url, $param)
|
|
23
|
+{
|
|
24
|
+ global $host;
|
|
25
|
+ global $key;
|
|
26
|
+ global $token;
|
|
27
|
+ $http = http_post_fields($host . $url, $param, array(), array("headers" =>
|
|
28
|
+ array("Api-Key" => $key, "Authorization" => $token)));
|
|
29
|
+ return check_error(http_parse_message($http));
|
|
30
|
+}
|
|
31
|
+
|
|
32
|
+function api_get($url, $param)
|
|
33
|
+{
|
|
34
|
+ global $host;
|
|
35
|
+ global $key;
|
|
36
|
+ global $token;
|
|
37
|
+ $f = true;
|
|
38
|
+ foreach ($param as $k => $v)
|
|
39
|
+ {
|
|
40
|
+ if ($f)
|
|
41
|
+ {
|
|
42
|
+ $f = false;
|
|
43
|
+ $url .= "?";
|
|
44
|
+ }
|
|
45
|
+ else
|
|
46
|
+ $url .= "&";
|
|
47
|
+ $url .= urlencode($k) . "=" . urlencode($v);
|
|
48
|
+ }
|
|
49
|
+ $http = http_get($host . $url, array("headers" =>
|
|
50
|
+ array("Api-Key" => $key, "Authorization" => $token)));
|
|
51
|
+ return check_error(http_parse_message($http));
|
|
52
|
+}
|
|
53
|
+
|
|
54
|
+function add_status($status, $long, $lat, $r)
|
|
55
|
+{
|
|
56
|
+ $params = array("status" => $status);
|
|
57
|
+ if ($long !== null)
|
|
58
|
+ $params["longitude"] = $long;
|
|
59
|
+ if ($lat !== null)
|
|
60
|
+ $params["latitude"] = $lat;
|
|
61
|
+ $s = api_post("status", $params);
|
|
62
|
+ if ($s->user_id != $r->id)
|
|
63
|
+ die("[ KO ] Users ids don't match");
|
|
64
|
+ if (($long !== null && $s->longitude != $long)
|
|
65
|
+ || ($long === null && $s->longitude != null))
|
|
66
|
+ die("[ KO ] Longitudes don't match");
|
|
67
|
+ if (($lat !== null && $s->latitude != $lat)
|
|
68
|
+ || ($lat === null && $s->latitude != null))
|
|
69
|
+ die("[ KO ] Latitudes don't match");
|
|
70
|
+
|
|
71
|
+ echo "[ OK ] Status added\n";
|
|
72
|
+}
|
|
73
|
+
|
|
74
|
+function mk_status($status, $long, $lat)
|
|
75
|
+{
|
|
76
|
+ return array("status" => $status,
|
|
77
|
+ "long" => $long,
|
|
78
|
+ "lat" => $lat);
|
|
79
|
+}
|
|
80
|
+
|
|
81
|
+$username = "check_" . rand();
|
|
82
|
+$password = md5(rand());
|
|
83
|
+$user_pass = array("username" => $username, "password" => $password);
|
|
84
|
+
|
|
85
|
+
|
|
86
|
+$r = api_post("user", $user_pass);
|
|
87
|
+echo "[ OK ] User " . $r->username . " (" . $r->id . ") created\n";
|
|
88
|
+
|
|
89
|
+$l = api_post("user/login", $user_pass);
|
|
90
|
+if ($l->username != $r->username)
|
|
91
|
+ die("[ KO ] Usernames don't match");
|
|
92
|
+if ($l->id != $r->id)
|
|
93
|
+ die("[ KO ] Users ids don't match");
|
|
94
|
+$token = $r->token;
|
|
95
|
+echo "[ OK ] User " . $r->username . " (" . $r->id . ") logged in\n";
|
|
96
|
+
|
|
97
|
+$status = array(mk_status("check status null null", null, null),
|
|
98
|
+ mk_status("check status 42 null", 42, null),
|
|
99
|
+ mk_status("check status null 42", null, 42),
|
|
100
|
+ mk_status("check status 42.42 42", 42.42, 42));
|
|
101
|
+
|
|
102
|
+foreach ($status as $st)
|
|
103
|
+ add_status($st['status'], $st['long'], $st['lat'], $r);
|
|
104
|
+
|
|
105
|
+$f = api_get("status/feed", array());
|
|
106
|
+if (count($f) != count($status))
|
|
107
|
+ die("[ KO ] Did not found " . count($status).
|
|
108
|
+ " status (Was the database cleared?)\n");
|
|
109
|
+
|
|
110
|
+echo "[ OK ] All the status were added\n";
|
|
111
|
+
|
|
112
|
+api_post("status/" . $f[0]->id . "/confirm", array("confirmation" => 1));
|
|
113
|
+echo "[ OK ] Status confirmed once\n";
|
|
114
|
+api_post("status/" . $f[0]->id . "/confirm", array("confirmation" => 0));
|
|
115
|
+echo "[ OK ] Status confirmed tiwce\n";
|
|
116
|
+
|
|
117
|
+?>
|