INFRA-132 - @param type fixes
[civicrm-core.git] / tests / phpunit / api / v3 / ACLPermissionTest.php
index 5d8331fb9160e4e4d3126e61e8770c156e718f1a..95febd633c76a0f50a6062dd60215dcb898a5fdd 100644 (file)
@@ -1,9 +1,9 @@
 <?php
 /*
  +--------------------------------------------------------------------+
- | CiviCRM version 4.4                                                |
+ | CiviCRM version 4.6                                                |
  +--------------------------------------------------------------------+
- | Copyright CiviCRM LLC (c) 2004-2013                                |
+ | Copyright CiviCRM LLC (c) 2004-2014                                |
  +--------------------------------------------------------------------+
  | This file is a part of CiviCRM.                                    |
  |                                                                    |
@@ -33,23 +33,16 @@ require_once 'CiviTest/CiviUnitTestCase.php';
  * @package CiviCRM_APIv3
  * @subpackage API_Contact
  */
-
 class api_v3_ACLPermissionTest extends CiviUnitTestCase {
   protected $_apiversion = 3;
-  protected $_params;
-  protected $hookClass = NULL;
   public $DBResetRequired = FALSE;
-
-
-
   protected $_entity;
 
-  function setUp() {
+  public function setUp() {
     parent::setUp();
     $baoObj = new CRM_Core_DAO();
     $baoObj->createTestObject('CRM_Pledge_BAO_Pledge', array(), 1, 0);
     $baoObj->createTestObject('CRM_Core_BAO_Phone', array(), 1, 0);
-    $this->hookClass = CRM_Utils_Hook::singleton();
     $config = CRM_Core_Config::singleton();
     $config->userPermissionClass->permissions = array();
   }
@@ -58,7 +51,7 @@ class api_v3_ACLPermissionTest extends CiviUnitTestCase {
    * (non-PHPdoc)
    * @see CiviUnitTestCase::tearDown()
    */
-  function tearDown() {
+  public function tearDown() {
     CRM_Utils_Hook::singleton()->reset();
     $tablesToTruncate = array(
       'civicrm_contact',
@@ -79,7 +72,7 @@ class api_v3_ACLPermissionTest extends CiviUnitTestCase {
   /**
    * Function tests that an empty where hook returns no results
    */
-  function testContactGetNoResultsHook() {
+  public function testContactGetNoResultsHook() {
     $this->hookClass->setHook('civicrm_aclWhereClause', array($this, 'aclWhereHookNoResults'));
     $result = $this->callAPISuccess('contact', 'get', array(
       'check_permissions' => 1,
@@ -91,7 +84,7 @@ class api_v3_ACLPermissionTest extends CiviUnitTestCase {
   /**
    * Function tests all results are returned
    */
-  function testContactGetAllResultsHook() {
+  public function testContactGetAllResultsHook() {
     $this->hookClass->setHook('civicrm_aclWhereClause', array($this, 'aclWhereHookAllResults'));
     $result = $this->callAPISuccess('contact', 'get', array(
       'check_permissions' => 1,
@@ -104,7 +97,7 @@ class api_v3_ACLPermissionTest extends CiviUnitTestCase {
   /**
    * Function tests that deleted contacts are not returned
    */
-  function testContactGetPermissionHookNoDeleted() {
+  public function testContactGetPermissionHookNoDeleted() {
     $this->callAPISuccess('contact', 'create', array('id' => 2, 'is_deleted' => 1));
     $this->hookClass->setHook('civicrm_aclWhereClause', array($this, 'aclWhereHookAllResults'));
     $result = $this->callAPISuccess('contact', 'get', array(
@@ -115,9 +108,9 @@ class api_v3_ACLPermissionTest extends CiviUnitTestCase {
   }
 
   /**
-   * test permissions limited by hook
+   * Test permissions limited by hook
    */
-  function testContactGetHookLimitingHook() {
+  public function testContactGetHookLimitingHook() {
     $this->hookClass->setHook('civicrm_aclWhereClause', array($this, 'aclWhereOnlySecond'));
 
     $result = $this->callAPISuccess('contact', 'get', array(
@@ -128,10 +121,9 @@ class api_v3_ACLPermissionTest extends CiviUnitTestCase {
   }
 
   /**
-   * confirm that without check permissions we still get 2 contacts returned
+   * Confirm that without check permissions we still get 2 contacts returned
    */
-  function testContactGetHookLimitingHookDontCheck() {
-    //
+  public function testContactGetHookLimitingHookDontCheck() {
     $result = $this->callAPISuccess('contact', 'get', array(
       'check_permissions' => 0,
       'return' => 'display_name',
@@ -142,7 +134,7 @@ class api_v3_ACLPermissionTest extends CiviUnitTestCase {
   /**
    * Check that id works as a filter
    */
-  function testContactGetIDFilter() {
+  public function testContactGetIDFilter() {
     $this->hookClass->setHook('civicrm_aclWhereClause', array($this, 'aclWhereHookAllResults'));
     $result = $this->callAPISuccess('contact', 'get', array(
       'sequential' => 1,
@@ -157,7 +149,7 @@ class api_v3_ACLPermissionTest extends CiviUnitTestCase {
   /**
    * Check that address IS returned
    */
-  function testContactGetAddressReturned() {
+  public function testContactGetAddressReturned() {
     $this->hookClass->setHook('civicrm_aclWhereClause', array($this, 'aclWhereOnlySecond'));
     $fullresult = $this->callAPISuccess('contact', 'get', array(
       'sequential' => 1,
@@ -174,7 +166,7 @@ class api_v3_ACLPermissionTest extends CiviUnitTestCase {
       'phone_type_id',
       'phone',
       'worldregion_id',
-      'world_region'
+      'world_region',
     );
     $expectedReturnElements = array_diff(array_keys($fullresult['values'][0]), $elementsReturnDoesntSupport);
     $result = $this->callAPISuccess('contact', 'get', array(
@@ -191,9 +183,9 @@ class api_v3_ACLPermissionTest extends CiviUnitTestCase {
   /**
    * Check that pledge IS not returned
    */
-  function testContactGetPledgeIDNotReturned() {
+  public function testContactGetPledgeIDNotReturned() {
     $this->hookClass->setHook('civicrm_aclWhereClause', array($this, 'aclWhereHookAllResults'));
-    $fullresult = $this->callAPISuccess('contact', 'get', array(
+    $this->callAPISuccess('contact', 'get', array(
       'sequential' => 1,
     ));
     $result = $this->callAPISuccess('contact', 'get', array(
@@ -207,9 +199,9 @@ class api_v3_ACLPermissionTest extends CiviUnitTestCase {
   /**
    * Check that pledge IS not an allowable filter
    */
-  function testContactGetPledgeIDNotFiltered() {
+  public function testContactGetPledgeIDNotFiltered() {
     $this->hookClass->setHook('civicrm_aclWhereClause', array($this, 'aclWhereHookAllResults'));
-    $fullresult = $this->callAPISuccess('contact', 'get', array(
+    $this->callAPISuccess('contact', 'get', array(
       'sequential' => 1,
     ));
     $result = $this->callAPISuccess('contact', 'get', array(
@@ -223,12 +215,12 @@ class api_v3_ACLPermissionTest extends CiviUnitTestCase {
   /**
    * Check that chaining doesn't bypass permissions
    */
-  function testContactGetPledgeNotChainable() {
+  public function testContactGetPledgeNotChainable() {
     $this->hookClass->setHook('civicrm_aclWhereClause', array($this, 'aclWhereOnlySecond'));
-    $fullresult = $this->callAPISuccess('contact', 'get', array(
+    $this->callAPISuccess('contact', 'get', array(
       'sequential' => 1,
     ));
-    $result = $this->callAPIFailure('contact', 'get', array(
+    $this->callAPIFailure('contact', 'get', array(
         'check_permissions' => 1,
         'api.pledge.get' => 1,
         'sequential' => 1,
@@ -237,17 +229,26 @@ class api_v3_ACLPermissionTest extends CiviUnitTestCase {
     );
   }
 
-  function setupCoreACL() {
+  public function setupCoreACL() {
     $this->createLoggedInUser();
-    $this->_permissionedDisabledGroup = $this->groupCreate(array('title' => 'pick-me-disabled', 'is_active' => 0, 'name' => 'pick-me-disabled'));
-    $this->_permissionedGroup = $this->groupCreate(array('title' => 'pick-me-active', 'is_active' => 1, 'name' => 'pick-me-active'));
+    $this->_permissionedDisabledGroup = $this->groupCreate(array(
+        'title' => 'pick-me-disabled',
+        'is_active' => 0,
+        'name' => 'pick-me-disabled',
+      ));
+    $this->_permissionedGroup = $this->groupCreate(array(
+        'title' => 'pick-me-active',
+        'is_active' => 1,
+        'name' => 'pick-me-active',
+      ));
     $this->setupACL();
   }
+
   /**
    * @dataProvider entities
    * confirm that without check permissions we still get 2 contacts returned
    */
-  function testEntitiesGetHookLimitingHookNoCheck($entity) {
+  public function testEntitiesGetHookLimitingHookNoCheck($entity) {
     CRM_Core_Config::singleton()->userPermissionClass->permissions = array();
     $this->setUpEntities($entity);
     $this->hookClass->setHook('civicrm_aclWhereClause', array($this, 'aclWhereHookNoResults'));
@@ -262,7 +263,7 @@ class api_v3_ACLPermissionTest extends CiviUnitTestCase {
    * @dataProvider entities
    * confirm that without check permissions we still get 2 entities returned
    */
-  function testEntitiesGetCoreACLLimitingHookNoCheck($entity) {
+  public function testEntitiesGetCoreACLLimitingHookNoCheck($entity) {
     $this->setupCoreACL();
     //CRM_Core_Config::singleton()->userPermissionClass->permissions = array();
     $this->setUpEntities($entity);
@@ -273,14 +274,15 @@ class api_v3_ACLPermissionTest extends CiviUnitTestCase {
     ));
     $this->assertEquals(2, $result['count']);
   }
+
   /**
    * @dataProvider entities
    * confirm that with check permissions we don't get entities
    */
-  function testEntitiesGetCoreACLLimitingHookCheck($entity) {
+  public function testEntitiesGetCoreACLLimitingCheck($entity) {
+    $this->markTestIncomplete('this does not work in 4.4 but can be enabled in 4.5 or a security release of 4.4 including the important security fix CRM-14877');
     $this->setupCoreACL();
     $this->setUpEntities($entity);
-    $this->hookClass->setHook('civicrm_aclWhereClause', array($this, 'aclWhereHookNoResults'));
     $result = $this->callAPISuccess($entity, 'get', array(
       'check_permissions' => 1,
       'return' => 'contact_id',
@@ -293,7 +295,7 @@ class api_v3_ACLPermissionTest extends CiviUnitTestCase {
    * @dataProvider entities
    * Function tests that an empty where hook returns no results
    */
-  function testEntityGetNoResultsHook($entity) {
+  public function testEntityGetNoResultsHook($entity) {
     $this->markTestIncomplete('hook acls only work with contacts so far');
     CRM_Core_Config::singleton()->userPermissionClass->permissions = array();
     $this->setUpEntities($entity);
@@ -308,7 +310,7 @@ class api_v3_ACLPermissionTest extends CiviUnitTestCase {
    * @return array
    */
   public static function entities() {
-    return array(array('contribution'), array('participant'),);// @todo array('pledge' => 'pledge')
+    return array(array('contribution'), array('participant'));// @todo array('pledge' => 'pledge')
   }
 
   /**
@@ -316,7 +318,7 @@ class api_v3_ACLPermissionTest extends CiviUnitTestCase {
    */
   public function setUpEntities($entity) {
     $baoObj = new CRM_Core_DAO();
-    $baoObj->createTestObject( _civicrm_api3_get_BAO($entity), array(), 2, 0);
+    $baoObj->createTestObject(_civicrm_api3_get_BAO($entity), array(), 2, 0);
     CRM_Core_Config::singleton()->userPermissionClass->permissions = array(
       'access CiviCRM',
       'access CiviContribute',
@@ -326,22 +328,24 @@ class api_v3_ACLPermissionTest extends CiviUnitTestCase {
   }
 
   /**
-   * no results returned
+   * No results returned
    */
-  function aclWhereHookNoResults($type, &$tables, &$whereTables, &$contactID, &$where) {
+  public function aclWhereHookNoResults($type, &$tables, &$whereTables, &$contactID, &$where) {
   }
 
   /**
-   * all results returned
+   * All results returned
+   * @implements CRM_Utils_Hook::aclWhereClause
    */
-  function aclWhereHookAllResults($type, &$tables, &$whereTables, &$contactID, &$where) {
+  public function aclWhereHookAllResults($type, &$tables, &$whereTables, &$contactID, &$where) {
     $where = " (1) ";
   }
 
   /**
-   * full results returned
+   * Full results returned
+   * @implements CRM_Utils_Hook::aclWhereClause
    */
-  function aclWhereOnlySecond($type, &$tables, &$whereTables, &$contactID, &$where) {
+  public function aclWhereOnlySecond($type, &$tables, &$whereTables, &$contactID, &$where) {
     $where = " contact_a.id > 1";
   }
 }