api test for CRM-16796
authorjitendrapurohit <jitendra.purohit@webaccessglobal.com>
Tue, 7 Jul 2015 09:49:06 +0000 (15:19 +0530)
committerjitendrapurohit <jitendra.purohit@webaccessglobal.com>
Fri, 10 Jul 2015 04:46:07 +0000 (10:16 +0530)
Civi/API/Subscriber/PermissionCheck.php
api/v3/examples/UFField/Replace.php
tests/phpunit/CiviTest/CiviUnitTestCase.php
tests/phpunit/api/v3/UFFieldTest.php

index 184a8305b98ba2c44c038b765cbde0f4a213af99..4603eaf9d9ff002240d2f34c04ff350dba91bdf5 100644 (file)
@@ -88,10 +88,12 @@ class PermissionCheck implements EventSubscriberInterface {
   }
 
   /**
-   * check API for ACL permission.
-   * @param $apiRequest
-   * @return bool
-   */
+  *  Check API for ACL permission.
+  *
+  * @param array $apiRequest
+  *
+  * @return bool
+  */
   public function checkACLPermission($apiRequest) {
     switch ($apiRequest['entity']) {
       case 'UFGroup':
index fc95c904393727c1eba414f1181636886d60c6ef..f94ad49347d9066536b138bbdc647b4c7b5ac5b6 100644 (file)
@@ -41,6 +41,7 @@ function uf_field_replace_example() {
         'phone_type_id' => 1,
       ),
     ),
+    'check_permissions' => TRUE,
   );
 
   try{
index 2bf7e806ae8c383694c893820aa0039f655c4f39..a7a361e3384dd21e65430fb9ecd36aca1ee2e16a 100755 (executable)
@@ -3025,7 +3025,7 @@ AND    ( TABLE_NAME LIKE 'civicrm_value_%' )
    *   $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'));
    */
-  public function setupACL() {
+  public function setupACL($isProfile = FALSE) {
     global $_REQUEST;
     $_REQUEST = $this->_params;
 
@@ -3047,36 +3047,49 @@ AND    ( TABLE_NAME LIKE 'civicrm_value_%' )
 
     CRM_Core_DAO::executeQuery("
     INSERT INTO civicrm_acl_entity_role (
-    `acl_role_id`, `entity_table`, `entity_id`
-    ) VALUES (55, 'civicrm_group', {$this->_permissionedGroup});
+    `acl_role_id`, `entity_table`, `entity_id`, `is_active`
+    ) VALUES (55, 'civicrm_group', {$this->_permissionedGroup}, 1);
     ");
 
-    CRM_Core_DAO::executeQuery("
-    INSERT INTO civicrm_acl (
-    `name`, `entity_table`, `entity_id`, `operation`, `object_table`, `object_id`, `is_active`
-    )
-    VALUES (
-    'view picked', 'civicrm_group', $this->_permissionedGroup , 'Edit', 'civicrm_saved_search', {$this->_permissionedGroup}, 1
-    );
-    ");
+    if ($isProfile) {
+      CRM_Core_DAO::executeQuery("
+      INSERT INTO civicrm_acl (
+      `name`, `entity_table`, `entity_id`, `operation`, `object_table`, `object_id`, `is_active`
+      )
+      VALUES (
+      'view picked', 'civicrm_acl_role', 55, 'Edit', 'civicrm_uf_group', 0, 1
+      );
+      ");
+    }
+    else {
+      CRM_Core_DAO::executeQuery("
+      INSERT INTO civicrm_acl (
+      `name`, `entity_table`, `entity_id`, `operation`, `object_table`, `object_id`, `is_active`
+      )
+      VALUES (
+      'view picked', 'civicrm_group', $this->_permissionedGroup , 'Edit', 'civicrm_saved_search', {$this->_permissionedGroup}, 1
+      );
+      ");
+
+      CRM_Core_DAO::executeQuery("
+      INSERT INTO civicrm_acl (
+      `name`, `entity_table`, `entity_id`, `operation`, `object_table`, `object_id`, `is_active`
+      )
+      VALUES (
+      'view picked', 'civicrm_group',  $this->_permissionedGroup, 'Edit', 'civicrm_saved_search', {$this->_permissionedDisabledGroup}, 1
+      );
+      ");
+      //flush cache
+      CRM_ACL_BAO_Cache::resetCache();
+      CRM_Contact_BAO_Group::getPermissionClause(TRUE);
+      CRM_ACL_API::groupPermission('whatever', 9999, NULL, 'civicrm_saved_search', NULL, NULL, TRUE);
+    }
 
-    CRM_Core_DAO::executeQuery("
-    INSERT INTO civicrm_acl (
-    `name`, `entity_table`, `entity_id`, `operation`, `object_table`, `object_id`, `is_active`
-    )
-    VALUES (
-    'view picked', 'civicrm_group',  $this->_permissionedGroup, 'Edit', 'civicrm_saved_search', {$this->_permissionedDisabledGroup}, 1
-    );
-    ");
     $this->_loggedInUser = CRM_Core_Session::singleton()->get('userID');
     $this->callAPISuccess('group_contact', 'create', array(
       'group_id' => $this->_permissionedGroup,
       'contact_id' => $this->_loggedInUser,
     ));
-    //flush cache
-    CRM_ACL_BAO_Cache::resetCache();
-    CRM_Contact_BAO_Group::getPermissionClause(TRUE);
-    CRM_ACL_API::groupPermission('whatever', 9999, NULL, 'civicrm_saved_search', NULL, NULL, TRUE);
   }
 
   /**
index c21ef3531baf3ae6152c1faad7d279938b468a56..9d4b01a27a972620104e64ee9ee049adfbf35d67 100644 (file)
@@ -196,6 +196,7 @@ class api_v3_UFFieldTest extends CiviUnitTestCase {
       'uf_group_id' => $this->_ufGroupId,
       'option.autoweight' => FALSE,
       'values' => $baseFields,
+      'check_permissions' => TRUE,
     );
 
     $result = $this->callAPIAndDocument('uf_field', 'replace', $params, __FUNCTION__, __FILE__);
@@ -217,4 +218,43 @@ class api_v3_UFFieldTest extends CiviUnitTestCase {
     }
   }
 
+  /**
+   * Check Profile API permission without ACL.
+   */
+  public function testProfilesWithoutACL() {
+    $this->createLoggedInUser();
+    $baseFields[] = array(
+      'field_name' => 'first_name',
+      'field_type' => 'Contact',
+      'visibility' => 'Public Pages and Listings',
+      'weight' => 3,
+      'label' => 'Test First Name',
+      'is_searchable' => 1,
+      'is_active' => 1,
+    );
+    CRM_Core_Config::singleton()->userPermissionClass->permissions = array('access CiviCRM');
+    $params = array(
+      'uf_group_id' => $this->_ufGroupId,
+      'option.autoweight' => FALSE,
+      'values' => $baseFields,
+      'check_permissions' => TRUE,
+    );
+    $this->_loggedInUser = CRM_Core_Session::singleton()->get('userID');
+    $result = $this->callAPIFailure('uf_field', 'replace', $params);
+  }
+
+  /**
+   * Check Profile ACL for API permission.
+   */
+  public function testACLPermissionforProfiles() {
+    $this->createLoggedInUser();
+    $this->_permissionedGroup = $this->groupCreate(array(
+      'title' => 'Edit Profiles',
+      'is_active' => 1,
+      'name' => 'edit-profiles',
+    ));
+    $this->setupACL(TRUE);
+    $this->testReplaceUFFields();
+  }
+
 }