Skip to content

Commit 2040991

Browse files
committed
added tests for tenancy
1 parent 5b3f545 commit 2040991

File tree

2 files changed

+81
-1
lines changed

2 files changed

+81
-1
lines changed

api.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1136,7 +1136,7 @@ protected function parseGetParameterArray($get,$name,$characters) {
11361136

11371137
protected function applyBeforeHandler(&$action,&$database,&$table,&$ids,&$callback,&$inputs) {
11381138
if (is_callable($callback,true)) {
1139-
$max = count($ids)?:count($inputs);
1139+
$max = (is_array($ids)&&count($ids))?:count($inputs);
11401140
$values = array('action'=>$action,'database'=>$database,'table'=>$table);
11411141
for ($i=0;$i<$max;$i++) {
11421142
$action = $values['action'];

tests/Tests.php

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -674,4 +674,84 @@ public function testListUsersColumnsWithoutTenancyId()
674674
$test->get('/users?columns=username,location');
675675
$test->expect('{"users":{"columns":["username","location"],"records":[["user1","POINT(30 20)"]]}}');
676676
}
677+
678+
public function testTenancyCreateColumns()
679+
{
680+
// creation should fail, since due to tenancy function it will try to create with id=1, which is a PK and is already taken
681+
$test = new Api($this);
682+
$test->post('/users?columns=username,password,location', '{"username":"user3","password":"pass3","location":null}');
683+
$test->expect('null');
684+
}
685+
686+
public function testTenancyCreateExclude()
687+
{
688+
// creation should fail, since due to tenancy function it will try to create with id=1, which is a PK and is already taken
689+
$test = new Api($this);
690+
$test->post('/users?exclude=id', '{"username":"user3","password":"pass3","location":null}');
691+
$test->expect('null');
692+
}
693+
694+
public function testTenancyListColumns()
695+
{
696+
// should list only user with id=1 (exactly 1 record)
697+
$test = new Api($this);
698+
$test->get('/users?columns=username,location');
699+
$test->expect('{"users":{"columns":["username","location"],"records":[["user1",null]]}}');
700+
}
701+
702+
public function testTenancyListExclude()
703+
{
704+
// should list only user with id=1 (exactly 1 record)
705+
$test = new Api($this);
706+
$test->get('/users?exclude=id');
707+
$test->expect('{"users":{"columns":["username","location"],"records":[["user1",null]]}}');
708+
}
709+
710+
public function testTenancyReadColumns()
711+
{
712+
// should fail, since due to tenancy function user id=2 is unvailable to us
713+
$test = new Api($this);
714+
$test->get('/users/2?columns=username,location');
715+
$test->expect(false, 'Not found (object)');
716+
}
717+
718+
public function testTenancyReadExclude()
719+
{
720+
// should fail, since due to tenancy function user id=2 is unvailable to us
721+
$test = new Api($this);
722+
$test->get('/users/2?exclude=id');
723+
$test->expect(false, 'Not found (object)');
724+
}
725+
726+
public function testTenancyUpdateColumns()
727+
{
728+
// should fail, since due to tenancy function user id=2 is unvailable to us
729+
$test = new Api($this);
730+
$test->put('/users/2?columns=location', '{"location":"somelocation"}');
731+
$test->expect('0');
732+
}
733+
734+
public function testTenancyUpdateExclude()
735+
{
736+
// should fail, since due to tenancy function user id=2 is unvailable to us
737+
$test = new Api($this);
738+
$test->put('/users/2?exclude=id', '{"location":"somelocation"}');
739+
$test->expect('0');
740+
}
741+
742+
public function testTenancyDeleteColumns()
743+
{
744+
// should fail, since due to tenancy function user id=2 is unvailable to us
745+
$test = new Api($this);
746+
$test->delete('/users/2?columns=location');
747+
$test->expect('0');
748+
}
749+
750+
public function testTenancyDeleteExclude()
751+
{
752+
// should fail, since due to tenancy function user id=2 is unvailable to us
753+
$test = new Api($this);
754+
$test->delete('/users/2?exclude=id');
755+
$test->expect('0');
756+
}
677757
}

0 commit comments

Comments
 (0)