|
@@ -48,14 +48,14 @@ abstract class Tests extends TestBase
|
48
|
48
|
public function testAddPost()
|
49
|
49
|
{
|
50
|
50
|
$test = new Api($this);
|
51
|
|
- $test->post('/posts','{"user_id":1,"category_id":1,"content":"test"}');
|
|
51
|
+ $test->post('/posts', '{"user_id":1,"category_id":1,"content":"test"}');
|
52
|
52
|
$test->expect('3');
|
53
|
53
|
}
|
54
|
54
|
|
55
|
55
|
public function testEditPost()
|
56
|
56
|
{
|
57
|
57
|
$test = new Api($this);
|
58
|
|
- $test->put('/posts/3','{"user_id":1,"category_id":1,"content":"test (edited)"}');
|
|
58
|
+ $test->put('/posts/3', '{"user_id":1,"category_id":1,"content":"test (edited)"}');
|
59
|
59
|
$test->expect('1');
|
60
|
60
|
$test->get('/posts/3');
|
61
|
61
|
$test->expect('{"id":3,"user_id":1,"category_id":1,"content":"test (edited)"}');
|
|
@@ -64,7 +64,7 @@ abstract class Tests extends TestBase
|
64
|
64
|
public function testEditPostColumnsMissingField()
|
65
|
65
|
{
|
66
|
66
|
$test = new Api($this);
|
67
|
|
- $test->put('/posts/3?columns=id,content','{"content":"test (edited 2)"}');
|
|
67
|
+ $test->put('/posts/3?columns=id,content', '{"content":"test (edited 2)"}');
|
68
|
68
|
$test->expect('1');
|
69
|
69
|
$test->get('/posts/3');
|
70
|
70
|
$test->expect('{"id":3,"user_id":1,"category_id":1,"content":"test (edited 2)"}');
|
|
@@ -73,7 +73,7 @@ abstract class Tests extends TestBase
|
73
|
73
|
public function testEditPostColumnsExtraField()
|
74
|
74
|
{
|
75
|
75
|
$test = new Api($this);
|
76
|
|
- $test->put('/posts/3?columns=id,content','{"user_id":2,"content":"test (edited 3)"}');
|
|
76
|
+ $test->put('/posts/3?columns=id,content', '{"user_id":2,"content":"test (edited 3)"}');
|
77
|
77
|
$test->expect('1');
|
78
|
78
|
$test->get('/posts/3');
|
79
|
79
|
$test->expect('{"id":3,"user_id":1,"category_id":1,"content":"test (edited 3)"}');
|
|
@@ -83,7 +83,7 @@ abstract class Tests extends TestBase
|
83
|
83
|
{
|
84
|
84
|
$utf8 = json_encode('Hello world, Καλημέρα κόσμε, コンニチハ');
|
85
|
85
|
$test = new Api($this);
|
86
|
|
- $test->put('/posts/2','{"content":'.$utf8.'}');
|
|
86
|
+ $test->put('/posts/2', '{"content":'.$utf8.'}');
|
87
|
87
|
$test->expect('1');
|
88
|
88
|
$test->get('/posts/2');
|
89
|
89
|
$test->expect('{"id":2,"user_id":1,"category_id":2,"content":'.$utf8.'}');
|
|
@@ -95,7 +95,7 @@ abstract class Tests extends TestBase
|
95
|
95
|
$url_encoded = urlencode($utf8);
|
96
|
96
|
$json_encoded = json_encode($utf8);
|
97
|
97
|
$test = new Api($this);
|
98
|
|
- $test->put('/posts/2','content='.$url_encoded);
|
|
98
|
+ $test->put('/posts/2', 'content='.$url_encoded);
|
99
|
99
|
$test->expect('1');
|
100
|
100
|
$test->get('/posts/2');
|
101
|
101
|
$test->expect('{"id":2,"user_id":1,"category_id":2,"content":'.$json_encoded.'}');
|
|
@@ -107,20 +107,20 @@ abstract class Tests extends TestBase
|
107
|
107
|
$test->delete('/posts/3');
|
108
|
108
|
$test->expect('1');
|
109
|
109
|
$test->get('/posts/3');
|
110
|
|
- $test->expect(false,'Not found (object)');
|
|
110
|
+ $test->expect(false, 'Not found (object)');
|
111
|
111
|
}
|
112
|
112
|
|
113
|
113
|
public function testAddPostWithPost()
|
114
|
114
|
{
|
115
|
115
|
$test = new Api($this);
|
116
|
|
- $test->post('/posts','user_id=1&category_id=1&content=test');
|
|
116
|
+ $test->post('/posts', 'user_id=1&category_id=1&content=test');
|
117
|
117
|
$test->expect('4');
|
118
|
118
|
}
|
119
|
119
|
|
120
|
120
|
public function testEditPostWithPost()
|
121
|
121
|
{
|
122
|
122
|
$test = new Api($this);
|
123
|
|
- $test->put('/posts/4','user_id=1&category_id=1&content=test+(edited)');
|
|
123
|
+ $test->put('/posts/4', 'user_id=1&category_id=1&content=test+(edited)');
|
124
|
124
|
$test->expect('1');
|
125
|
125
|
$test->get('/posts/4');
|
126
|
126
|
$test->expect('{"id":4,"user_id":1,"category_id":1,"content":"test (edited)"}');
|
|
@@ -132,14 +132,14 @@ abstract class Tests extends TestBase
|
132
|
132
|
$test->delete('/posts/4');
|
133
|
133
|
$test->expect('1');
|
134
|
134
|
$test->get('/posts/4');
|
135
|
|
- $test->expect(false,'Not found (object)');
|
|
135
|
+ $test->expect(false, 'Not found (object)');
|
136
|
136
|
}
|
137
|
137
|
|
138
|
138
|
public function testListWithPaginate()
|
139
|
139
|
{
|
140
|
140
|
$test = new Api($this);
|
141
|
141
|
for ($i=1;$i<=10;$i++) {
|
142
|
|
- $test->post('/posts','{"user_id":1,"category_id":1,"content":"#'.$i.'"}');
|
|
142
|
+ $test->post('/posts', '{"user_id":1,"category_id":1,"content":"#'.$i.'"}');
|
143
|
143
|
$test->expect(4+$i);
|
144
|
144
|
}
|
145
|
145
|
$test->get('/posts?page=2,2&order=id');
|
|
@@ -207,7 +207,7 @@ abstract class Tests extends TestBase
|
207
|
207
|
$binary = base64_encode("\0abc\0\n\r\b\0");
|
208
|
208
|
$base64url = rtrim(strtr($binary, '+/', '-_'), '=');
|
209
|
209
|
$test = new Api($this);
|
210
|
|
- $test->put('/categories/2','{"icon":"'.$base64url.'"}');
|
|
210
|
+ $test->put('/categories/2', '{"icon":"'.$base64url.'"}');
|
211
|
211
|
$test->expect('1');
|
212
|
212
|
$test->get('/categories/2');
|
213
|
213
|
$test->expect('{"id":2,"name":"article","icon":"'.$binary.'"}');
|
|
@@ -216,7 +216,7 @@ abstract class Tests extends TestBase
|
216
|
216
|
public function testEditCategoryWithNull()
|
217
|
217
|
{
|
218
|
218
|
$test = new Api($this);
|
219
|
|
- $test->put('/categories/2','{"icon":null}');
|
|
219
|
+ $test->put('/categories/2', '{"icon":null}');
|
220
|
220
|
$test->expect('1');
|
221
|
221
|
$test->get('/categories/2');
|
222
|
222
|
$test->expect('{"id":2,"name":"article","icon":null}');
|
|
@@ -227,7 +227,7 @@ abstract class Tests extends TestBase
|
227
|
227
|
$binary = base64_encode("€ \0abc\0\n\r\b\0");
|
228
|
228
|
$base64url = rtrim(strtr($binary, '+/', '-_'), '=');
|
229
|
229
|
$test = new Api($this);
|
230
|
|
- $test->put('/categories/2','icon='.$base64url);
|
|
230
|
+ $test->put('/categories/2', 'icon='.$base64url);
|
231
|
231
|
$test->expect('1');
|
232
|
232
|
$test->get('/categories/2');
|
233
|
233
|
$test->expect('{"id":2,"name":"article","icon":"'.$binary.'"}');
|
|
@@ -243,7 +243,7 @@ abstract class Tests extends TestBase
|
243
|
243
|
public function testEditCategoryWithNullWithPost()
|
244
|
244
|
{
|
245
|
245
|
$test = new Api($this);
|
246
|
|
- $test->put('/categories/2','icon__is_null');
|
|
246
|
+ $test->put('/categories/2', 'icon__is_null');
|
247
|
247
|
$test->expect('1');
|
248
|
248
|
$test->get('/categories/2');
|
249
|
249
|
$test->expect('{"id":2,"name":"article","icon":null}');
|
|
@@ -252,7 +252,7 @@ abstract class Tests extends TestBase
|
252
|
252
|
public function testAddPostFailure()
|
253
|
253
|
{
|
254
|
254
|
$test = new Api($this);
|
255
|
|
- $test->post('/posts','{"user_id":"a","category_id":1,"content":"tests"}');
|
|
255
|
+ $test->post('/posts', '{"user_id":"a","category_id":1,"content":"tests"}');
|
256
|
256
|
$test->expect('null');
|
257
|
257
|
}
|
258
|
258
|
|
|
@@ -260,7 +260,7 @@ abstract class Tests extends TestBase
|
260
|
260
|
{
|
261
|
261
|
$test = new Api($this);
|
262
|
262
|
$test->options('/posts/2');
|
263
|
|
- $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);
|
|
263
|
+ $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);
|
264
|
264
|
}
|
265
|
265
|
|
266
|
266
|
public function testHidingPasswordColumn()
|
|
@@ -273,14 +273,14 @@ abstract class Tests extends TestBase
|
273
|
273
|
public function testValidatorErrorMessage()
|
274
|
274
|
{
|
275
|
275
|
$test = new Api($this);
|
276
|
|
- $test->put('/posts/1','{"category_id":"a"}');
|
277
|
|
- $test->expect(false,'{"category_id":"must be numeric"}');
|
|
276
|
+ $test->put('/posts/1', '{"category_id":"a"}');
|
|
277
|
+ $test->expect(false, '{"category_id":"must be numeric"}');
|
278
|
278
|
}
|
279
|
279
|
|
280
|
280
|
public function testSanitizerToStripTags()
|
281
|
281
|
{
|
282
|
282
|
$test = new Api($this);
|
283
|
|
- $test->put('/categories/2','{"name":"<script>alert();</script>"}');
|
|
283
|
+ $test->put('/categories/2', '{"name":"<script>alert();</script>"}');
|
284
|
284
|
$test->expect('1');
|
285
|
285
|
$test->get('/categories/2');
|
286
|
286
|
$test->expect('{"id":2,"name":"alert();","icon":null}');
|
|
@@ -289,21 +289,21 @@ abstract class Tests extends TestBase
|
289
|
289
|
public function testErrorOnInvalidJson()
|
290
|
290
|
{
|
291
|
291
|
$test = new Api($this);
|
292
|
|
- $test->post('/posts','{"}');
|
293
|
|
- $test->expect(false,'Not found (input)');
|
|
292
|
+ $test->post('/posts', '{"}');
|
|
293
|
+ $test->expect(false, 'Not found (input)');
|
294
|
294
|
}
|
295
|
295
|
|
296
|
296
|
public function testErrorOnDuplicatePrimaryKey()
|
297
|
297
|
{
|
298
|
298
|
$test = new Api($this);
|
299
|
|
- $test->post('/posts','{"id":1,"user_id":1,"category_id":1,"content":"blog started (duplicate)"}');
|
|
299
|
+ $test->post('/posts', '{"id":1,"user_id":1,"category_id":1,"content":"blog started (duplicate)"}');
|
300
|
300
|
$test->expect('null');
|
301
|
301
|
}
|
302
|
302
|
|
303
|
303
|
public function testErrorOnFailingForeignKeyConstraint()
|
304
|
304
|
{
|
305
|
305
|
$test = new Api($this);
|
306
|
|
- $test->post('/posts','{"user_id":3,"category_id":1,"content":"fk constraint"}');
|
|
306
|
+ $test->post('/posts', '{"user_id":3,"category_id":1,"content":"fk constraint"}');
|
307
|
307
|
$test->expect('null');
|
308
|
308
|
}
|
309
|
309
|
|
|
@@ -317,14 +317,14 @@ abstract class Tests extends TestBase
|
317
|
317
|
public function testEditUserPassword()
|
318
|
318
|
{
|
319
|
319
|
$test = new Api($this);
|
320
|
|
- $test->put('/users/1','{"password":"testtest"}');
|
|
320
|
+ $test->put('/users/1', '{"password":"testtest"}');
|
321
|
321
|
$test->expect('1');
|
322
|
322
|
}
|
323
|
323
|
|
324
|
324
|
public function testEditUserLocation()
|
325
|
325
|
{
|
326
|
326
|
$test = new Api($this);
|
327
|
|
- $test->put('/users/1','{"location":"POINT(30 20)"}');
|
|
327
|
+ $test->put('/users/1', '{"location":"POINT(30 20)"}');
|
328
|
328
|
$test->expect('1');
|
329
|
329
|
$test->get('/users/1?columns=id,location');
|
330
|
330
|
if ($this->getEngineName()=='SQLServer') {
|
|
@@ -349,7 +349,7 @@ abstract class Tests extends TestBase
|
349
|
349
|
{
|
350
|
350
|
if ($this->getEngineName()!='SQLServer') {
|
351
|
351
|
$test = new Api($this);
|
352
|
|
- $test->put('/users/1','{"id":2,"password":"testtest2"}');
|
|
352
|
+ $test->put('/users/1', '{"id":2,"password":"testtest2"}');
|
353
|
353
|
$test->expect('1');
|
354
|
354
|
$test->get('/users/1?columns=id,username,password');
|
355
|
355
|
$test->expect('{"id":1,"username":"user1","password":"testtest2"}');
|
|
@@ -360,13 +360,13 @@ abstract class Tests extends TestBase
|
360
|
360
|
{
|
361
|
361
|
$test = new Api($this);
|
362
|
362
|
$test->get('/users/2');
|
363
|
|
- $test->expect(false,'Not found (object)');
|
|
363
|
+ $test->expect(false, 'Not found (object)');
|
364
|
364
|
}
|
365
|
365
|
|
366
|
366
|
public function testEditOtherUser()
|
367
|
367
|
{
|
368
|
368
|
$test = new Api($this);
|
369
|
|
- $test->put('/users/2','{"password":"testtest"}');
|
|
369
|
+ $test->put('/users/2', '{"password":"testtest"}');
|
370
|
370
|
$test->expect('0');
|
371
|
371
|
}
|
372
|
372
|
|
|
@@ -466,7 +466,7 @@ abstract class Tests extends TestBase
|
466
|
466
|
public function testAddPostsWithNonExistingCategory()
|
467
|
467
|
{
|
468
|
468
|
$test = new Api($this);
|
469
|
|
- $test->post('/posts','[{"user_id":1,"category_id":1,"content":"tests"},{"user_id":1,"category_id":15,"content":"tests"}]');
|
|
469
|
+ $test->post('/posts', '[{"user_id":1,"category_id":1,"content":"tests"},{"user_id":1,"category_id":15,"content":"tests"}]');
|
470
|
470
|
$test->expect('null');
|
471
|
471
|
$test->get('/posts?columns=content&filter=content,eq,tests');
|
472
|
472
|
$test->expect('{"posts":{"columns":["content"],"records":[]}}');
|
|
@@ -475,7 +475,7 @@ abstract class Tests extends TestBase
|
475
|
475
|
public function testAddPosts()
|
476
|
476
|
{
|
477
|
477
|
$test = new Api($this);
|
478
|
|
- $test->post('/posts','[{"user_id":1,"category_id":1,"content":"tests"},{"user_id":1,"category_id":1,"content":"tests"}]');
|
|
478
|
+ $test->post('/posts', '[{"user_id":1,"category_id":1,"content":"tests"},{"user_id":1,"category_id":1,"content":"tests"}]');
|
479
|
479
|
$test->expectAny();
|
480
|
480
|
$test->get('/posts?columns=content&filter=content,eq,tests');
|
481
|
481
|
$test->expect('{"posts":{"columns":["content"],"records":[["tests"],["tests"]]}}');
|
|
@@ -491,7 +491,7 @@ abstract class Tests extends TestBase
|
491
|
491
|
public function testIncrementEventVisitors()
|
492
|
492
|
{
|
493
|
493
|
$test = new Api($this);
|
494
|
|
- $test->patch('/events/1','{"visitors":11}');
|
|
494
|
+ $test->patch('/events/1', '{"visitors":11}');
|
495
|
495
|
$test->expect('1');
|
496
|
496
|
$test->get('/events/1');
|
497
|
497
|
$test->expect('{"id":1,"name":"Launch","datetime":"2016-01-01 13:01:01","visitors":11}');
|
|
@@ -500,7 +500,7 @@ abstract class Tests extends TestBase
|
500
|
500
|
public function testIncrementEventVisitorsWithZero()
|
501
|
501
|
{
|
502
|
502
|
$test = new Api($this);
|
503
|
|
- $test->patch('/events/1','{"visitors":0}');
|
|
503
|
+ $test->patch('/events/1', '{"visitors":0}');
|
504
|
504
|
$test->expect('1');
|
505
|
505
|
$test->get('/events/1');
|
506
|
506
|
$test->expect('{"id":1,"name":"Launch","datetime":"2016-01-01 13:01:01","visitors":11}');
|
|
@@ -509,7 +509,7 @@ abstract class Tests extends TestBase
|
509
|
509
|
public function testDecrementEventVisitors()
|
510
|
510
|
{
|
511
|
511
|
$test = new Api($this);
|
512
|
|
- $test->patch('/events/1','{"visitors":-5}');
|
|
512
|
+ $test->patch('/events/1', '{"visitors":-5}');
|
513
|
513
|
$test->expect('1');
|
514
|
514
|
$test->get('/events/1');
|
515
|
515
|
$test->expect('{"id":1,"name":"Launch","datetime":"2016-01-01 13:01:01","visitors":6}');
|
|
@@ -527,15 +527,15 @@ abstract class Tests extends TestBase
|
527
|
527
|
$test = new Api($this);
|
528
|
528
|
$test->get('/tags?transform=1');
|
529
|
529
|
$test->expect('{"tags":[{"id":1,"name":"funny"},{"id":2,"name":"important"}]}');
|
530
|
|
- $test->put('/tags/1,2','[{"name":"funny"},{"name":"important"}]');
|
|
530
|
+ $test->put('/tags/1,2', '[{"name":"funny"},{"name":"important"}]');
|
531
|
531
|
$test->expect('[1,1]');
|
532
|
532
|
}
|
533
|
533
|
|
534
|
534
|
public function testUpdateMultipleTagsTooManyIds()
|
535
|
535
|
{
|
536
|
536
|
$test = new Api($this);
|
537
|
|
- $test->put('/tags/1,2,3','[{"name":"funny!!!"},{"name":"important"}]');
|
538
|
|
- $test->expect(false,'Not found (subject)');
|
|
537
|
+ $test->put('/tags/1,2,3', '[{"name":"funny!!!"},{"name":"important"}]');
|
|
538
|
+ $test->expect(false, 'Not found (subject)');
|
539
|
539
|
$test->get('/tags?transform=1');
|
540
|
540
|
$test->expect('{"tags":[{"id":1,"name":"funny"},{"id":2,"name":"important"}]}');
|
541
|
541
|
}
|
|
@@ -543,7 +543,7 @@ abstract class Tests extends TestBase
|
543
|
543
|
public function testUpdateMultipleTagsWithoutFields()
|
544
|
544
|
{
|
545
|
545
|
$test = new Api($this);
|
546
|
|
- $test->put('/tags/1,2','[{"name":"funny!!!"},{}]');
|
|
546
|
+ $test->put('/tags/1,2', '[{"name":"funny!!!"},{}]');
|
547
|
547
|
$test->expect('null');
|
548
|
548
|
$test->get('/tags?transform=1');
|
549
|
549
|
$test->expect('{"tags":[{"id":1,"name":"funny"},{"id":2,"name":"important"}]}');
|
|
@@ -552,7 +552,7 @@ abstract class Tests extends TestBase
|
552
|
552
|
public function testDeleteMultipleTags()
|
553
|
553
|
{
|
554
|
554
|
$test = new Api($this);
|
555
|
|
- $test->post('/tags','[{"name":"extra"},{"name":"more"}]');
|
|
555
|
+ $test->post('/tags', '[{"name":"extra"},{"name":"more"}]');
|
556
|
556
|
$test->expect('[3,4]');
|
557
|
557
|
$test->delete('/tags/3,4');
|
558
|
558
|
$test->expect('[1,1]');
|
|
@@ -593,9 +593,9 @@ abstract class Tests extends TestBase
|
593
|
593
|
{
|
594
|
594
|
$test = new Api($this);
|
595
|
595
|
if (static::$capabilities & self::JSON) {
|
596
|
|
- $test->put('/products/1','{"properties":{"depth":false,"model":"TRX-120","width":100,"height":123}}');
|
|
596
|
+ $test->put('/products/1', '{"properties":{"depth":false,"model":"TRX-120","width":100,"height":123}}');
|
597
|
597
|
} else {
|
598
|
|
- $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}"}');
|
599
|
599
|
}
|
600
|
600
|
$test->expect('1');
|
601
|
601
|
$test->get('/products/1?columns=id,properties');
|
|
@@ -610,9 +610,9 @@ abstract class Tests extends TestBase
|
610
|
610
|
{
|
611
|
611
|
$test = new Api($this);
|
612
|
612
|
if (static::$capabilities & self::JSON) {
|
613
|
|
- $test->post('/products','{"name":"Laptop","price":"1299.99","properties":{}}');
|
|
613
|
+ $test->post('/products', '{"name":"Laptop","price":"1299.99","properties":{}}');
|
614
|
614
|
} else {
|
615
|
|
- $test->post('/products','{"name":"Laptop","price":"1299.99","properties":"{}"}');
|
|
615
|
+ $test->post('/products', '{"name":"Laptop","price":"1299.99","properties":"{}"}');
|
616
|
616
|
}
|
617
|
617
|
$test->expect('2');
|
618
|
618
|
$test->get('/products/2?columns=id,created_at,deleted_at');
|