From f0054c4089f0c77834e32fe1923052a60dcfc876 Mon Sep 17 00:00:00 2001 From: saeideng Date: Mon, 28 Mar 2016 00:08:38 +0430 Subject: [PATCH 1/2] add tests for idColumn --- tests/TestCase/Auth/TinyAuthorizeTest.php | 57 +++++++++++++++++++++++ 1 file changed, 57 insertions(+) diff --git a/tests/TestCase/Auth/TinyAuthorizeTest.php b/tests/TestCase/Auth/TinyAuthorizeTest.php index 611fd8eb..8cb1c26b 100644 --- a/tests/TestCase/Auth/TinyAuthorizeTest.php +++ b/tests/TestCase/Auth/TinyAuthorizeTest.php @@ -318,6 +318,7 @@ public function testBasicUserMethodDisallowed() { ]); $this->assertEquals('Roles', $object->config('rolesTable')); $this->assertEquals('role_id', $object->config('roleColumn')); + $this->assertEquals('id', $object->config('idColumn')); // All tests performed against this action $this->request->params['action'] = 'add'; @@ -1353,6 +1354,62 @@ public function testUserRolesCustomPivotTable() { $this->assertEquals($expected, $res); } + /** + * Tests idColumn + * + * @return void + */ + public function testIdColumnPivotTable() { + $object = new TestTinyAuthorize($this->collection, [ + + 'multiRole' => true, + 'rolesTable' => 'DatabaseRoles', + 'pivotTable' => 'DatabaseUserRoles', + 'roleColumn' => 'role_id', + 'userColumn' => 'user_id', + 'idColumn' => 'profile_id', + ]); + + // Make protected function available + $reflection = new ReflectionClass(get_class($object)); + $method = $reflection->getMethod('_getUserRoles'); + $method->setAccessible(true); + + $user = [ + 'id' => 1, + 'profile_id' => 2 + ]; + $expected = [ + 0 => 11, // user + 1 => 13 // admin + ]; + $res = $method->invokeArgs($object, [$user]); + $this->assertEquals($expected, $res); + + $user = [ + 'id' => 1, + 'profile_id' => 1 + ]; + $expected = [ + 0 => 11, // user + 1 => 12 // moderator + ]; + $res = $method->invokeArgs($object, [$user]); + $this->assertEquals($expected, $res); + + //without id + $user = [ + 'profile_id' => 1 + ]; + $expected = [ + 0 => 11, // user + 1 => 12 // moderator + ]; + $res = $method->invokeArgs($object, [$user]); + $this->assertEquals($expected, $res); + + } + /** * Tests single-role exception thrown when the roleColumn field is missing * from the user table. From ad16942fa85207c6343ad11702f8856275ae65ac Mon Sep 17 00:00:00 2001 From: saeideng Date: Mon, 28 Mar 2016 00:20:06 +0430 Subject: [PATCH 2/2] CS --- tests/TestCase/Auth/TinyAuthorizeTest.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/tests/TestCase/Auth/TinyAuthorizeTest.php b/tests/TestCase/Auth/TinyAuthorizeTest.php index 8cb1c26b..6641ff2e 100644 --- a/tests/TestCase/Auth/TinyAuthorizeTest.php +++ b/tests/TestCase/Auth/TinyAuthorizeTest.php @@ -1374,7 +1374,7 @@ public function testIdColumnPivotTable() { $reflection = new ReflectionClass(get_class($object)); $method = $reflection->getMethod('_getUserRoles'); $method->setAccessible(true); - + $user = [ 'id' => 1, 'profile_id' => 2 @@ -1385,7 +1385,7 @@ public function testIdColumnPivotTable() { ]; $res = $method->invokeArgs($object, [$user]); $this->assertEquals($expected, $res); - + $user = [ 'id' => 1, 'profile_id' => 1 @@ -1396,7 +1396,7 @@ public function testIdColumnPivotTable() { ]; $res = $method->invokeArgs($object, [$user]); $this->assertEquals($expected, $res); - + //without id $user = [ 'profile_id' => 1 @@ -1407,7 +1407,7 @@ public function testIdColumnPivotTable() { ]; $res = $method->invokeArgs($object, [$user]); $this->assertEquals($expected, $res); - + } /**