Browse Source

Improve float and integer handling

Maurits van der Schee 7 years ago
parent
commit
8616b6795b
7 changed files with 174 additions and 82 deletions
  1. 39
    27
      api.php
  2. BIN
      data/blog.db
  3. 11
    0
      tests/blog_mysql.sql
  4. 27
    0
      tests/blog_postgresql.sql
  5. 9
    0
      tests/blog_sqlite.sql
  6. 26
    0
      tests/blog_sqlserver.sql
  7. 62
    55
      tests/tests.php

+ 39
- 27
api.php View File

5
 	public function getSql($name);
5
 	public function getSql($name);
6
 	public function connect($hostname,$username,$password,$database,$port,$socket,$charset);
6
 	public function connect($hostname,$username,$password,$database,$port,$socket,$charset);
7
 	public function query($sql,$params=array());
7
 	public function query($sql,$params=array());
8
-	public function fetchAssoc($result);
9
-	public function fetchRow($result);
8
+	public function fetchAssoc($result,$fields=false);
9
+	public function fetchRow($result,$fields=false);
10
 	public function insertId($result);
10
 	public function insertId($result);
11
 	public function affectedRows($result);
11
 	public function affectedRows($result);
12
 	public function close($result);
12
 	public function close($result);
104
 		if (!mysqli_query($db,'SET SESSION sql_mode = \'ANSI_QUOTES\';')) {
104
 		if (!mysqli_query($db,'SET SESSION sql_mode = \'ANSI_QUOTES\';')) {
105
 			throw new \Exception('Error setting ANSI quotes. '.mysqli_error($db));
105
 			throw new \Exception('Error setting ANSI quotes. '.mysqli_error($db));
106
 		}
106
 		}
107
+		if (!mysqli_options($db,MYSQLI_OPT_INT_AND_FLOAT_NATIVE,true)) {
108
+			throw new \Exception('Error setting int and float native. '.mysqli_error($db));
109
+		}
107
 		$this->db = $db;
110
 		$this->db = $db;
108
 	}
111
 	}
109
 
112
 
138
 		return mysqli_query($db,$sql);
141
 		return mysqli_query($db,$sql);
139
 	}
142
 	}
140
 
143
 
141
-	public function fetchAssoc($result) {
144
+	public function fetchAssoc($result,$fields=false) {
142
 		return mysqli_fetch_assoc($result);
145
 		return mysqli_fetch_assoc($result);
143
 	}
146
 	}
144
 
147
 
145
-	public function fetchRow($result) {
148
+	public function fetchRow($result,$fields=false) {
146
 		return mysqli_fetch_row($result);
149
 		return mysqli_fetch_row($result);
147
 	}
150
 	}
148
 
151
 
365
 		return @pg_query($db,$sql);
368
 		return @pg_query($db,$sql);
366
 	}
369
 	}
367
 
370
 
368
-	public function fetchAssoc($result) {
369
-		return pg_fetch_assoc($result);
371
+	protected function convertFloatAndInt($result,&$values, $fields) {
372
+		array_walk($values, function(&$v,$i) use ($result,$fields){
373
+			$t = $fields[$i]->type;
374
+			if (is_string($v) && in_array($t,array('int2','int4','int8','float4','float8'))) {
375
+				$v+=0;
376
+			}
377
+		});
370
 	}
378
 	}
371
 
379
 
372
-	public function fetchRow($result) {
373
-		return pg_fetch_row($result);
380
+	public function fetchAssoc($result,$fields=false) {
381
+		$values = pg_fetch_assoc($result);
382
+		if ($values && $fields) {
383
+			$this->convertFloatAndInt($result,$values,$fields);
384
+		}
385
+		return $values;
386
+	}
387
+
388
+	public function fetchRow($result,$fields=false) {
389
+		$values = pg_fetch_row($result);
390
+		if ($values && $fields) {
391
+			$this->convertFloatAndInt($result,$values,array_values($fields));
392
+		}
393
+		return $values;
374
 	}
394
 	}
375
 
395
 
376
 	public function insertId($result) {
396
 	public function insertId($result) {
591
 		return sqlsrv_query($db,$sql,$args)?:null;
611
 		return sqlsrv_query($db,$sql,$args)?:null;
592
 	}
612
 	}
593
 
613
 
594
-	public function fetchAssoc($result) {
595
-		$values = sqlsrv_fetch_array($result, SQLSRV_FETCH_ASSOC);
596
-		if ($values) $values = array_map(function($v){ return is_null($v)?null:(string)$v; },$values);
597
-		return $values;
614
+	public function fetchAssoc($result,$fields=false) {
615
+		return sqlsrv_fetch_array($result, SQLSRV_FETCH_ASSOC);
598
 	}
616
 	}
599
 
617
 
600
-	public function fetchRow($result) {
601
-		$values = sqlsrv_fetch_array($result, SQLSRV_FETCH_NUMERIC);
602
-		if ($values) $values = array_map(function($v){ return is_null($v)?null:(string)$v; },$values);
603
-		return $values;
618
+	public function fetchRow($result,$fields=false) {
619
+		return sqlsrv_fetch_array($result, SQLSRV_FETCH_NUMERIC);
604
 	}
620
 	}
605
 
621
 
606
 	public function insertId($result) {
622
 	public function insertId($result) {
832
 		return $result;
848
 		return $result;
833
 	}
849
 	}
834
 
850
 
835
-	public function fetchAssoc($result) {
836
-		$values = $result->fetchArray(SQLITE3_ASSOC);
837
-		if ($values) $values = array_map(function($v){ return is_null($v)?null:(string)$v; },$values);
838
-		return $values;
851
+	public function fetchAssoc($result,$fields=false) {
852
+		return $result->fetchArray(SQLITE3_ASSOC);
839
 	}
853
 	}
840
 
854
 
841
-	public function fetchRow($result) {
842
-		$values = $result->fetchArray(SQLITE3_NUM);
843
-		if ($values) $values = array_map(function($v){ return is_null($v)?null:(string)$v; },$values);
844
-		return $values;
855
+	public function fetchRow($result,$fields=false) {
856
+		return $result->fetchArray(SQLITE3_NUM);
845
 	}
857
 	}
846
 
858
 
847
 	public function insertId($result) {
859
 	public function insertId($result) {
1240
 		$this->addWhereFromFilters($filters[$table],$sql,$params);
1252
 		$this->addWhereFromFilters($filters[$table],$sql,$params);
1241
 		$object = null;
1253
 		$object = null;
1242
 		if ($result = $this->db->query($sql,$params)) {
1254
 		if ($result = $this->db->query($sql,$params)) {
1243
-			$object = $this->db->fetchAssoc($result);
1255
+			$object = $this->db->fetchAssoc($result,$fields[$table]);
1244
 			$this->db->close($result);
1256
 			$this->db->close($result);
1245
 		}
1257
 		}
1246
 		return $object;
1258
 		return $object;
1625
 			$keys = array_flip($keys);
1637
 			$keys = array_flip($keys);
1626
 			echo ',"records":[';
1638
 			echo ',"records":[';
1627
 			$first_row = true;
1639
 			$first_row = true;
1628
-			while ($row = $this->db->fetchRow($result)) {
1640
+			while ($row = $this->db->fetchRow($result,$fields[$table])) {
1629
 				if ($first_row) $first_row = false;
1641
 				if ($first_row) $first_row = false;
1630
 				else echo ',';
1642
 				else echo ',';
1631
 				if (isset($collect[$table])) {
1643
 				if (isset($collect[$table])) {
1675
 				$keys = array_flip($keys);
1687
 				$keys = array_flip($keys);
1676
 				echo ',"records":[';
1688
 				echo ',"records":[';
1677
 				$first_row = true;
1689
 				$first_row = true;
1678
-				while ($row = $this->db->fetchRow($result)) {
1690
+				while ($row = $this->db->fetchRow($result,$fields[$table])) {
1679
 					if ($first_row) $first_row = false;
1691
 					if ($first_row) $first_row = false;
1680
 					else echo ',';
1692
 					else echo ',';
1681
 					if (isset($collect[$table])) {
1693
 					if (isset($collect[$table])) {

BIN
data/blog.db View File


+ 11
- 0
tests/blog_mysql.sql View File

118
 DROP VIEW IF EXISTS `tag_usage`;
118
 DROP VIEW IF EXISTS `tag_usage`;
119
 CREATE VIEW `tag_usage` AS select `name`, count(`name`) AS `count` from `tags`, `post_tags` where `tags`.`id` = `post_tags`.`tag_id` group by `name` order by `count` desc, `name`;
119
 CREATE VIEW `tag_usage` AS select `name`, count(`name`) AS `count` from `tags`, `post_tags` where `tags`.`id` = `post_tags`.`tag_id` group by `name` order by `count` desc, `name`;
120
 
120
 
121
+DROP TABLE IF EXISTS `products`;
122
+CREATE TABLE `products` (
123
+  `id` int(11) NOT NULL AUTO_INCREMENT,
124
+  `name` varchar(255) NOT NULL,
125
+  `price` decimal(10,2) NOT NULL,
126
+  PRIMARY KEY (`id`)
127
+) ENGINE=InnoDB DEFAULT CHARSET=utf8;
128
+
129
+INSERT INTO `products` (`id`, `name`, `price`) VALUES
130
+(1,	'Calculator', '23.01');
131
+
121
 -- 2016-11-05 13:11:47
132
 -- 2016-11-05 13:11:47

+ 27
- 0
tests/blog_postgresql.sql View File

28
 DROP TABLE IF EXISTS countries CASCADE;
28
 DROP TABLE IF EXISTS countries CASCADE;
29
 DROP TABLE IF EXISTS events CASCADE;
29
 DROP TABLE IF EXISTS events CASCADE;
30
 DROP VIEW IF EXISTS tag_usage;
30
 DROP VIEW IF EXISTS tag_usage;
31
+DROP TABLE IF EXISTS products CASCADE;
32
+
31
 --
33
 --
32
 -- Name: categories; Type: TABLE; Schema: public; Owner: postgres; Tablespace:
34
 -- Name: categories; Type: TABLE; Schema: public; Owner: postgres; Tablespace:
33
 --
35
 --
120
 
122
 
121
 CREATE VIEW "tag_usage" AS select "name", count("name") AS "count" from "tags", "post_tags" where "tags"."id" = "post_tags"."tag_id" group by "name" order by "count" desc, "name";
123
 CREATE VIEW "tag_usage" AS select "name", count("name") AS "count" from "tags", "post_tags" where "tags"."id" = "post_tags"."tag_id" group by "name" order by "count" desc, "name";
122
 
124
 
125
+--
126
+-- Name: products; Type: TABLE; Schema: public; Owner: postgres; Tablespace:
127
+--
128
+
129
+CREATE TABLE products (
130
+    id serial NOT NULL,
131
+    name character varying(255) NOT NULL,
132
+    price decimal(10,2) NOT NULL
133
+);
134
+
123
 --
135
 --
124
 -- Data for Name: categories; Type: TABLE DATA; Schema: public; Owner: postgres
136
 -- Data for Name: categories; Type: TABLE DATA; Schema: public; Owner: postgres
125
 --
137
 --
187
 INSERT INTO "events" ("name", "datetime") VALUES
199
 INSERT INTO "events" ("name", "datetime") VALUES
188
 ('Launch',	'2016-01-01 13:01:01.111');
200
 ('Launch',	'2016-01-01 13:01:01.111');
189
 
201
 
202
+--
203
+-- Data for Name: events; Type: TABLE DATA; Schema: public; Owner: postgres
204
+--
205
+
206
+INSERT INTO "products" ("name", "price") VALUES
207
+('Calculator',	'23.01');
208
+
190
 --
209
 --
191
 -- Name: categories_pkey; Type: CONSTRAINT; Schema: public; Owner: postgres; Tablespace:
210
 -- Name: categories_pkey; Type: CONSTRAINT; Schema: public; Owner: postgres; Tablespace:
192
 --
211
 --
258
     ADD CONSTRAINT events_pkey PRIMARY KEY (id);
277
     ADD CONSTRAINT events_pkey PRIMARY KEY (id);
259
 
278
 
260
 
279
 
280
+--
281
+-- Name: products_pkey; Type: CONSTRAINT; Schema: public; Owner: postgres; Tablespace:
282
+--
283
+
284
+ALTER TABLE ONLY products
285
+    ADD CONSTRAINT products_pkey PRIMARY KEY (id);
286
+
287
+
261
 --
288
 --
262
 -- Name: comments_post_id_idx; Type: INDEX; Schema: public; Owner: postgres; Tablespace:
289
 -- Name: comments_post_id_idx; Type: INDEX; Schema: public; Owner: postgres; Tablespace:
263
 --
290
 --

+ 9
- 0
tests/blog_sqlite.sql View File

100
 DROP VIEW IF EXISTS `tag_usage`;
100
 DROP VIEW IF EXISTS `tag_usage`;
101
 CREATE VIEW `tag_usage` AS select `name`, count(`name`) AS `count` from `tags`, `post_tags` where `tags`.`id` = `post_tags`.`tag_id` group by `name` order by `count` desc, `name`;
101
 CREATE VIEW `tag_usage` AS select `name`, count(`name`) AS `count` from `tags`, `post_tags` where `tags`.`id` = `post_tags`.`tag_id` group by `name` order by `count` desc, `name`;
102
 
102
 
103
+DROP TABLE IF EXISTS `products`;
104
+CREATE TABLE `products` (
105
+  `id` integer NOT NULL PRIMARY KEY AUTOINCREMENT,
106
+  `name` text(255) NOT NULL,
107
+  `price` text(12) NOT NULL
108
+);
109
+
110
+INSERT INTO `products` (`id`, `name`, `price`) VALUES (1,	'Calculator', '23.01');
111
+
103
 --
112
 --

+ 26
- 0
tests/blog_sqlserver.sql View File

23
 ALTER TABLE [comments] DROP CONSTRAINT [FK_comments_posts]
23
 ALTER TABLE [comments] DROP CONSTRAINT [FK_comments_posts]
24
 END
24
 END
25
 GO
25
 GO
26
+IF (OBJECT_ID('products', 'U') IS NOT NULL)
27
+BEGIN
28
+DROP TABLE [products]
29
+END
30
+GO
26
 IF (OBJECT_ID('events', 'U') IS NOT NULL)
31
 IF (OBJECT_ID('events', 'U') IS NOT NULL)
27
 BEGIN
32
 BEGIN
28
 DROP TABLE [events]
33
 DROP TABLE [events]
193
 AS
198
 AS
194
 SELECT top 100 PERCENT name, COUNT(name) AS [count] FROM tags, post_tags WHERE tags.id = post_tags.tag_id GROUP BY name ORDER BY [count] DESC, name
199
 SELECT top 100 PERCENT name, COUNT(name) AS [count] FROM tags, post_tags WHERE tags.id = post_tags.tag_id GROUP BY name ORDER BY [count] DESC, name
195
 
200
 
201
+GO
202
+SET ANSI_NULLS ON
203
+GO
204
+SET QUOTED_IDENTIFIER ON
205
+GO
206
+CREATE TABLE [products](
207
+	[id] [int] IDENTITY,
208
+	[name] [nvarchar](max) NOT NULL,
209
+	[price] [decimal](10,2) NOT NULL,
210
+ CONSTRAINT [PK_products] PRIMARY KEY CLUSTERED
211
+(
212
+	[id] ASC
213
+)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
214
+) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]
215
+
196
 GO
216
 GO
197
 SET IDENTITY_INSERT [categories] ON
217
 SET IDENTITY_INSERT [categories] ON
198
 GO
218
 GO
264
 GO
284
 GO
265
 SET IDENTITY_INSERT [events] OFF
285
 SET IDENTITY_INSERT [events] OFF
266
 GO
286
 GO
287
+SET IDENTITY_INSERT [products] ON
288
+GO
289
+INSERT [products] ([id], [name], [price]) VALUES (1, N'Calculator', N'23.01')
290
+GO
291
+SET IDENTITY_INSERT [products] OFF
292
+GO
267
 ALTER TABLE [comments]  WITH CHECK ADD  CONSTRAINT [FK_comments_posts] FOREIGN KEY([post_id])
293
 ALTER TABLE [comments]  WITH CHECK ADD  CONSTRAINT [FK_comments_posts] FOREIGN KEY([post_id])
268
 REFERENCES [posts] ([id])
294
 REFERENCES [posts] ([id])
269
 GO
295
 GO

+ 62
- 55
tests/tests.php View File

192
 	{
192
 	{
193
 		$test = new API($this);
193
 		$test = new API($this);
194
 		$test->get('/posts');
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
 	public function testListPostColumns()
198
 	public function testListPostColumns()
199
 	{
199
 	{
200
 		$test = new API($this);
200
 		$test = new API($this);
201
 		$test->get('/posts?columns=id,content');
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
 	public function testListPostsWithTransform()
205
 	public function testListPostsWithTransform()
206
 	{
206
 	{
207
 		$test = new API($this);
207
 		$test = new API($this);
208
 		$test->get('/posts?transform=1');
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
 	public function testReadPost()
212
 	public function testReadPost()
213
 	{
213
 	{
214
 		$test = new API($this);
214
 		$test = new API($this);
215
 		$test->get('/posts/2');
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
 	public function testReadPosts()
219
 	public function testReadPosts()
220
 	{
220
 	{
221
 		$test = new API($this);
221
 		$test = new API($this);
222
 		$test->get('/posts/1,2');
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
 	public function testReadPostColumns()
226
 	public function testReadPostColumns()
227
 	{
227
 	{
228
 		$test = new API($this);
228
 		$test = new API($this);
229
 		$test->get('/posts/2?columns=id,content');
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
 	public function testAddPost()
233
 	public function testAddPost()
234
 	{
234
 	{
235
 		$test = new API($this);
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
 		$test->expect('3');
237
 		$test->expect('3');
238
 	}
238
 	}
239
 
239
 
240
 	public function testEditPost()
240
 	public function testEditPost()
241
 	{
241
 	{
242
 		$test = new API($this);
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
 		$test->expect('1');
244
 		$test->expect('1');
245
 		$test->get('/posts/3');
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
 	public function testEditPostColumnsMissingField()
249
 	public function testEditPostColumnsMissingField()
252
 		$test->put('/posts/3?columns=id,content','{"content":"test (edited 2)"}');
252
 		$test->put('/posts/3?columns=id,content','{"content":"test (edited 2)"}');
253
 		$test->expect('1');
253
 		$test->expect('1');
254
 		$test->get('/posts/3');
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
     public function testEditPostColumnsExtraField()
258
     public function testEditPostColumnsExtraField()
259
 	{
259
 	{
260
 		$test = new API($this);
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
 		$test->expect('1');
262
 		$test->expect('1');
263
 		$test->get('/posts/3');
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
 	public function testEditPostWithUtf8Content()
267
 	public function testEditPostWithUtf8Content()
271
 		$test->put('/posts/2','{"content":'.$utf8.'}');
271
 		$test->put('/posts/2','{"content":'.$utf8.'}');
272
 		$test->expect('1');
272
 		$test->expect('1');
273
 		$test->get('/posts/2');
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
 	public function testEditPostWithUtf8ContentWithPost()
277
 	public function testEditPostWithUtf8ContentWithPost()
283
 		$test->put('/posts/2','content='.$url_encoded);
283
 		$test->put('/posts/2','content='.$url_encoded);
284
 		$test->expect('1');
284
 		$test->expect('1');
285
 		$test->get('/posts/2');
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
 	public function testDeletePost()
289
 	public function testDeletePost()
308
 		$test->put('/posts/4','user_id=1&category_id=1&content=test+(edited)');
308
 		$test->put('/posts/4','user_id=1&category_id=1&content=test+(edited)');
309
 		$test->expect('1');
309
 		$test->expect('1');
310
 		$test->get('/posts/4');
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
 	public function testDeletePostWithPost()
314
 	public function testDeletePostWithPost()
324
 	{
324
 	{
325
 		$test = new API($this);
325
 		$test = new API($this);
326
 		for ($i=1;$i<=10;$i++) {
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
 		  $test->expect(4+$i);
328
 		  $test->expect(4+$i);
329
 		}
329
 		}
330
 		$test->get('/posts?page=2,2&order=id');
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
 	public function testListWithPaginateLastPage()
334
 	public function testListWithPaginateLastPage()
335
 	{
335
 	{
336
 		$test = new API($this);
336
 		$test = new API($this);
337
 		$test->get('/posts?page=3,5&order=id');
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
 	public function testListExampleFromReadme()
341
 	public function testListExampleFromReadme()
342
 	{
342
 	{
343
 		$test = new API($this);
343
 		$test = new API($this);
344
 		$test->get('/posts?include=categories,tags,comments&filter=id,eq,1');
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
 	public function testListExampleFromReadmeWithTransform()
348
 	public function testListExampleFromReadmeWithTransform()
349
 	{
349
 	{
350
 		$test = new API($this);
350
 		$test = new API($this);
351
 		$test->get('/posts?include=categories,tags,comments&filter=id,eq,1&transform=1');
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
 	public function testEditCategoryWithBinaryContent()
355
 	public function testEditCategoryWithBinaryContent()
360
 		$test->put('/categories/2','{"icon":"'.$base64url.'"}');
360
 		$test->put('/categories/2','{"icon":"'.$base64url.'"}');
361
 		$test->expect('1');
361
 		$test->expect('1');
362
 		$test->get('/categories/2');
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
 	public function testEditCategoryWithNull()
366
 	public function testEditCategoryWithNull()
369
 		$test->put('/categories/2','{"icon":null}');
369
 		$test->put('/categories/2','{"icon":null}');
370
 		$test->expect('1');
370
 		$test->expect('1');
371
 		$test->get('/categories/2');
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
 	public function testEditCategoryWithBinaryContentWithPost()
375
 	public function testEditCategoryWithBinaryContentWithPost()
380
 		$test->put('/categories/2','icon='.$base64url);
380
 		$test->put('/categories/2','icon='.$base64url);
381
 		$test->expect('1');
381
 		$test->expect('1');
382
 		$test->get('/categories/2');
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
 	public function testListCategoriesWithBinaryContent()
386
 	public function testListCategoriesWithBinaryContent()
387
 	{
387
 	{
388
 		$test = new API($this);
388
 		$test = new API($this);
389
 		$test->get('/categories');
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
 	public function testEditCategoryWithNullWithPost()
393
 	public function testEditCategoryWithNullWithPost()
396
 		$test->put('/categories/2','icon__is_null');
396
 		$test->put('/categories/2','icon__is_null');
397
 		$test->expect('1');
397
 		$test->expect('1');
398
 		$test->get('/categories/2');
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
 	public function testAddPostFailure()
402
 	public function testAddPostFailure()
403
 	{
403
 	{
404
 		$test = new API($this);
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
 		$test->expect('null');
406
 		$test->expect('null');
407
 	}
407
 	}
408
 
408
 
417
 	{
417
 	{
418
 		$test = new API($this);
418
 		$test = new API($this);
419
 		$test->get('/users?filter=id,eq,1&transform=1');
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
 	public function testValidatorErrorMessage()
423
 	public function testValidatorErrorMessage()
433
 		$test->put('/categories/2','{"name":"<script>alert();</script>"}');
433
 		$test->put('/categories/2','{"name":"<script>alert();</script>"}');
434
 		$test->expect('1');
434
 		$test->expect('1');
435
 		$test->get('/categories/2');
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
 	public function testErrorOnInvalidJson()
439
 	public function testErrorOnInvalidJson()
446
 	public function testErrorOnDuplicatePrimaryKey()
446
 	public function testErrorOnDuplicatePrimaryKey()
447
 	{
447
 	{
448
 		$test = new API($this);
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
 		$test->expect('null');
450
 		$test->expect('null');
451
 	}
451
 	}
452
 
452
 
453
 	public function testErrorOnFailingForeignKeyConstraint()
453
 	public function testErrorOnFailingForeignKeyConstraint()
454
 	{
454
 	{
455
 		$test = new API($this);
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
 		$test->expect('null');
457
 		$test->expect('null');
458
 	}
458
 	}
459
 
459
 
461
 	{
461
 	{
462
 		$test = new API($this);
462
 		$test = new API($this);
463
 		$test->get('/users?include=posts,tags');
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
 	public function testEditUserPassword()
467
 	public function testEditUserPassword()
478
 		$test->expect('1');
478
 		$test->expect('1');
479
 		$test->get('/users/1?columns=id,location');
479
 		$test->get('/users/1?columns=id,location');
480
 		if (PHP_CRUD_API_Config::$dbengine=='SQLServer') {
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
 		} else {
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
 		$test = new API($this);
489
 		$test = new API($this);
490
 		$test->get('/users?columns=id,location');
490
 		$test->get('/users?columns=id,location');
491
 		if (PHP_CRUD_API_Config::$dbengine=='SQLServer') {
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
 		} else {
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
 	{
499
 	{
500
 		if (PHP_CRUD_API_Config::$dbengine!='SQLServer') {
500
 		if (PHP_CRUD_API_Config::$dbengine!='SQLServer') {
501
 			$test = new API($this);
501
 			$test = new API($this);
502
-			$test->put('/users/1','{"id":"2","password":"testtest2"}');
502
+			$test->put('/users/1','{"id":2,"password":"testtest2"}');
503
 			$test->expect('1');
503
 			$test->expect('1');
504
 			$test->get('/users/1?columns=id,username,password');
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
 	{
524
 	{
525
 		$test = new API($this);
525
 		$test = new API($this);
526
 		$test->get('/categories?filter[]=icon,is,null&transform=1');
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
 	public function testFilterCategoryOnNotNullIcon()
530
 	public function testFilterCategoryOnNotNullIcon()
538
 	{
538
 	{
539
 		$test = new API($this);
539
 		$test = new API($this);
540
 		$test->get('/posts?filter[]=id,nin,1,2,3,4,7,8,9,10,11,12,13,14&transform=1');
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
 	public function testFilterPostsBetween()
544
 	public function testFilterPostsBetween()
545
 	{
545
 	{
546
 		$test = new API($this);
546
 		$test = new API($this);
547
 		$test->get('/posts?filter[]=id,bt,5,6&transform=1');
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
 	public function testFilterPostsNotBetween()
551
 	public function testFilterPostsNotBetween()
552
 	{
552
 	{
553
 		$test = new API($this);
553
 		$test = new API($this);
554
 		$test->get('/posts?filter[]=id,nbt,2,13&transform=1');
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
 	public function testColumnsWithTable()
558
 	public function testColumnsWithTable()
566
 	{
566
 	{
567
 		$test = new API($this);
567
 		$test = new API($this);
568
 		$test->get('/posts?columns=posts.*&filter=id,eq,1&transform=1');
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
 	public function testColumnsOnInclude()
572
 	public function testColumnsOnInclude()
573
 	{
573
 	{
574
 		$test = new API($this);
574
 		$test = new API($this);
575
 		$test->get('/posts?include=categories&columns=categories.name&filter=id,eq,1&transform=1');
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
 	public function testFilterOnRelationAnd()
579
 	public function testFilterOnRelationAnd()
580
 	{
580
 	{
581
 		$test = new API($this);
581
 		$test = new API($this);
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');
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
 	public function testFilterOnRelationOr()
586
 	public function testFilterOnRelationOr()
587
 	{
587
 	{
588
 		$test = new API($this);
588
 		$test = new API($this);
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');
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
 	public function testColumnsOnWrongInclude()
593
 	public function testColumnsOnWrongInclude()
594
 	{
594
 	{
595
 		$test = new API($this);
595
 		$test = new API($this);
596
 		$test->get('/posts?include=categories&columns=categories&filter=id,eq,1&transform=1');
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
 	public function testColumnsOnImplicitJoin()
600
 	public function testColumnsOnImplicitJoin()
601
 	{
601
 	{
602
 		$test = new API($this);
602
 		$test = new API($this);
603
 		$test->get('/posts?include=tags&columns=posts.id,tags.name&filter=id,eq,1&transform=1');
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
 	public function testSpatialFilterWithin()
607
 	public function testSpatialFilterWithin()
609
 		if (PHP_CRUD_API_Config::$dbengine!='SQLite') {
609
 		if (PHP_CRUD_API_Config::$dbengine!='SQLite') {
610
 			$test = new API($this);
610
 			$test = new API($this);
611
 			$test->get('/users?columns=id,username&filter=location,swi,POINT(30 20)');
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
 	public function testAddPostsWithNonExistingCategory()
616
 	public function testAddPostsWithNonExistingCategory()
617
 	{ 
617
 	{ 
618
 		$test = new API($this);
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
 		$test->expect('null');
620
 		$test->expect('null');
621
 		$test->get('/posts?columns=content&filter=content,eq,tests');
621
 		$test->get('/posts?columns=content&filter=content,eq,tests');
622
 		$test->expect('{"posts":{"columns":["content"],"records":[]}}');
622
 		$test->expect('{"posts":{"columns":["content"],"records":[]}}');
625
 	public function testAddPosts()
625
 	public function testAddPosts()
626
 	{
626
 	{
627
 		$test = new API($this);
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
 		$test->expectAny();
629
 		$test->expectAny();
630
 		$test->get('/posts?columns=content&filter=content,eq,tests');
630
 		$test->get('/posts?columns=content&filter=content,eq,tests');
631
 		$test->expect('{"posts":{"columns":["content"],"records":[["tests"],["tests"]]}}');
631
 		$test->expect('{"posts":{"columns":["content"],"records":[["tests"],["tests"]]}}');
642
 	{
642
 	{
643
 		$test = new API($this);
643
 		$test = new API($this);
644
 		$test->get('/tag_usage');
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
 	public function testUpdateMultipleTags()
648
 	public function testUpdateMultipleTags()
649
 	{
649
 	{
650
 		$test = new API($this);
650
 		$test = new API($this);
651
 		$test->get('/tags?transform=1');
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
 		$test->put('/tags/1,2','[{"name":"funny"},{"name":"important"}]');
653
 		$test->put('/tags/1,2','[{"name":"funny"},{"name":"important"}]');
654
 		$test->expect('[1,1]');
654
 		$test->expect('[1,1]');
655
 	}
655
 	}
660
 		$test->put('/tags/1,2,3','[{"name":"funny!!!"},{"name":"important"}]');
660
 		$test->put('/tags/1,2,3','[{"name":"funny!!!"},{"name":"important"}]');
661
 		$test->expect(false,'Not found (subject)');
661
 		$test->expect(false,'Not found (subject)');
662
 		$test->get('/tags?transform=1');
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
 	public function testUpdateMultipleTagsWithoutFields()
666
 	public function testUpdateMultipleTagsWithoutFields()
669
 		$test->put('/tags/1,2','[{"name":"funny!!!"},{}]');
669
 		$test->put('/tags/1,2','[{"name":"funny!!!"},{}]');
670
 		$test->expect('null');
670
 		$test->expect('null');
671
 		$test->get('/tags?transform=1');
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
 	public function testDeleteMultipleTags()
675
 	public function testDeleteMultipleTags()
680
 		$test->delete('/tags/3,4');
680
 		$test->delete('/tags/3,4');
681
 		$test->expect('[1,1]');
681
 		$test->expect('[1,1]');
682
 		$test->get('/tags?transform=1');
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
 }

Loading…
Cancel
Save