Merge branch 'master' of github.com:mevdschee/php-crud-api
This commit is contained in:
commit
f4a1c73705
7 changed files with 12 additions and 12 deletions
|
|
@ -150,8 +150,8 @@ Search is implemented with the "filter" parameter. You need to specify the colum
|
|||
- le: lower or equal (number is lower than or equal to value)
|
||||
- ge: greater or equal (number is higher than or equal to value)
|
||||
- gt: greater than (number is higher than value)
|
||||
- in: in (number is in comma seperated list of values)
|
||||
- ni: not in (number is not in comma seperated list of values)
|
||||
- in: in (number is in comma separated list of values)
|
||||
- ni: not in (number is not in comma separated list of values)
|
||||
- is: is null (field contains "NULL" value)
|
||||
- no: not null (field does not contain "NULL" value)
|
||||
|
||||
|
|
@ -186,7 +186,7 @@ Output:
|
|||
|
||||
### List + Column selection
|
||||
|
||||
By default all columns are selected. With the "columns" parameter you can select specific columns. Multiple columns should be comma seperated. An asterisk ("*") may be used as a wildcard to indicate "all columns":
|
||||
By default all columns are selected. With the "columns" parameter you can select specific columns. Multiple columns should be comma separated. An asterisk ("*") may be used as a wildcard to indicate "all columns":
|
||||
|
||||
```
|
||||
GET http://localhost/api.php/categories?columns=name
|
||||
|
|
|
|||
|
|
@ -39,7 +39,7 @@ switch ($method) {
|
|||
$sql = "delete `$table` where id=$key"; break;
|
||||
}
|
||||
|
||||
// excecute SQL statement
|
||||
// execute SQL statement
|
||||
$result = mysqli_query($link,$sql);
|
||||
|
||||
// die if SQL statement failed
|
||||
|
|
|
|||
|
|
@ -14,7 +14,7 @@ CREATE TABLE `categories` (
|
|||
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
|
||||
|
||||
INSERT INTO `categories` (`id`, `name`, `icon`) VALUES
|
||||
(1, 'anouncement', NULL),
|
||||
(1, 'announcement', NULL),
|
||||
(2, 'article', NULL);
|
||||
|
||||
DROP TABLE IF EXISTS `comments`;
|
||||
|
|
|
|||
|
|
@ -97,7 +97,7 @@ CREATE TABLE users (
|
|||
--
|
||||
|
||||
INSERT INTO "categories" ("name", "icon") VALUES
|
||||
('anouncement', NULL),
|
||||
('announcement', NULL),
|
||||
('article', NULL);
|
||||
|
||||
--
|
||||
|
|
|
|||
|
|
@ -7,7 +7,7 @@ CREATE TABLE "categories" (
|
|||
"icon" blob NULL
|
||||
);
|
||||
|
||||
INSERT INTO "categories" ("id", "name", "icon") VALUES (1, 'anouncement', NULL);
|
||||
INSERT INTO "categories" ("id", "name", "icon") VALUES (1, 'announcement', NULL);
|
||||
INSERT INTO "categories" ("id", "name", "icon") VALUES (2, 'article', NULL);
|
||||
|
||||
DROP TABLE IF EXISTS "comments";
|
||||
|
|
|
|||
|
|
@ -141,7 +141,7 @@ CREATE TABLE [users](
|
|||
GO
|
||||
SET IDENTITY_INSERT [categories] ON
|
||||
GO
|
||||
INSERT [categories] ([id], [name], [icon]) VALUES (1, N'anouncement', NULL)
|
||||
INSERT [categories] ([id], [name], [icon]) VALUES (1, N'announcement', NULL)
|
||||
GO
|
||||
INSERT [categories] ([id], [name], [icon]) VALUES (2, N'article', NULL)
|
||||
GO
|
||||
|
|
|
|||
|
|
@ -329,14 +329,14 @@ class PHP_CRUD_API_Test extends PHPUnit_Framework_TestCase
|
|||
{
|
||||
$test = new API($this);
|
||||
$test->get('/posts?include=categories,tags,comments&filter=id,eq,1');
|
||||
$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","anouncement",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"]]}}');
|
||||
$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"]]}}');
|
||||
}
|
||||
|
||||
public function testListExampleFromReadmeWithTransform()
|
||||
{
|
||||
$test = new API($this);
|
||||
$test->get('/posts?include=categories,tags,comments&filter=id,eq,1&transform=1');
|
||||
$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":"anouncement","icon":null}],"content":"blog started"}]}');
|
||||
$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"}]}');
|
||||
}
|
||||
|
||||
public function testEditCategoryWithBinaryContent()
|
||||
|
|
@ -487,7 +487,7 @@ class PHP_CRUD_API_Test extends PHPUnit_Framework_TestCase
|
|||
{
|
||||
$test = new API($this);
|
||||
$test->get('/categories?filter[]=icon,is,null&transform=1');
|
||||
$test->expect('{"categories":[{"id":"1","name":"anouncement","icon":null},{"id":"2","name":"alert();","icon":null}]}');
|
||||
$test->expect('{"categories":[{"id":"1","name":"announcement","icon":null},{"id":"2","name":"alert();","icon":null}]}');
|
||||
}
|
||||
|
||||
public function testFilterCategoryOnNotNullIcon()
|
||||
|
|
@ -522,7 +522,7 @@ class PHP_CRUD_API_Test extends PHPUnit_Framework_TestCase
|
|||
{
|
||||
$test = new API($this);
|
||||
$test->get('/posts?include=categories&columns=categories.name&filter=id,eq,1&transform=1');
|
||||
$test->expect('{"posts":[{"category_id":"1","categories":[{"id":"1","name":"anouncement"}]}]}');
|
||||
$test->expect('{"posts":[{"category_id":"1","categories":[{"id":"1","name":"announcement"}]}]}');
|
||||
}
|
||||
|
||||
public function testColumnsOnWrongInclude()
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue