Browse Source

Prepare for PSR compliant namespacing

Maurits van der Schee 7 years ago
parent
commit
cca56e7859
2 changed files with 191 additions and 188 deletions
  1. 114
    0
      tests/Api.php
  2. 77
    188
      tests/Tests.php

+ 114
- 0
tests/Api.php View File

1
+<?php
2
+
3
+require_once(__DIR__ . '/../api.php');
4
+
5
+class Api
6
+{
7
+    /**
8
+     * Database configuration array
9
+     *
10
+     * @var array
11
+     */
12
+    protected $config;
13
+
14
+    /**
15
+     * @var PHP_CRUD_API_Test
16
+     */
17
+    protected $test;
18
+
19
+    /**
20
+     * @var PHP_CRUD_API
21
+     */
22
+    protected $api;
23
+
24
+    public function __construct($test)
25
+    {
26
+        $this->test = $test;
27
+        $this->config = $test::$config;
28
+        $this->config['dbengine'] = $test->getEngineName();
29
+    }
30
+
31
+    private function action($method,$url,$data='')
32
+    {
33
+        $url = parse_url($url);
34
+        $query = isset($url['query'])?$url['query']:'';
35
+        parse_str($query,$get);
36
+
37
+        $this->api = new PHP_CRUD_API(array(
38
+            'dbengine'=>$this->config['dbengine'],
39
+            'hostname'=>$this->config['hostname'],
40
+            'username'=>$this->config['username'],
41
+            'password'=>$this->config['password'],
42
+            'database'=>$this->config['database'],
43
+            // callbacks
44
+            'table_authorizer'=>function($action,$database,$table) { return true; },
45
+            'column_authorizer'=>function($action,$database,$table,$column) { return !($column=='password'&&$action=='list'); },
46
+            'record_filter'=>function($action,$database,$table) { return ($table=='posts')?array('id,neq,13'):false; },
47
+            'tenancy_function'=>function($action,$database,$table,$column) { return ($table=='users'&&$column=='id')?1:null; },
48
+            'input_sanitizer'=>function($action,$database,$table,$column,$type,$value) { return is_string($value)?strip_tags($value):$value; },
49
+            'input_validator'=>function($action,$database,$table,$column,$type,$value,$context) { return ($column=='category_id' && !is_numeric($value))?'must be numeric':true; },
50
+            'before'=>function(&$action,&$database,&$table,&$id,&$input) { if ($table=='products') if ($action=='create') $input->created_at = '2013-12-11 10:09:08'; else if ($action=='delete') { $action='update'; $input = (object)array('deleted_at' => '2013-12-11 11:10:09'); } },
51
+            'after'=>function($action,$database,$table,$id,$input,$output) { file_put_contents('log.txt',var_export(array($action,$database,$table,$id,$input,$output),true),FILE_APPEND); },
52
+            // for tests
53
+            'method'=>$method,
54
+            'request'=>$url['path'],
55
+            'post'=>$data,
56
+            'get'=>$get,
57
+        ));
58
+        return $this;
59
+    }
60
+
61
+    public function get($url)
62
+    {
63
+        return $this->action('GET',$url);
64
+    }
65
+
66
+    public function post($url,$data)
67
+    {
68
+        return $this->action('POST',$url,$data);
69
+    }
70
+
71
+    public function put($url,$data)
72
+    {
73
+        return $this->action('PUT',$url,$data);
74
+    }
75
+
76
+    public function delete($url)
77
+    {
78
+        return $this->action('DELETE',$url);
79
+    }
80
+
81
+    public function options($url)
82
+    {
83
+        return $this->action('OPTIONS',$url);
84
+    }
85
+
86
+    public function patch($url,$data)
87
+    {
88
+        return $this->action('PATCH',$url,$data);
89
+    }
90
+
91
+    public function expectAny()
92
+    {
93
+        ob_start();
94
+        $this->api->executeCommand();
95
+        ob_end_clean();
96
+        return $this;
97
+    }
98
+
99
+    public function expect($output,$error=false)
100
+    {
101
+        $exception = false;
102
+        ob_start();
103
+        try {
104
+            $this->api->executeCommand();
105
+        } catch (\Exception $e) {
106
+            $exception = $e->getMessage();
107
+        }
108
+        $data = ob_get_contents();
109
+        ob_end_clean();
110
+        if ($exception) $this->test->assertEquals($error, $exception);
111
+        else $this->test->assertEquals($output, $data);
112
+        return $this;
113
+    }
114
+}

+ 77
- 188
tests/Tests.php View File

1
 <?php
1
 <?php
2
 
2
 
3
 require_once(__DIR__ . '/TestBase.php');
3
 require_once(__DIR__ . '/TestBase.php');
4
-require_once(__DIR__ . '/../api.php');
5
-
6
-class API
7
-{
8
-    /**
9
-     * Database configuration array
10
-     *
11
-     * @var array
12
-     */
13
-    protected $config;
14
-
15
-    /**
16
-     * @var PHP_CRUD_API_Test
17
-     */
18
-    protected $test;
19
-
20
-    /**
21
-     * @var PHP_CRUD_API
22
-     */
23
-    protected $api;
24
-
25
-    public function __construct($test)
26
-    {
27
-        $this->test = $test;
28
-        $this->config = $test::$config;
29
-        $this->config['dbengine'] = $test->getEngineName();
30
-    }
31
-
32
-    private function action($method,$url,$data='')
33
-    {
34
-        $url = parse_url($url);
35
-        $query = isset($url['query'])?$url['query']:'';
36
-        parse_str($query,$get);
37
-
38
-        $this->api = new PHP_CRUD_API(array(
39
-            'dbengine'=>$this->config['dbengine'],
40
-            'hostname'=>$this->config['hostname'],
41
-            'username'=>$this->config['username'],
42
-            'password'=>$this->config['password'],
43
-            'database'=>$this->config['database'],
44
-            // callbacks
45
-            'table_authorizer'=>function($action,$database,$table) { return true; },
46
-            'column_authorizer'=>function($action,$database,$table,$column) { return !($column=='password'&&$action=='list'); },
47
-            'record_filter'=>function($action,$database,$table) { return ($table=='posts')?array('id,neq,13'):false; },
48
-            'tenancy_function'=>function($action,$database,$table,$column) { return ($table=='users'&&$column=='id')?1:null; },
49
-            'input_sanitizer'=>function($action,$database,$table,$column,$type,$value) { return is_string($value)?strip_tags($value):$value; },
50
-            'input_validator'=>function($action,$database,$table,$column,$type,$value,$context) { return ($column=='category_id' && !is_numeric($value))?'must be numeric':true; },
51
-            'before'=>function(&$action,&$database,&$table,&$id,&$input) { if ($table=='products') if ($action=='create') $input->created_at = '2013-12-11 10:09:08'; else if ($action=='delete') { $action='update'; $input = (object)array('deleted_at' => '2013-12-11 11:10:09'); } },
52
-            'after'=>function($action,$database,$table,$id,$input,$output) { file_put_contents('log.txt',var_export(array($action,$database,$table,$id,$input,$output),true),FILE_APPEND); },
53
-            // for tests
54
-            'method'=>$method,
55
-            'request'=>$url['path'],
56
-            'post'=>$data,
57
-            'get'=>$get,
58
-        ));
59
-        return $this;
60
-    }
61
-
62
-    public function get($url)
63
-    {
64
-        return $this->action('GET',$url);
65
-    }
66
-
67
-    public function post($url,$data)
68
-    {
69
-        return $this->action('POST',$url,$data);
70
-    }
71
-
72
-    public function put($url,$data)
73
-    {
74
-        return $this->action('PUT',$url,$data);
75
-    }
76
-
77
-    public function delete($url)
78
-    {
79
-        return $this->action('DELETE',$url);
80
-    }
81
-
82
-    public function options($url)
83
-    {
84
-        return $this->action('OPTIONS',$url);
85
-    }
86
-
87
-    public function patch($url,$data)
88
-    {
89
-        return $this->action('PATCH',$url,$data);
90
-    }
91
-
92
-    public function expectAny()
93
-    {
94
-        ob_start();
95
-        $this->api->executeCommand();
96
-        ob_end_clean();
97
-        return $this;
98
-    }
99
-
100
-    public function expect($output,$error=false)
101
-    {
102
-        $exception = false;
103
-        ob_start();
104
-        try {
105
-            $this->api->executeCommand();
106
-        } catch (\Exception $e) {
107
-            $exception = $e->getMessage();
108
-        }
109
-        $data = ob_get_contents();
110
-        ob_end_clean();
111
-        if ($exception) $this->test->assertEquals($error, $exception);
112
-        else $this->test->assertEquals($output, $data);
113
-        return $this;
114
-    }
115
-}
4
+require_once(__DIR__ . '/Api.php');
116
 
5
 
117
 abstract class Tests extends TestBase
6
 abstract class Tests extends TestBase
118
 {
7
 {
119
     public function testListPosts()
8
     public function testListPosts()
120
     {
9
     {
121
-        $test = new API($this);
10
+        $test = new Api($this);
122
         $test->get('/posts');
11
         $test->get('/posts');
123
         $test->expect('{"posts":{"columns":["id","user_id","category_id","content"],"records":[[1,1,1,"blog started"],[2,1,2,"It works!"]]}}');
12
         $test->expect('{"posts":{"columns":["id","user_id","category_id","content"],"records":[[1,1,1,"blog started"],[2,1,2,"It works!"]]}}');
124
     }
13
     }
125
 
14
 
126
     public function testListPostColumns()
15
     public function testListPostColumns()
127
     {
16
     {
128
-        $test = new API($this);
17
+        $test = new Api($this);
129
         $test->get('/posts?columns=id,content');
18
         $test->get('/posts?columns=id,content');
130
         $test->expect('{"posts":{"columns":["id","content"],"records":[[1,"blog started"],[2,"It works!"]]}}');
19
         $test->expect('{"posts":{"columns":["id","content"],"records":[[1,"blog started"],[2,"It works!"]]}}');
131
     }
20
     }
132
 
21
 
133
     public function testListPostsWithTransform()
22
     public function testListPostsWithTransform()
134
     {
23
     {
135
-        $test = new API($this);
24
+        $test = new Api($this);
136
         $test->get('/posts?transform=1');
25
         $test->get('/posts?transform=1');
137
         $test->expect('{"posts":[{"id":1,"user_id":1,"category_id":1,"content":"blog started"},{"id":2,"user_id":1,"category_id":2,"content":"It works!"}]}');
26
         $test->expect('{"posts":[{"id":1,"user_id":1,"category_id":1,"content":"blog started"},{"id":2,"user_id":1,"category_id":2,"content":"It works!"}]}');
138
     }
27
     }
139
 
28
 
140
     public function testReadPost()
29
     public function testReadPost()
141
     {
30
     {
142
-        $test = new API($this);
31
+        $test = new Api($this);
143
         $test->get('/posts/2');
32
         $test->get('/posts/2');
144
         $test->expect('{"id":2,"user_id":1,"category_id":2,"content":"It works!"}');
33
         $test->expect('{"id":2,"user_id":1,"category_id":2,"content":"It works!"}');
145
     }
34
     }
146
 
35
 
147
     public function testReadPosts()
36
     public function testReadPosts()
148
     {
37
     {
149
-        $test = new API($this);
38
+        $test = new Api($this);
150
         $test->get('/posts/1,2');
39
         $test->get('/posts/1,2');
151
         $test->expect('[{"id":1,"user_id":1,"category_id":1,"content":"blog started"},{"id":2,"user_id":1,"category_id":2,"content":"It works!"}]');
40
         $test->expect('[{"id":1,"user_id":1,"category_id":1,"content":"blog started"},{"id":2,"user_id":1,"category_id":2,"content":"It works!"}]');
152
     }
41
     }
153
 
42
 
154
     public function testReadPostColumns()
43
     public function testReadPostColumns()
155
     {
44
     {
156
-        $test = new API($this);
45
+        $test = new Api($this);
157
         $test->get('/posts/2?columns=id,content');
46
         $test->get('/posts/2?columns=id,content');
158
         $test->expect('{"id":2,"content":"It works!"}');
47
         $test->expect('{"id":2,"content":"It works!"}');
159
     }
48
     }
160
 
49
 
161
     public function testAddPost()
50
     public function testAddPost()
162
     {
51
     {
163
-        $test = new API($this);
52
+        $test = new Api($this);
164
         $test->post('/posts','{"user_id":1,"category_id":1,"content":"test"}');
53
         $test->post('/posts','{"user_id":1,"category_id":1,"content":"test"}');
165
         $test->expect('3');
54
         $test->expect('3');
166
     }
55
     }
167
 
56
 
168
     public function testEditPost()
57
     public function testEditPost()
169
     {
58
     {
170
-        $test = new API($this);
59
+        $test = new Api($this);
171
         $test->put('/posts/3','{"user_id":1,"category_id":1,"content":"test (edited)"}');
60
         $test->put('/posts/3','{"user_id":1,"category_id":1,"content":"test (edited)"}');
172
         $test->expect('1');
61
         $test->expect('1');
173
         $test->get('/posts/3');
62
         $test->get('/posts/3');
176
 
65
 
177
     public function testEditPostColumnsMissingField()
66
     public function testEditPostColumnsMissingField()
178
     {
67
     {
179
-        $test = new API($this);
68
+        $test = new Api($this);
180
         $test->put('/posts/3?columns=id,content','{"content":"test (edited 2)"}');
69
         $test->put('/posts/3?columns=id,content','{"content":"test (edited 2)"}');
181
         $test->expect('1');
70
         $test->expect('1');
182
         $test->get('/posts/3');
71
         $test->get('/posts/3');
185
 
74
 
186
     public function testEditPostColumnsExtraField()
75
     public function testEditPostColumnsExtraField()
187
     {
76
     {
188
-        $test = new API($this);
77
+        $test = new Api($this);
189
         $test->put('/posts/3?columns=id,content','{"user_id":2,"content":"test (edited 3)"}');
78
         $test->put('/posts/3?columns=id,content','{"user_id":2,"content":"test (edited 3)"}');
190
         $test->expect('1');
79
         $test->expect('1');
191
         $test->get('/posts/3');
80
         $test->get('/posts/3');
195
     public function testEditPostWithUtf8Content()
84
     public function testEditPostWithUtf8Content()
196
     {
85
     {
197
         $utf8 = json_encode('Hello world, Καλημέρα κόσμε, コンニチハ');
86
         $utf8 = json_encode('Hello world, Καλημέρα κόσμε, コンニチハ');
198
-        $test = new API($this);
87
+        $test = new Api($this);
199
         $test->put('/posts/2','{"content":'.$utf8.'}');
88
         $test->put('/posts/2','{"content":'.$utf8.'}');
200
         $test->expect('1');
89
         $test->expect('1');
201
         $test->get('/posts/2');
90
         $test->get('/posts/2');
207
         $utf8 = '€ Hello world, Καλημέρα κόσμε, コンニチハ';
96
         $utf8 = '€ Hello world, Καλημέρα κόσμε, コンニチハ';
208
         $url_encoded = urlencode($utf8);
97
         $url_encoded = urlencode($utf8);
209
         $json_encoded = json_encode($utf8);
98
         $json_encoded = json_encode($utf8);
210
-        $test = new API($this);
99
+        $test = new Api($this);
211
         $test->put('/posts/2','content='.$url_encoded);
100
         $test->put('/posts/2','content='.$url_encoded);
212
         $test->expect('1');
101
         $test->expect('1');
213
         $test->get('/posts/2');
102
         $test->get('/posts/2');
216
 
105
 
217
     public function testDeletePost()
106
     public function testDeletePost()
218
     {
107
     {
219
-        $test = new API($this);
108
+        $test = new Api($this);
220
         $test->delete('/posts/3');
109
         $test->delete('/posts/3');
221
         $test->expect('1');
110
         $test->expect('1');
222
         $test->get('/posts/3');
111
         $test->get('/posts/3');
225
 
114
 
226
     public function testAddPostWithPost()
115
     public function testAddPostWithPost()
227
     {
116
     {
228
-        $test = new API($this);
117
+        $test = new Api($this);
229
         $test->post('/posts','user_id=1&category_id=1&content=test');
118
         $test->post('/posts','user_id=1&category_id=1&content=test');
230
         $test->expect('4');
119
         $test->expect('4');
231
     }
120
     }
232
 
121
 
233
     public function testEditPostWithPost()
122
     public function testEditPostWithPost()
234
     {
123
     {
235
-        $test = new API($this);
124
+        $test = new Api($this);
236
         $test->put('/posts/4','user_id=1&category_id=1&content=test+(edited)');
125
         $test->put('/posts/4','user_id=1&category_id=1&content=test+(edited)');
237
         $test->expect('1');
126
         $test->expect('1');
238
         $test->get('/posts/4');
127
         $test->get('/posts/4');
241
 
130
 
242
     public function testDeletePostWithPost()
131
     public function testDeletePostWithPost()
243
     {
132
     {
244
-        $test = new API($this);
133
+        $test = new Api($this);
245
         $test->delete('/posts/4');
134
         $test->delete('/posts/4');
246
         $test->expect('1');
135
         $test->expect('1');
247
         $test->get('/posts/4');
136
         $test->get('/posts/4');
250
 
139
 
251
     public function testListWithPaginate()
140
     public function testListWithPaginate()
252
     {
141
     {
253
-        $test = new API($this);
142
+        $test = new Api($this);
254
         for ($i=1;$i<=10;$i++) {
143
         for ($i=1;$i<=10;$i++) {
255
             $test->post('/posts','{"user_id":1,"category_id":1,"content":"#'.$i.'"}');
144
             $test->post('/posts','{"user_id":1,"category_id":1,"content":"#'.$i.'"}');
256
             $test->expect(4+$i);
145
             $test->expect(4+$i);
261
 
150
 
262
     public function testListWithPaginateInMultipleOrder()
151
     public function testListWithPaginateInMultipleOrder()
263
     {
152
     {
264
-        $test = new API($this);
153
+        $test = new Api($this);
265
         $test->get('/posts?page=1,2&order[]=category_id,asc&order[]=id,desc');
154
         $test->get('/posts?page=1,2&order[]=category_id,asc&order[]=id,desc');
266
         $test->expect('{"posts":{"columns":["id","user_id","category_id","content"],"records":[[14,1,1,"#10"],[12,1,1,"#8"]],"results":11}}');
155
         $test->expect('{"posts":{"columns":["id","user_id","category_id","content"],"records":[[14,1,1,"#10"],[12,1,1,"#8"]],"results":11}}');
267
     }
156
     }
268
 
157
 
269
     public function testListWithPaginateInDescendingOrder()
158
     public function testListWithPaginateInDescendingOrder()
270
     {
159
     {
271
-        $test = new API($this);
160
+        $test = new Api($this);
272
         $test->get('/posts?page=2,2&order=id,desc');
161
         $test->get('/posts?page=2,2&order=id,desc');
273
         $test->expect('{"posts":{"columns":["id","user_id","category_id","content"],"records":[[11,1,1,"#7"],[10,1,1,"#6"]],"results":11}}');
162
         $test->expect('{"posts":{"columns":["id","user_id","category_id","content"],"records":[[11,1,1,"#7"],[10,1,1,"#6"]],"results":11}}');
274
     }
163
     }
275
 
164
 
276
     public function testListWithPaginateLastPage()
165
     public function testListWithPaginateLastPage()
277
     {
166
     {
278
-        $test = new API($this);
167
+        $test = new Api($this);
279
         $test->get('/posts?page=3,5&order=id');
168
         $test->get('/posts?page=3,5&order=id');
280
         $test->expect('{"posts":{"columns":["id","user_id","category_id","content"],"records":[[14,1,1,"#10"]],"results":11}}');
169
         $test->expect('{"posts":{"columns":["id","user_id","category_id","content"],"records":[[14,1,1,"#10"]],"results":11}}');
281
     }
170
     }
282
 
171
 
283
     public function testListExampleFromReadmeFullRecord()
172
     public function testListExampleFromReadmeFullRecord()
284
     {
173
     {
285
-        $test = new API($this);
174
+        $test = new Api($this);
286
         $test->get('/posts?filter=id,eq,1');
175
         $test->get('/posts?filter=id,eq,1');
287
         $test->expect('{"posts":{"columns":["id","user_id","category_id","content"],"records":[[1,1,1,"blog started"]]}}');
176
         $test->expect('{"posts":{"columns":["id","user_id","category_id","content"],"records":[[1,1,1,"blog started"]]}}');
288
     }
177
     }
289
 
178
 
290
     public function testListExampleFromReadmeWithExclude()
179
     public function testListExampleFromReadmeWithExclude()
291
     {
180
     {
292
-        $test = new API($this);
181
+        $test = new Api($this);
293
         $test->get('/posts?exclude=id&filter=id,eq,1');
182
         $test->get('/posts?exclude=id&filter=id,eq,1');
294
         $test->expect('{"posts":{"columns":["user_id","category_id","content"],"records":[[1,1,"blog started"]]}}');
183
         $test->expect('{"posts":{"columns":["user_id","category_id","content"],"records":[[1,1,"blog started"]]}}');
295
     }
184
     }
296
 
185
 
297
     public function testListExampleFromReadme()
186
     public function testListExampleFromReadme()
298
     {
187
     {
299
-        $test = new API($this);
188
+        $test = new Api($this);
300
         $test->get('/posts?include=categories,tags,comments&filter=id,eq,1');
189
         $test->get('/posts?include=categories,tags,comments&filter=id,eq,1');
301
         $test->expect('{"posts":{"columns":["id","user_id","category_id","content"],"records":[[1,1,1,"blog started"]]},"post_tags":{"relations":{"post_id":"posts.id"},"columns":["id","post_id","tag_id"],"records":[[1,1,1],[2,1,2]]},"categories":{"relations":{"id":"posts.category_id"},"columns":["id","name","icon"],"records":[[1,"announcement",null]]},"tags":{"relations":{"id":"post_tags.tag_id"},"columns":["id","name"],"records":[[1,"funny"],[2,"important"]]},"comments":{"relations":{"post_id":"posts.id"},"columns":["id","post_id","message"],"records":[[1,1,"great"],[2,1,"fantastic"]]}}');
190
         $test->expect('{"posts":{"columns":["id","user_id","category_id","content"],"records":[[1,1,1,"blog started"]]},"post_tags":{"relations":{"post_id":"posts.id"},"columns":["id","post_id","tag_id"],"records":[[1,1,1],[2,1,2]]},"categories":{"relations":{"id":"posts.category_id"},"columns":["id","name","icon"],"records":[[1,"announcement",null]]},"tags":{"relations":{"id":"post_tags.tag_id"},"columns":["id","name"],"records":[[1,"funny"],[2,"important"]]},"comments":{"relations":{"post_id":"posts.id"},"columns":["id","post_id","message"],"records":[[1,1,"great"],[2,1,"fantastic"]]}}');
302
     }
191
     }
303
 
192
 
304
     public function testListExampleFromReadmeWithTransform()
193
     public function testListExampleFromReadmeWithTransform()
305
     {
194
     {
306
-        $test = new API($this);
195
+        $test = new Api($this);
307
         $test->get('/posts?include=categories,tags,comments&filter=id,eq,1&transform=1');
196
         $test->get('/posts?include=categories,tags,comments&filter=id,eq,1&transform=1');
308
         $test->expect('{"posts":[{"id":1,"post_tags":[{"id":1,"post_id":1,"tag_id":1,"tags":[{"id":1,"name":"funny"}]},{"id":2,"post_id":1,"tag_id":2,"tags":[{"id":2,"name":"important"}]}],"comments":[{"id":1,"post_id":1,"message":"great"},{"id":2,"post_id":1,"message":"fantastic"}],"user_id":1,"category_id":1,"categories":[{"id":1,"name":"announcement","icon":null}],"content":"blog started"}]}');
197
         $test->expect('{"posts":[{"id":1,"post_tags":[{"id":1,"post_id":1,"tag_id":1,"tags":[{"id":1,"name":"funny"}]},{"id":2,"post_id":1,"tag_id":2,"tags":[{"id":2,"name":"important"}]}],"comments":[{"id":1,"post_id":1,"message":"great"},{"id":2,"post_id":1,"message":"fantastic"}],"user_id":1,"category_id":1,"categories":[{"id":1,"name":"announcement","icon":null}],"content":"blog started"}]}');
309
     }
198
     }
310
 
199
 
311
     public function testListExampleFromReadmeWithTransformWithExclude()
200
     public function testListExampleFromReadmeWithTransformWithExclude()
312
     {
201
     {
313
-        $test = new API($this);
202
+        $test = new Api($this);
314
         $test->get('/posts?include=categories,tags,comments&exclude=comments.message&filter=id,eq,1&transform=1');
203
         $test->get('/posts?include=categories,tags,comments&exclude=comments.message&filter=id,eq,1&transform=1');
315
         $test->expect('{"posts":[{"id":1,"post_tags":[{"id":1,"post_id":1,"tag_id":1,"tags":[{"id":1,"name":"funny"}]},{"id":2,"post_id":1,"tag_id":2,"tags":[{"id":2,"name":"important"}]}],"comments":[{"id":1,"post_id":1},{"id":2,"post_id":1}],"user_id":1,"category_id":1,"categories":[{"id":1,"name":"announcement","icon":null}],"content":"blog started"}]}');
204
         $test->expect('{"posts":[{"id":1,"post_tags":[{"id":1,"post_id":1,"tag_id":1,"tags":[{"id":1,"name":"funny"}]},{"id":2,"post_id":1,"tag_id":2,"tags":[{"id":2,"name":"important"}]}],"comments":[{"id":1,"post_id":1},{"id":2,"post_id":1}],"user_id":1,"category_id":1,"categories":[{"id":1,"name":"announcement","icon":null}],"content":"blog started"}]}');
316
     }
205
     }
319
     {
208
     {
320
         $binary = base64_encode("\0abc\0\n\r\b\0");
209
         $binary = base64_encode("\0abc\0\n\r\b\0");
321
         $base64url = rtrim(strtr($binary, '+/', '-_'), '=');
210
         $base64url = rtrim(strtr($binary, '+/', '-_'), '=');
322
-        $test = new API($this);
211
+        $test = new Api($this);
323
         $test->put('/categories/2','{"icon":"'.$base64url.'"}');
212
         $test->put('/categories/2','{"icon":"'.$base64url.'"}');
324
         $test->expect('1');
213
         $test->expect('1');
325
         $test->get('/categories/2');
214
         $test->get('/categories/2');
328
 
217
 
329
     public function testEditCategoryWithNull()
218
     public function testEditCategoryWithNull()
330
     {
219
     {
331
-        $test = new API($this);
220
+        $test = new Api($this);
332
         $test->put('/categories/2','{"icon":null}');
221
         $test->put('/categories/2','{"icon":null}');
333
         $test->expect('1');
222
         $test->expect('1');
334
         $test->get('/categories/2');
223
         $test->get('/categories/2');
339
     {
228
     {
340
         $binary = base64_encode("€ \0abc\0\n\r\b\0");
229
         $binary = base64_encode("€ \0abc\0\n\r\b\0");
341
         $base64url = rtrim(strtr($binary, '+/', '-_'), '=');
230
         $base64url = rtrim(strtr($binary, '+/', '-_'), '=');
342
-        $test = new API($this);
231
+        $test = new Api($this);
343
         $test->put('/categories/2','icon='.$base64url);
232
         $test->put('/categories/2','icon='.$base64url);
344
         $test->expect('1');
233
         $test->expect('1');
345
         $test->get('/categories/2');
234
         $test->get('/categories/2');
348
 
237
 
349
     public function testListCategoriesWithBinaryContent()
238
     public function testListCategoriesWithBinaryContent()
350
     {
239
     {
351
-        $test = new API($this);
240
+        $test = new Api($this);
352
         $test->get('/categories');
241
         $test->get('/categories');
353
         $test->expect('{"categories":{"columns":["id","name","icon"],"records":[[1,"announcement",null],[2,"article","4oKsIABhYmMACg1cYgA="]]}}');
242
         $test->expect('{"categories":{"columns":["id","name","icon"],"records":[[1,"announcement",null],[2,"article","4oKsIABhYmMACg1cYgA="]]}}');
354
     }
243
     }
355
 
244
 
356
     public function testEditCategoryWithNullWithPost()
245
     public function testEditCategoryWithNullWithPost()
357
     {
246
     {
358
-        $test = new API($this);
247
+        $test = new Api($this);
359
         $test->put('/categories/2','icon__is_null');
248
         $test->put('/categories/2','icon__is_null');
360
         $test->expect('1');
249
         $test->expect('1');
361
         $test->get('/categories/2');
250
         $test->get('/categories/2');
364
 
253
 
365
     public function testAddPostFailure()
254
     public function testAddPostFailure()
366
     {
255
     {
367
-        $test = new API($this);
256
+        $test = new Api($this);
368
         $test->post('/posts','{"user_id":"a","category_id":1,"content":"tests"}');
257
         $test->post('/posts','{"user_id":"a","category_id":1,"content":"tests"}');
369
         $test->expect('null');
258
         $test->expect('null');
370
     }
259
     }
371
 
260
 
372
     public function testOptionsRequest()
261
     public function testOptionsRequest()
373
     {
262
     {
374
-        $test = new API($this);
263
+        $test = new Api($this);
375
         $test->options('/posts/2');
264
         $test->options('/posts/2');
376
         $test->expect('["Access-Control-Allow-Headers: Content-Type, X-XSRF-TOKEN","Access-Control-Allow-Methods: OPTIONS, GET, PUT, POST, DELETE, PATCH","Access-Control-Allow-Credentials: true","Access-Control-Max-Age: 1728000"]',false);
265
         $test->expect('["Access-Control-Allow-Headers: Content-Type, X-XSRF-TOKEN","Access-Control-Allow-Methods: OPTIONS, GET, PUT, POST, DELETE, PATCH","Access-Control-Allow-Credentials: true","Access-Control-Max-Age: 1728000"]',false);
377
     }
266
     }
378
 
267
 
379
     public function testHidingPasswordColumn()
268
     public function testHidingPasswordColumn()
380
     {
269
     {
381
-        $test = new API($this);
270
+        $test = new Api($this);
382
         $test->get('/users?filter=id,eq,1&transform=1');
271
         $test->get('/users?filter=id,eq,1&transform=1');
383
         $test->expect('{"users":[{"id":1,"username":"user1","location":null}]}');
272
         $test->expect('{"users":[{"id":1,"username":"user1","location":null}]}');
384
     }
273
     }
385
 
274
 
386
     public function testValidatorErrorMessage()
275
     public function testValidatorErrorMessage()
387
     {
276
     {
388
-        $test = new API($this);
277
+        $test = new Api($this);
389
         $test->put('/posts/1','{"category_id":"a"}');
278
         $test->put('/posts/1','{"category_id":"a"}');
390
         $test->expect(false,'{"category_id":"must be numeric"}');
279
         $test->expect(false,'{"category_id":"must be numeric"}');
391
     }
280
     }
392
 
281
 
393
     public function testSanitizerToStripTags()
282
     public function testSanitizerToStripTags()
394
     {
283
     {
395
-        $test = new API($this);
284
+        $test = new Api($this);
396
         $test->put('/categories/2','{"name":"<script>alert();</script>"}');
285
         $test->put('/categories/2','{"name":"<script>alert();</script>"}');
397
         $test->expect('1');
286
         $test->expect('1');
398
         $test->get('/categories/2');
287
         $test->get('/categories/2');
401
 
290
 
402
     public function testErrorOnInvalidJson()
291
     public function testErrorOnInvalidJson()
403
     {
292
     {
404
-        $test = new API($this);
293
+        $test = new Api($this);
405
         $test->post('/posts','{"}');
294
         $test->post('/posts','{"}');
406
         $test->expect(false,'Not found (input)');
295
         $test->expect(false,'Not found (input)');
407
     }
296
     }
408
 
297
 
409
     public function testErrorOnDuplicatePrimaryKey()
298
     public function testErrorOnDuplicatePrimaryKey()
410
     {
299
     {
411
-        $test = new API($this);
300
+        $test = new Api($this);
412
         $test->post('/posts','{"id":1,"user_id":1,"category_id":1,"content":"blog started (duplicate)"}');
301
         $test->post('/posts','{"id":1,"user_id":1,"category_id":1,"content":"blog started (duplicate)"}');
413
         $test->expect('null');
302
         $test->expect('null');
414
     }
303
     }
415
 
304
 
416
     public function testErrorOnFailingForeignKeyConstraint()
305
     public function testErrorOnFailingForeignKeyConstraint()
417
     {
306
     {
418
-        $test = new API($this);
307
+        $test = new Api($this);
419
         $test->post('/posts','{"user_id":3,"category_id":1,"content":"fk constraint"}');
308
         $test->post('/posts','{"user_id":3,"category_id":1,"content":"fk constraint"}');
420
         $test->expect('null');
309
         $test->expect('null');
421
     }
310
     }
422
 
311
 
423
     public function testMissingIntermediateTable()
312
     public function testMissingIntermediateTable()
424
     {
313
     {
425
-        $test = new API($this);
314
+        $test = new Api($this);
426
         $test->get('/users?include=posts,tags');
315
         $test->get('/users?include=posts,tags');
427
         $test->expect('{"users":{"columns":["id","username","location"],"records":[[1,"user1",null]]},"posts":{"relations":{"user_id":"users.id"},"columns":["id","user_id","category_id","content"],"records":[[1,1,1,"blog started"],[2,1,2,"\u20ac Hello world, \u039a\u03b1\u03bb\u03b7\u03bc\u1f73\u03c1\u03b1 \u03ba\u1f79\u03c3\u03bc\u03b5, \u30b3\u30f3\u30cb\u30c1\u30cf"],[5,1,1,"#1"],[6,1,1,"#2"],[7,1,1,"#3"],[8,1,1,"#4"],[9,1,1,"#5"],[10,1,1,"#6"],[11,1,1,"#7"],[12,1,1,"#8"],[14,1,1,"#10"]]},"post_tags":{"relations":{"post_id":"posts.id"},"columns":["id","post_id","tag_id"],"records":[[1,1,1],[2,1,2],[3,2,1],[4,2,2]]},"tags":{"relations":{"id":"post_tags.tag_id"},"columns":["id","name"],"records":[[1,"funny"],[2,"important"]]}}');
316
         $test->expect('{"users":{"columns":["id","username","location"],"records":[[1,"user1",null]]},"posts":{"relations":{"user_id":"users.id"},"columns":["id","user_id","category_id","content"],"records":[[1,1,1,"blog started"],[2,1,2,"\u20ac Hello world, \u039a\u03b1\u03bb\u03b7\u03bc\u1f73\u03c1\u03b1 \u03ba\u1f79\u03c3\u03bc\u03b5, \u30b3\u30f3\u30cb\u30c1\u30cf"],[5,1,1,"#1"],[6,1,1,"#2"],[7,1,1,"#3"],[8,1,1,"#4"],[9,1,1,"#5"],[10,1,1,"#6"],[11,1,1,"#7"],[12,1,1,"#8"],[14,1,1,"#10"]]},"post_tags":{"relations":{"post_id":"posts.id"},"columns":["id","post_id","tag_id"],"records":[[1,1,1],[2,1,2],[3,2,1],[4,2,2]]},"tags":{"relations":{"id":"post_tags.tag_id"},"columns":["id","name"],"records":[[1,"funny"],[2,"important"]]}}');
428
     }
317
     }
429
 
318
 
430
     public function testEditUserPassword()
319
     public function testEditUserPassword()
431
     {
320
     {
432
-        $test = new API($this);
321
+        $test = new Api($this);
433
         $test->put('/users/1','{"password":"testtest"}');
322
         $test->put('/users/1','{"password":"testtest"}');
434
         $test->expect('1');
323
         $test->expect('1');
435
     }
324
     }
436
 
325
 
437
     public function testEditUserLocation()
326
     public function testEditUserLocation()
438
     {
327
     {
439
-        $test = new API($this);
328
+        $test = new Api($this);
440
         $test->put('/users/1','{"location":"POINT(30 20)"}');
329
         $test->put('/users/1','{"location":"POINT(30 20)"}');
441
         $test->expect('1');
330
         $test->expect('1');
442
         $test->get('/users/1?columns=id,location');
331
         $test->get('/users/1?columns=id,location');
449
 
338
 
450
     public function testListUserLocations()
339
     public function testListUserLocations()
451
     {
340
     {
452
-        $test = new API($this);
341
+        $test = new Api($this);
453
         $test->get('/users?columns=id,location');
342
         $test->get('/users?columns=id,location');
454
         if ($this->getEngineName()=='SQLServer') {
343
         if ($this->getEngineName()=='SQLServer') {
455
             $test->expect('{"users":{"columns":["id","location"],"records":[[1,"POINT (30 20)"]]}}');
344
             $test->expect('{"users":{"columns":["id","location"],"records":[[1,"POINT (30 20)"]]}}');
461
     public function testEditUserWithId()
350
     public function testEditUserWithId()
462
     {
351
     {
463
         if ($this->getEngineName()!='SQLServer') {
352
         if ($this->getEngineName()!='SQLServer') {
464
-            $test = new API($this);
353
+            $test = new Api($this);
465
             $test->put('/users/1','{"id":2,"password":"testtest2"}');
354
             $test->put('/users/1','{"id":2,"password":"testtest2"}');
466
             $test->expect('1');
355
             $test->expect('1');
467
             $test->get('/users/1?columns=id,username,password');
356
             $test->get('/users/1?columns=id,username,password');
471
 
360
 
472
     public function testReadOtherUser()
361
     public function testReadOtherUser()
473
     {
362
     {
474
-        $test = new API($this);
363
+        $test = new Api($this);
475
         $test->get('/users/2');
364
         $test->get('/users/2');
476
         $test->expect(false,'Not found (object)');
365
         $test->expect(false,'Not found (object)');
477
     }
366
     }
478
 
367
 
479
     public function testEditOtherUser()
368
     public function testEditOtherUser()
480
     {
369
     {
481
-        $test = new API($this);
370
+        $test = new Api($this);
482
         $test->put('/users/2','{"password":"testtest"}');
371
         $test->put('/users/2','{"password":"testtest"}');
483
         $test->expect('0');
372
         $test->expect('0');
484
     }
373
     }
485
 
374
 
486
     public function testFilterCategoryOnNullIcon()
375
     public function testFilterCategoryOnNullIcon()
487
     {
376
     {
488
-        $test = new API($this);
377
+        $test = new Api($this);
489
         $test->get('/categories?filter[]=icon,is,null&transform=1');
378
         $test->get('/categories?filter[]=icon,is,null&transform=1');
490
         $test->expect('{"categories":[{"id":1,"name":"announcement","icon":null},{"id":2,"name":"alert();","icon":null}]}');
379
         $test->expect('{"categories":[{"id":1,"name":"announcement","icon":null},{"id":2,"name":"alert();","icon":null}]}');
491
     }
380
     }
492
 
381
 
493
     public function testFilterCategoryOnNotNullIcon()
382
     public function testFilterCategoryOnNotNullIcon()
494
     {
383
     {
495
-        $test = new API($this);
384
+        $test = new Api($this);
496
         $test->get('/categories?filter[]=icon,nis,null&transform=1');
385
         $test->get('/categories?filter[]=icon,nis,null&transform=1');
497
         $test->expect('{"categories":[]}');
386
         $test->expect('{"categories":[]}');
498
     }
387
     }
499
 
388
 
500
     public function testFilterPostsNotIn()
389
     public function testFilterPostsNotIn()
501
     {
390
     {
502
-        $test = new API($this);
391
+        $test = new Api($this);
503
         $test->get('/posts?filter[]=id,nin,1,2,3,4,7,8,9,10,11,12,13,14&transform=1');
392
         $test->get('/posts?filter[]=id,nin,1,2,3,4,7,8,9,10,11,12,13,14&transform=1');
504
         $test->expect('{"posts":[{"id":5,"user_id":1,"category_id":1,"content":"#1"},{"id":6,"user_id":1,"category_id":1,"content":"#2"}]}');
393
         $test->expect('{"posts":[{"id":5,"user_id":1,"category_id":1,"content":"#1"},{"id":6,"user_id":1,"category_id":1,"content":"#2"}]}');
505
     }
394
     }
506
 
395
 
507
     public function testFilterPostsBetween()
396
     public function testFilterPostsBetween()
508
     {
397
     {
509
-        $test = new API($this);
398
+        $test = new Api($this);
510
         $test->get('/posts?filter[]=id,bt,5,6&transform=1');
399
         $test->get('/posts?filter[]=id,bt,5,6&transform=1');
511
         $test->expect('{"posts":[{"id":5,"user_id":1,"category_id":1,"content":"#1"},{"id":6,"user_id":1,"category_id":1,"content":"#2"}]}');
400
         $test->expect('{"posts":[{"id":5,"user_id":1,"category_id":1,"content":"#1"},{"id":6,"user_id":1,"category_id":1,"content":"#2"}]}');
512
     }
401
     }
513
 
402
 
514
     public function testFilterPostsNotBetween()
403
     public function testFilterPostsNotBetween()
515
     {
404
     {
516
-        $test = new API($this);
405
+        $test = new Api($this);
517
         $test->get('/posts?filter[]=id,nbt,2,13&transform=1');
406
         $test->get('/posts?filter[]=id,nbt,2,13&transform=1');
518
         $test->expect('{"posts":[{"id":1,"user_id":1,"category_id":1,"content":"blog started"},{"id":14,"user_id":1,"category_id":1,"content":"#10"}]}');
407
         $test->expect('{"posts":[{"id":1,"user_id":1,"category_id":1,"content":"blog started"},{"id":14,"user_id":1,"category_id":1,"content":"#10"}]}');
519
     }
408
     }
520
 
409
 
521
     public function testColumnsWithTable()
410
     public function testColumnsWithTable()
522
     {
411
     {
523
-        $test = new API($this);
412
+        $test = new Api($this);
524
         $test->get('/posts?columns=posts.content&filter=id,eq,1&transform=1');
413
         $test->get('/posts?columns=posts.content&filter=id,eq,1&transform=1');
525
         $test->expect('{"posts":[{"content":"blog started"}]}');
414
         $test->expect('{"posts":[{"content":"blog started"}]}');
526
     }
415
     }
527
 
416
 
528
     public function testColumnsWithTableWildcard()
417
     public function testColumnsWithTableWildcard()
529
     {
418
     {
530
-        $test = new API($this);
419
+        $test = new Api($this);
531
         $test->get('/posts?columns=posts.*&filter=id,eq,1&transform=1');
420
         $test->get('/posts?columns=posts.*&filter=id,eq,1&transform=1');
532
         $test->expect('{"posts":[{"id":1,"user_id":1,"category_id":1,"content":"blog started"}]}');
421
         $test->expect('{"posts":[{"id":1,"user_id":1,"category_id":1,"content":"blog started"}]}');
533
     }
422
     }
534
 
423
 
535
     public function testColumnsOnInclude()
424
     public function testColumnsOnInclude()
536
     {
425
     {
537
-        $test = new API($this);
426
+        $test = new Api($this);
538
         $test->get('/posts?include=categories&columns=categories.name&filter=id,eq,1&transform=1');
427
         $test->get('/posts?include=categories&columns=categories.name&filter=id,eq,1&transform=1');
539
         $test->expect('{"posts":[{"category_id":1,"categories":[{"id":1,"name":"announcement"}]}]}');
428
         $test->expect('{"posts":[{"category_id":1,"categories":[{"id":1,"name":"announcement"}]}]}');
540
     }
429
     }
541
 
430
 
542
     public function testFilterOnRelationAnd()
431
     public function testFilterOnRelationAnd()
543
     {
432
     {
544
-        $test = new API($this);
433
+        $test = new Api($this);
545
         $test->get('/categories?include=posts&filter[]=id,ge,1&filter[]=id,le,1&filter[]=id,le,2&filter[]=posts.id,lt,8&filter[]=posts.id,gt,4');
434
         $test->get('/categories?include=posts&filter[]=id,ge,1&filter[]=id,le,1&filter[]=id,le,2&filter[]=posts.id,lt,8&filter[]=posts.id,gt,4');
546
         $test->expect('{"categories":{"columns":["id","name","icon"],"records":[[1,"announcement",null]]},"posts":{"relations":{"category_id":"categories.id"},"columns":["id","user_id","category_id","content"],"records":[[5,1,1,"#1"],[6,1,1,"#2"],[7,1,1,"#3"]]}}');
435
         $test->expect('{"categories":{"columns":["id","name","icon"],"records":[[1,"announcement",null]]},"posts":{"relations":{"category_id":"categories.id"},"columns":["id","user_id","category_id","content"],"records":[[5,1,1,"#1"],[6,1,1,"#2"],[7,1,1,"#3"]]}}');
547
     }
436
     }
548
 
437
 
549
     public function testFilterOnRelationOr()
438
     public function testFilterOnRelationOr()
550
     {
439
     {
551
-        $test = new API($this);
440
+        $test = new Api($this);
552
         $test->get('/categories?include=posts&filter[]=id,ge,1&filter[]=id,le,1&filter[]=posts.id,eq,5&filter[]=posts.id,eq,6&filter[]=posts.id,eq,7&satisfy=all,posts.any');
441
         $test->get('/categories?include=posts&filter[]=id,ge,1&filter[]=id,le,1&filter[]=posts.id,eq,5&filter[]=posts.id,eq,6&filter[]=posts.id,eq,7&satisfy=all,posts.any');
553
         $test->expect('{"categories":{"columns":["id","name","icon"],"records":[[1,"announcement",null]]},"posts":{"relations":{"category_id":"categories.id"},"columns":["id","user_id","category_id","content"],"records":[[5,1,1,"#1"],[6,1,1,"#2"],[7,1,1,"#3"]]}}');
442
         $test->expect('{"categories":{"columns":["id","name","icon"],"records":[[1,"announcement",null]]},"posts":{"relations":{"category_id":"categories.id"},"columns":["id","user_id","category_id","content"],"records":[[5,1,1,"#1"],[6,1,1,"#2"],[7,1,1,"#3"]]}}');
554
     }
443
     }
555
 
444
 
556
     public function testColumnsOnWrongInclude()
445
     public function testColumnsOnWrongInclude()
557
     {
446
     {
558
-        $test = new API($this);
447
+        $test = new Api($this);
559
         $test->get('/posts?include=categories&columns=categories&filter=id,eq,1&transform=1');
448
         $test->get('/posts?include=categories&columns=categories&filter=id,eq,1&transform=1');
560
         $test->expect('{"posts":[{"category_id":1,"categories":[{"id":1}]}]}');
449
         $test->expect('{"posts":[{"category_id":1,"categories":[{"id":1}]}]}');
561
     }
450
     }
562
 
451
 
563
     public function testColumnsOnImplicitJoin()
452
     public function testColumnsOnImplicitJoin()
564
     {
453
     {
565
-        $test = new API($this);
454
+        $test = new Api($this);
566
         $test->get('/posts?include=tags&columns=posts.id,tags.name&filter=id,eq,1&transform=1');
455
         $test->get('/posts?include=tags&columns=posts.id,tags.name&filter=id,eq,1&transform=1');
567
         $test->expect('{"posts":[{"id":1,"post_tags":[{"post_id":1,"tag_id":1,"tags":[{"id":1,"name":"funny"}]},{"post_id":1,"tag_id":2,"tags":[{"id":2,"name":"important"}]}]}]}');
456
         $test->expect('{"posts":[{"id":1,"post_tags":[{"post_id":1,"tag_id":1,"tags":[{"id":1,"name":"funny"}]},{"post_id":1,"tag_id":2,"tags":[{"id":2,"name":"important"}]}]}]}');
568
     }
457
     }
570
     public function testSpatialFilterWithin()
459
     public function testSpatialFilterWithin()
571
     {
460
     {
572
         if (static::$capabilities & self::GIS) {
461
         if (static::$capabilities & self::GIS) {
573
-            $test = new API($this);
462
+            $test = new Api($this);
574
             $test->get('/users?columns=id,username&filter=location,swi,POINT(30 20)');
463
             $test->get('/users?columns=id,username&filter=location,swi,POINT(30 20)');
575
             $test->expect('{"users":{"columns":["id","username"],"records":[[1,"user1"]]}}');
464
             $test->expect('{"users":{"columns":["id","username"],"records":[[1,"user1"]]}}');
576
         }
465
         }
578
 
467
 
579
     public function testAddPostsWithNonExistingCategory()
468
     public function testAddPostsWithNonExistingCategory()
580
     {
469
     {
581
-        $test = new API($this);
470
+        $test = new Api($this);
582
         $test->post('/posts','[{"user_id":1,"category_id":1,"content":"tests"},{"user_id":1,"category_id":15,"content":"tests"}]');
471
         $test->post('/posts','[{"user_id":1,"category_id":1,"content":"tests"},{"user_id":1,"category_id":15,"content":"tests"}]');
583
         $test->expect('null');
472
         $test->expect('null');
584
         $test->get('/posts?columns=content&filter=content,eq,tests');
473
         $test->get('/posts?columns=content&filter=content,eq,tests');
587
 
476
 
588
     public function testAddPosts()
477
     public function testAddPosts()
589
     {
478
     {
590
-        $test = new API($this);
479
+        $test = new Api($this);
591
         $test->post('/posts','[{"user_id":1,"category_id":1,"content":"tests"},{"user_id":1,"category_id":1,"content":"tests"}]');
480
         $test->post('/posts','[{"user_id":1,"category_id":1,"content":"tests"},{"user_id":1,"category_id":1,"content":"tests"}]');
592
         $test->expectAny();
481
         $test->expectAny();
593
         $test->get('/posts?columns=content&filter=content,eq,tests');
482
         $test->get('/posts?columns=content&filter=content,eq,tests');
596
 
485
 
597
     public function testListEvents()
486
     public function testListEvents()
598
     {
487
     {
599
-        $test = new API($this);
488
+        $test = new Api($this);
600
         $test->get('/events?columns=datetime');
489
         $test->get('/events?columns=datetime');
601
         $test->expect('{"events":{"columns":["datetime"],"records":[["2016-01-01 13:01:01"]]}}');
490
         $test->expect('{"events":{"columns":["datetime"],"records":[["2016-01-01 13:01:01"]]}}');
602
     }
491
     }
603
 
492
 
604
     public function testIncrementEventVisitors()
493
     public function testIncrementEventVisitors()
605
     {
494
     {
606
-        $test = new API($this);
495
+        $test = new Api($this);
607
         $test->patch('/events/1','{"visitors":11}');
496
         $test->patch('/events/1','{"visitors":11}');
608
         $test->expect('1');
497
         $test->expect('1');
609
         $test->get('/events/1');
498
         $test->get('/events/1');
612
 
501
 
613
     public function testIncrementEventVisitorsWithZero()
502
     public function testIncrementEventVisitorsWithZero()
614
     {
503
     {
615
-        $test = new API($this);
504
+        $test = new Api($this);
616
         $test->patch('/events/1','{"visitors":0}');
505
         $test->patch('/events/1','{"visitors":0}');
617
         $test->expect('1');
506
         $test->expect('1');
618
         $test->get('/events/1');
507
         $test->get('/events/1');
621
 
510
 
622
     public function testDecrementEventVisitors()
511
     public function testDecrementEventVisitors()
623
     {
512
     {
624
-        $test = new API($this);
513
+        $test = new Api($this);
625
         $test->patch('/events/1','{"visitors":-5}');
514
         $test->patch('/events/1','{"visitors":-5}');
626
         $test->expect('1');
515
         $test->expect('1');
627
         $test->get('/events/1');
516
         $test->get('/events/1');
630
 
519
 
631
     public function testListTagUsage()
520
     public function testListTagUsage()
632
     {
521
     {
633
-        $test = new API($this);
522
+        $test = new Api($this);
634
         $test->get('/tag_usage');
523
         $test->get('/tag_usage');
635
         $test->expect('{"tag_usage":{"columns":["name","count"],"records":[["funny",2],["important",2]]}}');
524
         $test->expect('{"tag_usage":{"columns":["name","count"],"records":[["funny",2],["important",2]]}}');
636
     }
525
     }
637
 
526
 
638
     public function testUpdateMultipleTags()
527
     public function testUpdateMultipleTags()
639
     {
528
     {
640
-        $test = new API($this);
529
+        $test = new Api($this);
641
         $test->get('/tags?transform=1');
530
         $test->get('/tags?transform=1');
642
         $test->expect('{"tags":[{"id":1,"name":"funny"},{"id":2,"name":"important"}]}');
531
         $test->expect('{"tags":[{"id":1,"name":"funny"},{"id":2,"name":"important"}]}');
643
         $test->put('/tags/1,2','[{"name":"funny"},{"name":"important"}]');
532
         $test->put('/tags/1,2','[{"name":"funny"},{"name":"important"}]');
646
 
535
 
647
     public function testUpdateMultipleTagsTooManyIds()
536
     public function testUpdateMultipleTagsTooManyIds()
648
     {
537
     {
649
-        $test = new API($this);
538
+        $test = new Api($this);
650
         $test->put('/tags/1,2,3','[{"name":"funny!!!"},{"name":"important"}]');
539
         $test->put('/tags/1,2,3','[{"name":"funny!!!"},{"name":"important"}]');
651
         $test->expect(false,'Not found (subject)');
540
         $test->expect(false,'Not found (subject)');
652
         $test->get('/tags?transform=1');
541
         $test->get('/tags?transform=1');
655
 
544
 
656
     public function testUpdateMultipleTagsWithoutFields()
545
     public function testUpdateMultipleTagsWithoutFields()
657
     {
546
     {
658
-        $test = new API($this);
547
+        $test = new Api($this);
659
         $test->put('/tags/1,2','[{"name":"funny!!!"},{}]');
548
         $test->put('/tags/1,2','[{"name":"funny!!!"},{}]');
660
         $test->expect('null');
549
         $test->expect('null');
661
         $test->get('/tags?transform=1');
550
         $test->get('/tags?transform=1');
664
 
553
 
665
     public function testDeleteMultipleTags()
554
     public function testDeleteMultipleTags()
666
     {
555
     {
667
-        $test = new API($this);
556
+        $test = new Api($this);
668
         $test->post('/tags','[{"name":"extra"},{"name":"more"}]');
557
         $test->post('/tags','[{"name":"extra"},{"name":"more"}]');
669
         $test->expect('[3,4]');
558
         $test->expect('[3,4]');
670
         $test->delete('/tags/3,4');
559
         $test->delete('/tags/3,4');
675
 
564
 
676
     public function testListProducts()
565
     public function testListProducts()
677
     {
566
     {
678
-        $test = new API($this);
567
+        $test = new Api($this);
679
         $test->get('/products?columns=id,name,price&transform=1');
568
         $test->get('/products?columns=id,name,price&transform=1');
680
         $test->expect('{"products":[{"id":1,"name":"Calculator","price":"23.01"}]}');
569
         $test->expect('{"products":[{"id":1,"name":"Calculator","price":"23.01"}]}');
681
     }
570
     }
682
 
571
 
683
     public function testListProductsProperties()
572
     public function testListProductsProperties()
684
     {
573
     {
685
-        $test = new API($this);
574
+        $test = new Api($this);
686
         $test->get('/products?columns=id,properties&transform=1');
575
         $test->get('/products?columns=id,properties&transform=1');
687
         if (static::$capabilities & self::JSON) {
576
         if (static::$capabilities & self::JSON) {
688
             $test->expect('{"products":[{"id":1,"properties":{"depth":false,"model":"TRX-120","width":100,"height":null}}]}');
577
             $test->expect('{"products":[{"id":1,"properties":{"depth":false,"model":"TRX-120","width":100,"height":null}}]}');
693
 
582
 
694
     public function testReadProductProperties()
583
     public function testReadProductProperties()
695
     {
584
     {
696
-        $test = new API($this);
585
+        $test = new Api($this);
697
         $test->get('/products/1?columns=id,properties');
586
         $test->get('/products/1?columns=id,properties');
698
         if (static::$capabilities & self::JSON) {
587
         if (static::$capabilities & self::JSON) {
699
             $test->expect('{"id":1,"properties":{"depth":false,"model":"TRX-120","width":100,"height":null}}');
588
             $test->expect('{"id":1,"properties":{"depth":false,"model":"TRX-120","width":100,"height":null}}');
704
 
593
 
705
     public function testWriteProductProperties()
594
     public function testWriteProductProperties()
706
     {
595
     {
707
-        $test = new API($this);
596
+        $test = new Api($this);
708
         if (static::$capabilities & self::JSON) {
597
         if (static::$capabilities & self::JSON) {
709
             $test->put('/products/1','{"properties":{"depth":false,"model":"TRX-120","width":100,"height":123}}');
598
             $test->put('/products/1','{"properties":{"depth":false,"model":"TRX-120","width":100,"height":123}}');
710
         } else {
599
         } else {
721
 
610
 
722
     public function testAddProducts()
611
     public function testAddProducts()
723
     {
612
     {
724
-        $test = new API($this);
613
+        $test = new Api($this);
725
         if (static::$capabilities & self::JSON) {
614
         if (static::$capabilities & self::JSON) {
726
             $test->post('/products','{"name":"Laptop","price":"1299.99","properties":{}}');
615
             $test->post('/products','{"name":"Laptop","price":"1299.99","properties":{}}');
727
         } else {
616
         } else {
734
 
623
 
735
     public function testSoftDeleteProducts()
624
     public function testSoftDeleteProducts()
736
     {
625
     {
737
-        $test = new API($this);
626
+        $test = new Api($this);
738
         $test->delete('/products/1,2');
627
         $test->delete('/products/1,2');
739
         $test->expect('[1,1]');
628
         $test->expect('[1,1]');
740
         $test->get('/products?columns=id,deleted_at');
629
         $test->get('/products?columns=id,deleted_at');
743
 
632
 
744
     public function testVarBinaryBarcodes()
633
     public function testVarBinaryBarcodes()
745
     {
634
     {
746
-        $test = new API($this);
635
+        $test = new Api($this);
747
         $test->get('/barcodes?transform=1');
636
         $test->get('/barcodes?transform=1');
748
         $test->expect('{"barcodes":[{"id":1,"product_id":1,"hex":"00ff01","bin":"AP8B"}]}');
637
         $test->expect('{"barcodes":[{"id":1,"product_id":1,"hex":"00ff01","bin":"AP8B"}]}');
749
     }
638
     }

Loading…
Cancel
Save