CRM-16526 CIVI-3 Added unit tests for financial type and membership type
authorEdsel <edsel.lopez@jmaconsulting.biz>
Mon, 22 Feb 2016 13:00:43 +0000 (18:30 +0530)
committerEdsel <edsel.lopez@jmaconsulting.biz>
Tue, 1 Mar 2016 06:49:12 +0000 (12:19 +0530)
----------------------------------------
* CRM-16526: ACLs for Financial Types
  https://issues.civicrm.org/jira/browse/CRM-16526

tests/phpunit/CRM/Financial/BAO/FinancialTypeTest.php

index 05ea8be0ed6c71f944b373ccb2666d704cbcb76c..39f8bb35f82a43bccc6e84658d24451fab17887b 100644 (file)
@@ -33,6 +33,7 @@ class CRM_Financial_BAO_FinancialTypeTest extends CiviUnitTestCase {
 
   public function setUp() {
     parent::setUp();
+    $this->_orgContactID = $this->organizationCreate();
   }
 
   public function teardown() {
@@ -121,4 +122,81 @@ class CRM_Financial_BAO_FinancialTypeTest extends CiviUnitTestCase {
     $this->assertEquals(empty($result), TRUE, 'Verify financial types record deletion.');
   }
 
+  /**
+   * Set ACLs for Financial Types()
+   */
+  public function setACL() {
+    CRM_Core_BAO_Setting::setItem(array('acl_financial_type' => 1), NULL, 'contribution_invoice_settings');
+  }
+
+  /**
+   * Check method testgetAvailableFinancialTypes()
+   */
+  public function testgetAvailableFinancialTypes() {
+    $this->setACL();
+    $config = &CRM_Core_Config::singleton();
+    $config->userPermissionClass->permissions = array(
+      'view contributions of type Donation',
+      'view contributions of type Member Dues',
+    );
+    CRM_Financial_BAO_FinancialType::getAvailableFinancialTypes($types);
+    $expectedResult = array(
+      1 => "Donation",
+      2 => "Member Dues",
+    );
+    $this->assertEquals($expectedResult, $types, 'Verify that only certain financial types can be retrieved');
+    CRM_Financial_BAO_FinancialType::$_availableFinancialTypes = NULL;
+    $config->userPermissionClass->permissions = array(
+      'view contributions of type Donation',
+    );
+    unset($expectedResult[2]);
+    CRM_Financial_BAO_FinancialType::getAvailableFinancialTypes($types);
+    $this->assertEquals($expectedResult, $types, 'Verify that removing permission for a financial type restricts the available financial types');
+  }
+
+  /**
+   * Check method testgetAvailableMembershipTypes()
+   */
+  public function testgetAvailableMembershipTypes() {
+    // Create Membership types
+    $ids = array();
+    $params = array(
+      'name' => 'Type One',
+      'domain_id' => 1,
+      'minimum_fee' => 10,
+      'duration_unit' => 'year',
+      'member_of_contact_id' => $this->_orgContactID,
+      'period_type' => 'fixed',
+      'duration_interval' => 1,
+      'financial_type_id' => 1,
+      'visibility' => 'Public',
+      'is_active' => 1,
+    );
+
+    $membershipType = CRM_Member_BAO_MembershipType::add($params, $ids);
+    // Add another
+    $params['name'] = 'Type Two';
+    $params['financial_type_id'] = 2;
+    $membershipType = CRM_Member_BAO_MembershipType::add($params, $ids);
+
+    $this->setACL();
+    $config = &CRM_Core_Config::singleton();
+    $config->userPermissionClass->permissions = array(
+      'view contributions of type Donation',
+      'view contributions of type Member Dues',
+    );
+    CRM_Financial_BAO_FinancialType::getAvailableMembershipTypes($types);
+    $expectedResult = array(
+      1 => "Type One",
+      2 => "Type Two",
+    );
+    $this->assertEquals($expectedResult, $types, 'Verify that only certain membership types can be retrieved');
+    $config->userPermissionClass->permissions = array(
+      'view contributions of type Donation',
+    );
+    unset($expectedResult[2]);
+    CRM_Financial_BAO_FinancialType::getAvailableMembershipTypes($types);
+    $this->assertEquals($expectedResult, $types, 'Verify that removing permission for a financial type restricts the available membership types');
+  }
+
 }