|
@@ -192,58 +192,58 @@ class PHP_CRUD_API_Test extends PHPUnit_Framework_TestCase
|
192
|
192
|
{
|
193
|
193
|
$test = new API($this);
|
194
|
194
|
$test->get('/posts');
|
195
|
|
- $test->expect('{"posts":{"columns":["id","user_id","category_id","content"],"records":[["1","1","1","blog started"],["2","1","2","It works!"]]}}');
|
|
195
|
+ $test->expect('{"posts":{"columns":["id","user_id","category_id","content"],"records":[[1,1,1,"blog started"],[2,1,2,"It works!"]]}}');
|
196
|
196
|
}
|
197
|
197
|
|
198
|
198
|
public function testListPostColumns()
|
199
|
199
|
{
|
200
|
200
|
$test = new API($this);
|
201
|
201
|
$test->get('/posts?columns=id,content');
|
202
|
|
- $test->expect('{"posts":{"columns":["id","content"],"records":[["1","blog started"],["2","It works!"]]}}');
|
|
202
|
+ $test->expect('{"posts":{"columns":["id","content"],"records":[[1,"blog started"],[2,"It works!"]]}}');
|
203
|
203
|
}
|
204
|
204
|
|
205
|
205
|
public function testListPostsWithTransform()
|
206
|
206
|
{
|
207
|
207
|
$test = new API($this);
|
208
|
208
|
$test->get('/posts?transform=1');
|
209
|
|
- $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!"}]}');
|
|
209
|
+ $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!"}]}');
|
210
|
210
|
}
|
211
|
211
|
|
212
|
212
|
public function testReadPost()
|
213
|
213
|
{
|
214
|
214
|
$test = new API($this);
|
215
|
215
|
$test->get('/posts/2');
|
216
|
|
- $test->expect('{"id":"2","user_id":"1","category_id":"2","content":"It works!"}');
|
|
216
|
+ $test->expect('{"id":2,"user_id":1,"category_id":2,"content":"It works!"}');
|
217
|
217
|
}
|
218
|
218
|
|
219
|
219
|
public function testReadPosts()
|
220
|
220
|
{
|
221
|
221
|
$test = new API($this);
|
222
|
222
|
$test->get('/posts/1,2');
|
223
|
|
- $test->expect('[{"id":"1","user_id":"1","category_id":"1","content":"blog started"},{"id":"2","user_id":"1","category_id":"2","content":"It works!"}]');
|
|
223
|
+ $test->expect('[{"id":1,"user_id":1,"category_id":1,"content":"blog started"},{"id":2,"user_id":1,"category_id":2,"content":"It works!"}]');
|
224
|
224
|
}
|
225
|
225
|
|
226
|
226
|
public function testReadPostColumns()
|
227
|
227
|
{
|
228
|
228
|
$test = new API($this);
|
229
|
229
|
$test->get('/posts/2?columns=id,content');
|
230
|
|
- $test->expect('{"id":"2","content":"It works!"}');
|
|
230
|
+ $test->expect('{"id":2,"content":"It works!"}');
|
231
|
231
|
}
|
232
|
232
|
|
233
|
233
|
public function testAddPost()
|
234
|
234
|
{
|
235
|
235
|
$test = new API($this);
|
236
|
|
- $test->post('/posts','{"user_id":"1","category_id":"1","content":"test"}');
|
|
236
|
+ $test->post('/posts','{"user_id":1,"category_id":1,"content":"test"}');
|
237
|
237
|
$test->expect('3');
|
238
|
238
|
}
|
239
|
239
|
|
240
|
240
|
public function testEditPost()
|
241
|
241
|
{
|
242
|
242
|
$test = new API($this);
|
243
|
|
- $test->put('/posts/3','{"user_id":"1","category_id":"1","content":"test (edited)"}');
|
|
243
|
+ $test->put('/posts/3','{"user_id":1,"category_id":1,"content":"test (edited)"}');
|
244
|
244
|
$test->expect('1');
|
245
|
245
|
$test->get('/posts/3');
|
246
|
|
- $test->expect('{"id":"3","user_id":"1","category_id":"1","content":"test (edited)"}');
|
|
246
|
+ $test->expect('{"id":3,"user_id":1,"category_id":1,"content":"test (edited)"}');
|
247
|
247
|
}
|
248
|
248
|
|
249
|
249
|
public function testEditPostColumnsMissingField()
|
|
@@ -252,16 +252,16 @@ class PHP_CRUD_API_Test extends PHPUnit_Framework_TestCase
|
252
|
252
|
$test->put('/posts/3?columns=id,content','{"content":"test (edited 2)"}');
|
253
|
253
|
$test->expect('1');
|
254
|
254
|
$test->get('/posts/3');
|
255
|
|
- $test->expect('{"id":"3","user_id":"1","category_id":"1","content":"test (edited 2)"}');
|
|
255
|
+ $test->expect('{"id":3,"user_id":1,"category_id":1,"content":"test (edited 2)"}');
|
256
|
256
|
}
|
257
|
257
|
|
258
|
258
|
public function testEditPostColumnsExtraField()
|
259
|
259
|
{
|
260
|
260
|
$test = new API($this);
|
261
|
|
- $test->put('/posts/3?columns=id,content','{"user_id":"2","content":"test (edited 3)"}');
|
|
261
|
+ $test->put('/posts/3?columns=id,content','{"user_id":2,"content":"test (edited 3)"}');
|
262
|
262
|
$test->expect('1');
|
263
|
263
|
$test->get('/posts/3');
|
264
|
|
- $test->expect('{"id":"3","user_id":"1","category_id":"1","content":"test (edited 3)"}');
|
|
264
|
+ $test->expect('{"id":3,"user_id":1,"category_id":1,"content":"test (edited 3)"}');
|
265
|
265
|
}
|
266
|
266
|
|
267
|
267
|
public function testEditPostWithUtf8Content()
|
|
@@ -271,7 +271,7 @@ class PHP_CRUD_API_Test extends PHPUnit_Framework_TestCase
|
271
|
271
|
$test->put('/posts/2','{"content":'.$utf8.'}');
|
272
|
272
|
$test->expect('1');
|
273
|
273
|
$test->get('/posts/2');
|
274
|
|
- $test->expect('{"id":"2","user_id":"1","category_id":"2","content":'.$utf8.'}');
|
|
274
|
+ $test->expect('{"id":2,"user_id":1,"category_id":2,"content":'.$utf8.'}');
|
275
|
275
|
}
|
276
|
276
|
|
277
|
277
|
public function testEditPostWithUtf8ContentWithPost()
|
|
@@ -283,7 +283,7 @@ class PHP_CRUD_API_Test extends PHPUnit_Framework_TestCase
|
283
|
283
|
$test->put('/posts/2','content='.$url_encoded);
|
284
|
284
|
$test->expect('1');
|
285
|
285
|
$test->get('/posts/2');
|
286
|
|
- $test->expect('{"id":"2","user_id":"1","category_id":"2","content":'.$json_encoded.'}');
|
|
286
|
+ $test->expect('{"id":2,"user_id":1,"category_id":2,"content":'.$json_encoded.'}');
|
287
|
287
|
}
|
288
|
288
|
|
289
|
289
|
public function testDeletePost()
|
|
@@ -308,7 +308,7 @@ class PHP_CRUD_API_Test extends PHPUnit_Framework_TestCase
|
308
|
308
|
$test->put('/posts/4','user_id=1&category_id=1&content=test+(edited)');
|
309
|
309
|
$test->expect('1');
|
310
|
310
|
$test->get('/posts/4');
|
311
|
|
- $test->expect('{"id":"4","user_id":"1","category_id":"1","content":"test (edited)"}');
|
|
311
|
+ $test->expect('{"id":4,"user_id":1,"category_id":1,"content":"test (edited)"}');
|
312
|
312
|
}
|
313
|
313
|
|
314
|
314
|
public function testDeletePostWithPost()
|
|
@@ -324,32 +324,32 @@ class PHP_CRUD_API_Test extends PHPUnit_Framework_TestCase
|
324
|
324
|
{
|
325
|
325
|
$test = new API($this);
|
326
|
326
|
for ($i=1;$i<=10;$i++) {
|
327
|
|
- $test->post('/posts','{"user_id":"1","category_id":"1","content":"#'.$i.'"}');
|
|
327
|
+ $test->post('/posts','{"user_id":1,"category_id":1,"content":"#'.$i.'"}');
|
328
|
328
|
$test->expect(4+$i);
|
329
|
329
|
}
|
330
|
330
|
$test->get('/posts?page=2,2&order=id');
|
331
|
|
- $test->expect('{"posts":{"columns":["id","user_id","category_id","content"],"records":[["5","1","1","#1"],["6","1","1","#2"]],"results":11}}');
|
|
331
|
+ $test->expect('{"posts":{"columns":["id","user_id","category_id","content"],"records":[[5,1,1,"#1"],[6,1,1,"#2"]],"results":11}}');
|
332
|
332
|
}
|
333
|
333
|
|
334
|
334
|
public function testListWithPaginateLastPage()
|
335
|
335
|
{
|
336
|
336
|
$test = new API($this);
|
337
|
337
|
$test->get('/posts?page=3,5&order=id');
|
338
|
|
- $test->expect('{"posts":{"columns":["id","user_id","category_id","content"],"records":[["14","1","1","#10"]],"results":11}}');
|
|
338
|
+ $test->expect('{"posts":{"columns":["id","user_id","category_id","content"],"records":[[14,1,1,"#10"]],"results":11}}');
|
339
|
339
|
}
|
340
|
340
|
|
341
|
341
|
public function testListExampleFromReadme()
|
342
|
342
|
{
|
343
|
343
|
$test = new API($this);
|
344
|
344
|
$test->get('/posts?include=categories,tags,comments&filter=id,eq,1');
|
345
|
|
- $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"]]}}');
|
|
345
|
+ $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"]]}}');
|
346
|
346
|
}
|
347
|
347
|
|
348
|
348
|
public function testListExampleFromReadmeWithTransform()
|
349
|
349
|
{
|
350
|
350
|
$test = new API($this);
|
351
|
351
|
$test->get('/posts?include=categories,tags,comments&filter=id,eq,1&transform=1');
|
352
|
|
- $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"}]}');
|
|
352
|
+ $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"}]}');
|
353
|
353
|
}
|
354
|
354
|
|
355
|
355
|
public function testEditCategoryWithBinaryContent()
|
|
@@ -360,7 +360,7 @@ class PHP_CRUD_API_Test extends PHPUnit_Framework_TestCase
|
360
|
360
|
$test->put('/categories/2','{"icon":"'.$base64url.'"}');
|
361
|
361
|
$test->expect('1');
|
362
|
362
|
$test->get('/categories/2');
|
363
|
|
- $test->expect('{"id":"2","name":"article","icon":"'.$binary.'"}');
|
|
363
|
+ $test->expect('{"id":2,"name":"article","icon":"'.$binary.'"}');
|
364
|
364
|
}
|
365
|
365
|
|
366
|
366
|
public function testEditCategoryWithNull()
|
|
@@ -369,7 +369,7 @@ class PHP_CRUD_API_Test extends PHPUnit_Framework_TestCase
|
369
|
369
|
$test->put('/categories/2','{"icon":null}');
|
370
|
370
|
$test->expect('1');
|
371
|
371
|
$test->get('/categories/2');
|
372
|
|
- $test->expect('{"id":"2","name":"article","icon":null}');
|
|
372
|
+ $test->expect('{"id":2,"name":"article","icon":null}');
|
373
|
373
|
}
|
374
|
374
|
|
375
|
375
|
public function testEditCategoryWithBinaryContentWithPost()
|
|
@@ -380,14 +380,14 @@ class PHP_CRUD_API_Test extends PHPUnit_Framework_TestCase
|
380
|
380
|
$test->put('/categories/2','icon='.$base64url);
|
381
|
381
|
$test->expect('1');
|
382
|
382
|
$test->get('/categories/2');
|
383
|
|
- $test->expect('{"id":"2","name":"article","icon":"'.$binary.'"}');
|
|
383
|
+ $test->expect('{"id":2,"name":"article","icon":"'.$binary.'"}');
|
384
|
384
|
}
|
385
|
385
|
|
386
|
386
|
public function testListCategoriesWithBinaryContent()
|
387
|
387
|
{
|
388
|
388
|
$test = new API($this);
|
389
|
389
|
$test->get('/categories');
|
390
|
|
- $test->expect('{"categories":{"columns":["id","name","icon"],"records":[["1","announcement",null],["2","article","4oKsIABhYmMACg1cYgA="]]}}');
|
|
390
|
+ $test->expect('{"categories":{"columns":["id","name","icon"],"records":[[1,"announcement",null],[2,"article","4oKsIABhYmMACg1cYgA="]]}}');
|
391
|
391
|
}
|
392
|
392
|
|
393
|
393
|
public function testEditCategoryWithNullWithPost()
|
|
@@ -396,13 +396,13 @@ class PHP_CRUD_API_Test extends PHPUnit_Framework_TestCase
|
396
|
396
|
$test->put('/categories/2','icon__is_null');
|
397
|
397
|
$test->expect('1');
|
398
|
398
|
$test->get('/categories/2');
|
399
|
|
- $test->expect('{"id":"2","name":"article","icon":null}');
|
|
399
|
+ $test->expect('{"id":2,"name":"article","icon":null}');
|
400
|
400
|
}
|
401
|
401
|
|
402
|
402
|
public function testAddPostFailure()
|
403
|
403
|
{
|
404
|
404
|
$test = new API($this);
|
405
|
|
- $test->post('/posts','{"user_id":"a","category_id":"1","content":"tests"}');
|
|
405
|
+ $test->post('/posts','{"user_id":"a","category_id":1,"content":"tests"}');
|
406
|
406
|
$test->expect('null');
|
407
|
407
|
}
|
408
|
408
|
|
|
@@ -417,7 +417,7 @@ class PHP_CRUD_API_Test extends PHPUnit_Framework_TestCase
|
417
|
417
|
{
|
418
|
418
|
$test = new API($this);
|
419
|
419
|
$test->get('/users?filter=id,eq,1&transform=1');
|
420
|
|
- $test->expect('{"users":[{"id":"1","username":"user1","location":null}]}');
|
|
420
|
+ $test->expect('{"users":[{"id":1,"username":"user1","location":null}]}');
|
421
|
421
|
}
|
422
|
422
|
|
423
|
423
|
public function testValidatorErrorMessage()
|
|
@@ -433,7 +433,7 @@ class PHP_CRUD_API_Test extends PHPUnit_Framework_TestCase
|
433
|
433
|
$test->put('/categories/2','{"name":"<script>alert();</script>"}');
|
434
|
434
|
$test->expect('1');
|
435
|
435
|
$test->get('/categories/2');
|
436
|
|
- $test->expect('{"id":"2","name":"alert();","icon":null}');
|
|
436
|
+ $test->expect('{"id":2,"name":"alert();","icon":null}');
|
437
|
437
|
}
|
438
|
438
|
|
439
|
439
|
public function testErrorOnInvalidJson()
|
|
@@ -446,14 +446,14 @@ class PHP_CRUD_API_Test extends PHPUnit_Framework_TestCase
|
446
|
446
|
public function testErrorOnDuplicatePrimaryKey()
|
447
|
447
|
{
|
448
|
448
|
$test = new API($this);
|
449
|
|
- $test->post('/posts','{"id":"1","user_id":"1","category_id":"1","content":"blog started (duplicate)"}');
|
|
449
|
+ $test->post('/posts','{"id":1,"user_id":1,"category_id":1,"content":"blog started (duplicate)"}');
|
450
|
450
|
$test->expect('null');
|
451
|
451
|
}
|
452
|
452
|
|
453
|
453
|
public function testErrorOnFailingForeignKeyConstraint()
|
454
|
454
|
{
|
455
|
455
|
$test = new API($this);
|
456
|
|
- $test->post('/posts','{"user_id":"3","category_id":"1","content":"fk constraint"}');
|
|
456
|
+ $test->post('/posts','{"user_id":3,"category_id":1,"content":"fk constraint"}');
|
457
|
457
|
$test->expect('null');
|
458
|
458
|
}
|
459
|
459
|
|
|
@@ -461,7 +461,7 @@ class PHP_CRUD_API_Test extends PHPUnit_Framework_TestCase
|
461
|
461
|
{
|
462
|
462
|
$test = new API($this);
|
463
|
463
|
$test->get('/users?include=posts,tags');
|
464
|
|
- $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"]]}}');
|
|
464
|
+ $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"]]}}');
|
465
|
465
|
}
|
466
|
466
|
|
467
|
467
|
public function testEditUserPassword()
|
|
@@ -478,9 +478,9 @@ class PHP_CRUD_API_Test extends PHPUnit_Framework_TestCase
|
478
|
478
|
$test->expect('1');
|
479
|
479
|
$test->get('/users/1?columns=id,location');
|
480
|
480
|
if (PHP_CRUD_API_Config::$dbengine=='SQLServer') {
|
481
|
|
- $test->expect('{"id":"1","location":"POINT (30 20)"}');
|
|
481
|
+ $test->expect('{"id":1,"location":"POINT (30 20)"}');
|
482
|
482
|
} else {
|
483
|
|
- $test->expect('{"id":"1","location":"POINT(30 20)"}');
|
|
483
|
+ $test->expect('{"id":1,"location":"POINT(30 20)"}');
|
484
|
484
|
}
|
485
|
485
|
}
|
486
|
486
|
|
|
@@ -489,9 +489,9 @@ class PHP_CRUD_API_Test extends PHPUnit_Framework_TestCase
|
489
|
489
|
$test = new API($this);
|
490
|
490
|
$test->get('/users?columns=id,location');
|
491
|
491
|
if (PHP_CRUD_API_Config::$dbengine=='SQLServer') {
|
492
|
|
- $test->expect('{"users":{"columns":["id","location"],"records":[["1","POINT (30 20)"]]}}');
|
|
492
|
+ $test->expect('{"users":{"columns":["id","location"],"records":[[1,"POINT (30 20)"]]}}');
|
493
|
493
|
} else {
|
494
|
|
- $test->expect('{"users":{"columns":["id","location"],"records":[["1","POINT(30 20)"]]}}');
|
|
494
|
+ $test->expect('{"users":{"columns":["id","location"],"records":[[1,"POINT(30 20)"]]}}');
|
495
|
495
|
}
|
496
|
496
|
}
|
497
|
497
|
|
|
@@ -499,10 +499,10 @@ class PHP_CRUD_API_Test extends PHPUnit_Framework_TestCase
|
499
|
499
|
{
|
500
|
500
|
if (PHP_CRUD_API_Config::$dbengine!='SQLServer') {
|
501
|
501
|
$test = new API($this);
|
502
|
|
- $test->put('/users/1','{"id":"2","password":"testtest2"}');
|
|
502
|
+ $test->put('/users/1','{"id":2,"password":"testtest2"}');
|
503
|
503
|
$test->expect('1');
|
504
|
504
|
$test->get('/users/1?columns=id,username,password');
|
505
|
|
- $test->expect('{"id":"1","username":"user1","password":"testtest2"}');
|
|
505
|
+ $test->expect('{"id":1,"username":"user1","password":"testtest2"}');
|
506
|
506
|
}
|
507
|
507
|
}
|
508
|
508
|
|
|
@@ -524,7 +524,7 @@ class PHP_CRUD_API_Test extends PHPUnit_Framework_TestCase
|
524
|
524
|
{
|
525
|
525
|
$test = new API($this);
|
526
|
526
|
$test->get('/categories?filter[]=icon,is,null&transform=1');
|
527
|
|
- $test->expect('{"categories":[{"id":"1","name":"announcement","icon":null},{"id":"2","name":"alert();","icon":null}]}');
|
|
527
|
+ $test->expect('{"categories":[{"id":1,"name":"announcement","icon":null},{"id":2,"name":"alert();","icon":null}]}');
|
528
|
528
|
}
|
529
|
529
|
|
530
|
530
|
public function testFilterCategoryOnNotNullIcon()
|
|
@@ -538,21 +538,21 @@ class PHP_CRUD_API_Test extends PHPUnit_Framework_TestCase
|
538
|
538
|
{
|
539
|
539
|
$test = new API($this);
|
540
|
540
|
$test->get('/posts?filter[]=id,nin,1,2,3,4,7,8,9,10,11,12,13,14&transform=1');
|
541
|
|
- $test->expect('{"posts":[{"id":"5","user_id":"1","category_id":"1","content":"#1"},{"id":"6","user_id":"1","category_id":"1","content":"#2"}]}');
|
|
541
|
+ $test->expect('{"posts":[{"id":5,"user_id":1,"category_id":1,"content":"#1"},{"id":6,"user_id":1,"category_id":1,"content":"#2"}]}');
|
542
|
542
|
}
|
543
|
543
|
|
544
|
544
|
public function testFilterPostsBetween()
|
545
|
545
|
{
|
546
|
546
|
$test = new API($this);
|
547
|
547
|
$test->get('/posts?filter[]=id,bt,5,6&transform=1');
|
548
|
|
- $test->expect('{"posts":[{"id":"5","user_id":"1","category_id":"1","content":"#1"},{"id":"6","user_id":"1","category_id":"1","content":"#2"}]}');
|
|
548
|
+ $test->expect('{"posts":[{"id":5,"user_id":1,"category_id":1,"content":"#1"},{"id":6,"user_id":1,"category_id":1,"content":"#2"}]}');
|
549
|
549
|
}
|
550
|
550
|
|
551
|
551
|
public function testFilterPostsNotBetween()
|
552
|
552
|
{
|
553
|
553
|
$test = new API($this);
|
554
|
554
|
$test->get('/posts?filter[]=id,nbt,2,13&transform=1');
|
555
|
|
- $test->expect('{"posts":[{"id":"1","user_id":"1","category_id":"1","content":"blog started"},{"id":"14","user_id":"1","category_id":"1","content":"#10"}]}');
|
|
555
|
+ $test->expect('{"posts":[{"id":1,"user_id":1,"category_id":1,"content":"blog started"},{"id":14,"user_id":1,"category_id":1,"content":"#10"}]}');
|
556
|
556
|
}
|
557
|
557
|
|
558
|
558
|
public function testColumnsWithTable()
|
|
@@ -566,42 +566,42 @@ class PHP_CRUD_API_Test extends PHPUnit_Framework_TestCase
|
566
|
566
|
{
|
567
|
567
|
$test = new API($this);
|
568
|
568
|
$test->get('/posts?columns=posts.*&filter=id,eq,1&transform=1');
|
569
|
|
- $test->expect('{"posts":[{"id":"1","user_id":"1","category_id":"1","content":"blog started"}]}');
|
|
569
|
+ $test->expect('{"posts":[{"id":1,"user_id":1,"category_id":1,"content":"blog started"}]}');
|
570
|
570
|
}
|
571
|
571
|
|
572
|
572
|
public function testColumnsOnInclude()
|
573
|
573
|
{
|
574
|
574
|
$test = new API($this);
|
575
|
575
|
$test->get('/posts?include=categories&columns=categories.name&filter=id,eq,1&transform=1');
|
576
|
|
- $test->expect('{"posts":[{"category_id":"1","categories":[{"id":"1","name":"announcement"}]}]}');
|
|
576
|
+ $test->expect('{"posts":[{"category_id":1,"categories":[{"id":1,"name":"announcement"}]}]}');
|
577
|
577
|
}
|
578
|
578
|
|
579
|
579
|
public function testFilterOnRelationAnd()
|
580
|
580
|
{
|
581
|
581
|
$test = new API($this);
|
582
|
582
|
$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');
|
583
|
|
- $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"]]}}');
|
|
583
|
+ $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"]]}}');
|
584
|
584
|
}
|
585
|
585
|
|
586
|
586
|
public function testFilterOnRelationOr()
|
587
|
587
|
{
|
588
|
588
|
$test = new API($this);
|
589
|
589
|
$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');
|
590
|
|
- $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"]]}}');
|
|
590
|
+ $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"]]}}');
|
591
|
591
|
}
|
592
|
592
|
|
593
|
593
|
public function testColumnsOnWrongInclude()
|
594
|
594
|
{
|
595
|
595
|
$test = new API($this);
|
596
|
596
|
$test->get('/posts?include=categories&columns=categories&filter=id,eq,1&transform=1');
|
597
|
|
- $test->expect('{"posts":[{"category_id":"1","categories":[{"id":"1"}]}]}');
|
|
597
|
+ $test->expect('{"posts":[{"category_id":1,"categories":[{"id":1}]}]}');
|
598
|
598
|
}
|
599
|
599
|
|
600
|
600
|
public function testColumnsOnImplicitJoin()
|
601
|
601
|
{
|
602
|
602
|
$test = new API($this);
|
603
|
603
|
$test->get('/posts?include=tags&columns=posts.id,tags.name&filter=id,eq,1&transform=1');
|
604
|
|
- $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"}]}]}]}');
|
|
604
|
+ $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"}]}]}]}');
|
605
|
605
|
}
|
606
|
606
|
|
607
|
607
|
public function testSpatialFilterWithin()
|
|
@@ -609,14 +609,14 @@ class PHP_CRUD_API_Test extends PHPUnit_Framework_TestCase
|
609
|
609
|
if (PHP_CRUD_API_Config::$dbengine!='SQLite') {
|
610
|
610
|
$test = new API($this);
|
611
|
611
|
$test->get('/users?columns=id,username&filter=location,swi,POINT(30 20)');
|
612
|
|
- $test->expect('{"users":{"columns":["id","username"],"records":[["1","user1"]]}}');
|
|
612
|
+ $test->expect('{"users":{"columns":["id","username"],"records":[[1,"user1"]]}}');
|
613
|
613
|
}
|
614
|
614
|
}
|
615
|
615
|
|
616
|
616
|
public function testAddPostsWithNonExistingCategory()
|
617
|
617
|
{
|
618
|
618
|
$test = new API($this);
|
619
|
|
- $test->post('/posts','[{"user_id":"1","category_id":"1","content":"tests"},{"user_id":"1","category_id":"15","content":"tests"}]');
|
|
619
|
+ $test->post('/posts','[{"user_id":1,"category_id":1,"content":"tests"},{"user_id":1,"category_id":15,"content":"tests"}]');
|
620
|
620
|
$test->expect('null');
|
621
|
621
|
$test->get('/posts?columns=content&filter=content,eq,tests');
|
622
|
622
|
$test->expect('{"posts":{"columns":["content"],"records":[]}}');
|
|
@@ -625,7 +625,7 @@ class PHP_CRUD_API_Test extends PHPUnit_Framework_TestCase
|
625
|
625
|
public function testAddPosts()
|
626
|
626
|
{
|
627
|
627
|
$test = new API($this);
|
628
|
|
- $test->post('/posts','[{"user_id":"1","category_id":"1","content":"tests"},{"user_id":"1","category_id":"1","content":"tests"}]');
|
|
628
|
+ $test->post('/posts','[{"user_id":1,"category_id":1,"content":"tests"},{"user_id":1,"category_id":1,"content":"tests"}]');
|
629
|
629
|
$test->expectAny();
|
630
|
630
|
$test->get('/posts?columns=content&filter=content,eq,tests');
|
631
|
631
|
$test->expect('{"posts":{"columns":["content"],"records":[["tests"],["tests"]]}}');
|
|
@@ -642,14 +642,14 @@ class PHP_CRUD_API_Test extends PHPUnit_Framework_TestCase
|
642
|
642
|
{
|
643
|
643
|
$test = new API($this);
|
644
|
644
|
$test->get('/tag_usage');
|
645
|
|
- $test->expect('{"tag_usage":{"columns":["name","count"],"records":[["funny","2"],["important","2"]]}}');
|
|
645
|
+ $test->expect('{"tag_usage":{"columns":["name","count"],"records":[["funny",2],["important",2]]}}');
|
646
|
646
|
}
|
647
|
647
|
|
648
|
648
|
public function testUpdateMultipleTags()
|
649
|
649
|
{
|
650
|
650
|
$test = new API($this);
|
651
|
651
|
$test->get('/tags?transform=1');
|
652
|
|
- $test->expect('{"tags":[{"id":"1","name":"funny"},{"id":"2","name":"important"}]}');
|
|
652
|
+ $test->expect('{"tags":[{"id":1,"name":"funny"},{"id":2,"name":"important"}]}');
|
653
|
653
|
$test->put('/tags/1,2','[{"name":"funny"},{"name":"important"}]');
|
654
|
654
|
$test->expect('[1,1]');
|
655
|
655
|
}
|
|
@@ -660,7 +660,7 @@ class PHP_CRUD_API_Test extends PHPUnit_Framework_TestCase
|
660
|
660
|
$test->put('/tags/1,2,3','[{"name":"funny!!!"},{"name":"important"}]');
|
661
|
661
|
$test->expect(false,'Not found (subject)');
|
662
|
662
|
$test->get('/tags?transform=1');
|
663
|
|
- $test->expect('{"tags":[{"id":"1","name":"funny"},{"id":"2","name":"important"}]}');
|
|
663
|
+ $test->expect('{"tags":[{"id":1,"name":"funny"},{"id":2,"name":"important"}]}');
|
664
|
664
|
}
|
665
|
665
|
|
666
|
666
|
public function testUpdateMultipleTagsWithoutFields()
|
|
@@ -669,7 +669,7 @@ class PHP_CRUD_API_Test extends PHPUnit_Framework_TestCase
|
669
|
669
|
$test->put('/tags/1,2','[{"name":"funny!!!"},{}]');
|
670
|
670
|
$test->expect('null');
|
671
|
671
|
$test->get('/tags?transform=1');
|
672
|
|
- $test->expect('{"tags":[{"id":"1","name":"funny"},{"id":"2","name":"important"}]}');
|
|
672
|
+ $test->expect('{"tags":[{"id":1,"name":"funny"},{"id":2,"name":"important"}]}');
|
673
|
673
|
}
|
674
|
674
|
|
675
|
675
|
public function testDeleteMultipleTags()
|
|
@@ -680,6 +680,13 @@ class PHP_CRUD_API_Test extends PHPUnit_Framework_TestCase
|
680
|
680
|
$test->delete('/tags/3,4');
|
681
|
681
|
$test->expect('[1,1]');
|
682
|
682
|
$test->get('/tags?transform=1');
|
683
|
|
- $test->expect('{"tags":[{"id":"1","name":"funny"},{"id":"2","name":"important"}]}');
|
|
683
|
+ $test->expect('{"tags":[{"id":1,"name":"funny"},{"id":2,"name":"important"}]}');
|
|
684
|
+ }
|
|
685
|
+
|
|
686
|
+ public function testListProducts()
|
|
687
|
+ {
|
|
688
|
+ $test = new API($this);
|
|
689
|
+ $test->get('/products?transform=1');
|
|
690
|
+ $test->expect('{"products":[{"id":1,"name":"Calculator","price":"23.01"}]}');
|
684
|
691
|
}
|
685
|
692
|
}
|