Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
C
Core
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Deploy
Releases
Container Registry
Model registry
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
justinfreeman (Agileware)
Core
Commits
6069a556
Commit
6069a556
authored
11 years ago
by
Kurund Jalmi
Browse files
Options
Downloads
Plain Diff
Merge pull request #1356 from kurund/test-fixes
Test fixes
parents
1d471d7f
31edf52e
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
tests/phpunit/api/v3/ACLPermissionTest.php
+111
-106
111 additions, 106 deletions
tests/phpunit/api/v3/ACLPermissionTest.php
with
111 additions
and
106 deletions
tests/phpunit/api/v3/ACLPermissionTest.php
+
111
−
106
View file @
6069a556
...
...
@@ -30,14 +30,14 @@ require_once 'CiviTest/CiviUnitTestCase.php';
/**
* This class is intended to test ACL permission using the multisite module
*
*
@package CiviCRM_APIv3
*
@subpackage API_Contact
* @package CiviCRM_APIv3
* @subpackage API_Contact
*/
class
api_v3_ACLPermissionTest
extends
CiviUnitTestCase
{
protected
$_apiversion
=
3
;
protected
$_params
;
protected
$hookClass
=
null
;
protected
$hookClass
=
NULL
;
public
$DBResetRequired
=
FALSE
;
public
$_eNoticeCompliant
=
TRUE
;
...
...
@@ -53,23 +53,25 @@ class api_v3_ACLPermissionTest extends CiviUnitTestCase {
$config
=
CRM_Core_Config
::
singleton
();
$config
->
userPermissionClass
->
permissions
=
array
();
}
/**
* (non-PHPdoc)
* @see CiviUnitTestCase::tearDown()
*/
/**
* (non-PHPdoc)
* @see CiviUnitTestCase::tearDown()
*/
function
tearDown
()
{
CRM_Utils_Hook
::
singleton
()
->
reset
();
$tablesToTruncate
=
array
(
'civicrm_contact'
,
'civicrm_contact'
,
);
$this
->
quickCleanup
(
$tablesToTruncate
);
$config
=
CRM_Core_Config
::
singleton
();
unset
(
$config
->
userPermissionClass
->
permissions
);
}
/**
* Function tests that an empty where hook returns no results
*/
function
testContactGetNoResultsHook
(){
/**
* Function tests that an empty where hook returns no results
*/
function
testContactGetNoResultsHook
()
{
$this
->
hookClass
->
setHook
(
'civicrm_aclWhereClause'
,
array
(
$this
,
'aclWhereHookNoResults'
));
$result
=
$this
->
callAPISuccess
(
'contact'
,
'get'
,
array
(
'check_permissions'
=>
1
,
...
...
@@ -80,25 +82,26 @@ class api_v3_ACLPermissionTest extends CiviUnitTestCase {
/**
* Function tests all results are returned
*/
function
testContactGetAllResultsHook
(){
*/
function
testContactGetAllResultsHook
()
{
$this
->
hookClass
->
setHook
(
'civicrm_aclWhereClause'
,
array
(
$this
,
'aclWhereHookAllResults'
));
$result
=
$this
->
callAPISuccess
(
'contact'
,
'get'
,
array
(
'check_permissions'
=>
1
,
'return'
=>
'display_name'
,
'check_permissions'
=>
1
,
'return'
=>
'display_name'
,
));
$this
->
assertEquals
(
2
,
$result
[
'count'
]);
}
/**
* Function tests that deleted contacts are not returned
*/
function
testContactGetPermissionHookNoDeleted
(){
*/
function
testContactGetPermissionHookNoDeleted
()
{
$result
=
$this
->
callAPISuccess
(
'contact'
,
'create'
,
array
(
'id'
=>
2
,
'is_deleted'
=>
1
));
$this
->
hookClass
->
setHook
(
'civicrm_aclWhereClause'
,
array
(
$this
,
'aclWhereHookAllResults'
));
$result
=
$this
->
callAPISuccess
(
'contact'
,
'get'
,
array
(
'check_permissions'
=>
1
,
'return'
=>
'display_name'
,
'check_permissions'
=>
1
,
'return'
=>
'display_name'
,
));
$this
->
assertEquals
(
1
,
$result
[
'count'
]);
}
...
...
@@ -106,20 +109,20 @@ class api_v3_ACLPermissionTest extends CiviUnitTestCase {
/**
* test permissions limited by hook
*/
function
testContactGetHookLimitingHook
(){
function
testContactGetHookLimitingHook
()
{
$this
->
hookClass
->
setHook
(
'civicrm_aclWhereClause'
,
array
(
$this
,
'aclWhereOnlySecond'
));
$result
=
$this
->
callAPISuccess
(
'contact'
,
'get'
,
array
(
'check_permissions'
=>
1
,
'return'
=>
'display_name'
,
));
));
$this
->
assertEquals
(
1
,
$result
[
'count'
]);
}
/**
* confirm that without check permissions we still get 2 contacts returned
*/
function
testContactGetHookLimitingHookDontCheck
(){
/**
* confirm that without check permissions we still get 2 contacts returned
*/
function
testContactGetHookLimitingHookDontCheck
()
{
//
$result
=
$this
->
callAPISuccess
(
'contact'
,
'get'
,
array
(
'check_permissions'
=>
0
,
...
...
@@ -127,10 +130,11 @@ class api_v3_ACLPermissionTest extends CiviUnitTestCase {
));
$this
->
assertEquals
(
2
,
$result
[
'count'
]);
}
/**
* Check that id works as a filter
*/
function
testContactGetIDFilter
(){
function
testContactGetIDFilter
()
{
$this
->
hookClass
->
setHook
(
'civicrm_aclWhereClause'
,
array
(
$this
,
'aclWhereHookAllResults'
));
$result
=
$this
->
callAPISuccess
(
'contact'
,
'get'
,
array
(
'sequential'
=>
1
,
...
...
@@ -142,104 +146,105 @@ class api_v3_ACLPermissionTest extends CiviUnitTestCase {
$this
->
assertEquals
(
2
,
$result
[
'id'
]);
}
/**
* Check that address IS returned
*/
function
testContactGetAddressReturned
(){
$this
->
hookClass
->
setHook
(
'civicrm_aclWhereClause'
,
array
(
$this
,
'aclWhereOnlySecond'
));
$fullresult
=
$this
->
callAPISuccess
(
'contact'
,
'get'
,
array
(
'sequential'
=>
1
,
));
//return doesn't work for all keys - can't fix that here so let's skip ...
//prefix & suffix are inconsistent due to CRM-7929
// unsure about others but return doesn't work on them
$elementsReturnDoesntSupport
=
array
(
'prefix_id'
,
'prefix'
,
'suffix_id'
,
'suffix'
,
'gender_id'
,
'gender'
,
'current_employer'
,
'phone_id'
,
'phone_type_id'
,
'phone'
,
'worldregion_id'
,
'world_region'
);
$expectedReturnElements
=
array_diff
(
array_keys
(
$fullresult
[
'values'
][
0
]),
$elementsReturnDoesntSupport
);
$result
=
$this
->
callAPISuccess
(
'contact'
,
'get'
,
array
(
'check_permissions'
=>
1
,
'return'
=>
$expectedReturnElements
,
'sequential'
=>
1
,
));
$this
->
assertEquals
(
1
,
$result
[
'count'
]);
foreach
(
$expectedReturnElements
as
$element
){
$this
->
assertArrayHasKey
(
$element
,
$result
[
'values'
][
0
]);
}
}
/**
* Check that pledge IS not returned
*/
function
testContactGetPledgeIDNotReturned
(){
$this
->
hookClass
->
setHook
(
'civicrm_aclWhereClause'
,
array
(
$this
,
'aclWhereHookAllResults'
));
$fullresult
=
$this
->
callAPISuccess
(
'contact'
,
'get'
,
array
(
'sequential'
=>
1
,
));
$result
=
$this
->
callAPISuccess
(
'contact'
,
'get'
,
array
(
'check_permissions'
=>
1
,
'return'
=>
'pledge_id'
,
'sequential'
=>
1
,
));
$this
->
assertArrayNotHasKey
(
'pledge_id'
,
$result
[
'values'
][
0
]);
/**
* Check that address IS returned
*/
function
testContactGetAddressReturned
()
{
$this
->
hookClass
->
setHook
(
'civicrm_aclWhereClause'
,
array
(
$this
,
'aclWhereOnlySecond'
));
$fullresult
=
$this
->
callAPISuccess
(
'contact'
,
'get'
,
array
(
'sequential'
=>
1
,
));
//return doesn't work for all keys - can't fix that here so let's skip ...
//prefix & suffix are inconsistent due to CRM-7929
// unsure about others but return doesn't work on them
$elementsReturnDoesntSupport
=
array
(
'prefix'
,
'suffix'
,
'gender'
,
'current_employer'
,
'phone_id'
,
'phone_type_id'
,
'phone'
,
'worldregion_id'
,
'world_region'
);
$expectedReturnElements
=
array_diff
(
array_keys
(
$fullresult
[
'values'
][
0
]),
$elementsReturnDoesntSupport
);
$result
=
$this
->
callAPISuccess
(
'contact'
,
'get'
,
array
(
'check_permissions'
=>
1
,
'return'
=>
$expectedReturnElements
,
'sequential'
=>
1
,
));
$this
->
assertEquals
(
1
,
$result
[
'count'
]);
foreach
(
$expectedReturnElements
as
$element
)
{
$this
->
assertArrayHasKey
(
$element
,
$result
[
'values'
][
0
]);
}
}
/**
* Check that pledge IS not returned
*/
function
testContactGetPledgeIDNotReturned
()
{
$this
->
hookClass
->
setHook
(
'civicrm_aclWhereClause'
,
array
(
$this
,
'aclWhereHookAllResults'
));
$fullresult
=
$this
->
callAPISuccess
(
'contact'
,
'get'
,
array
(
'sequential'
=>
1
,
));
$result
=
$this
->
callAPISuccess
(
'contact'
,
'get'
,
array
(
'check_permissions'
=>
1
,
'return'
=>
'pledge_id'
,
'sequential'
=>
1
,
));
$this
->
assertArrayNotHasKey
(
'pledge_id'
,
$result
[
'values'
][
0
]);
}
/**
* Check that pledge IS not an allowable filter
*/
function
testContactGetPledgeIDNotFiltered
(){
$this
->
hookClass
->
setHook
(
'civicrm_aclWhereClause'
,
array
(
$this
,
'aclWhereHookAllResults'
));
$fullresult
=
$this
->
callAPISuccess
(
'contact'
,
'get'
,
array
(
'sequential'
=>
1
,
));
$result
=
$this
->
callAPISuccess
(
'contact'
,
'get'
,
array
(
/**
* Check that pledge IS not an allowable filter
*/
function
testContactGetPledgeIDNotFiltered
()
{
$this
->
hookClass
->
setHook
(
'civicrm_aclWhereClause'
,
array
(
$this
,
'aclWhereHookAllResults'
));
$fullresult
=
$this
->
callAPISuccess
(
'contact'
,
'get'
,
array
(
'sequential'
=>
1
,
));
$result
=
$this
->
callAPISuccess
(
'contact'
,
'get'
,
array
(
'check_permissions'
=>
1
,
'pledge_id'
=>
1
,
'sequential'
=>
1
,
));
$this
->
assertEquals
(
2
,
$result
[
'count'
]);
}
/**
* Check that chaining doesn't bypass permissions
*/
function
testContactGetPledgeNotChainable
()
{
$this
->
hookClass
->
setHook
(
'civicrm_aclWhereClause'
,
array
(
$this
,
'aclWhereOnlySecond'
));
$fullresult
=
$this
->
callAPISuccess
(
'contact'
,
'get'
,
array
(
'sequential'
=>
1
,
));
$result
=
$this
->
callAPIFailure
(
'contact'
,
'get'
,
array
(
'check_permissions'
=>
1
,
'pledge
_id
'
=>
1
,
'
api.
pledge
.get
'
=>
1
,
'sequential'
=>
1
,
));
$this
->
assertEquals
(
2
,
$result
[
'count'
]);
}
/**
* Check that chaining doesn't bypass permissions
*/
function
testContactGetPledgeNotChainable
(){
$this
->
hookClass
->
setHook
(
'civicrm_aclWhereClause'
,
array
(
$this
,
'aclWhereOnlySecond'
));
$fullresult
=
$this
->
callAPISuccess
(
'contact'
,
'get'
,
array
(
'sequential'
=>
1
,
));
$result
=
$this
->
callAPIFailure
(
'contact'
,
'get'
,
array
(
'check_permissions'
=>
1
,
'api.pledge.get'
=>
1
,
'sequential'
=>
1
,
),
'Error in call to pledge_get : API permission check failed for pledge/get call; missing permission: access CiviCRM.'
);
}
);
}
/**
* no results returned
*/
function
aclWhereHookNoResults
(
$type
,
&
$tables
,
&
$whereTables
,
&
$contactID
,
&
$where
)
{
}
/**
* all results returned
*/
*/
function
aclWhereHookAllResults
(
$type
,
&
$tables
,
&
$whereTables
,
&
$contactID
,
&
$where
)
{
$where
=
" (1) "
;
}
/**
* full results returned
*/
*/
function
aclWhereOnlySecond
(
$type
,
&
$tables
,
&
$whereTables
,
&
$contactID
,
&
$where
)
{
$where
=
" contact_a.id > 1"
;
}
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment