public function setACL()
 {
     CRM_Financial_BAO_FinancialType::$_availableFinancialTypes = array();
     CRM_Financial_BAO_FinancialType::$_statusACLFt = array();
     $params = array('domain_id' => 1, 'contribution_invoice_settings' => array('acl_financial_type' => 1));
     $this->callAPISuccess('setting', 'create', $params);
 }
 /**
  * Flush statics relating to financial type.
  */
 protected function flushFinancialTypeStatics()
 {
     if (isset(\Civi::$statics['CRM_Financial_BAO_FinancialType'])) {
         unset(\Civi::$statics['CRM_Financial_BAO_FinancialType']);
     }
     if (isset(\Civi::$statics['CRM_Contribute_PseudoConstant'])) {
         unset(\Civi::$statics['CRM_Contribute_PseudoConstant']);
     }
     CRM_Contribute_PseudoConstant::flush('financialType');
     CRM_Contribute_PseudoConstant::flush('membershipType');
     // Pseudoconstants may be saved to the cache table.
     CRM_Core_DAO::executeQuery("TRUNCATE civicrm_cache");
     CRM_Financial_BAO_FinancialType::$_statusACLFt = array();
     CRM_Financial_BAO_FinancialType::$_availableFinancialTypes = NULL;
 }
 /**
  * Check method testcheckPermissionedLineItems()
  */
 public function testcheckPermissionedLineItems()
 {
     $contactId = Contact::createIndividual();
     $paramsSet['title'] = 'Price Set' . substr(sha1(rand()), 0, 4);
     $paramsSet['name'] = CRM_Utils_String::titleToVar($paramsSet['title']);
     $paramsSet['is_active'] = TRUE;
     $paramsSet['financial_type_id'] = 1;
     $paramsSet['extends'] = 1;
     $priceset = CRM_Price_BAO_PriceSet::create($paramsSet);
     $priceSetId = $priceset->id;
     //Checking for priceset added in the table.
     $this->assertDBCompareValue('CRM_Price_BAO_PriceSet', $priceSetId, 'title', 'id', $paramsSet['title'], 'Check DB for created priceset');
     $paramsField = array('label' => 'Price Field', 'name' => CRM_Utils_String::titleToVar('Price Field'), 'html_type' => 'CheckBox', 'option_label' => array('1' => 'Price Field 1', '2' => 'Price Field 2'), 'option_value' => array('1' => 100, '2' => 200), 'option_name' => array('1' => 'Price Field 1', '2' => 'Price Field 2'), 'option_weight' => array('1' => 1, '2' => 2), 'option_amount' => array('1' => 100, '2' => 200), 'is_display_amounts' => 1, 'weight' => 1, 'options_per_line' => 1, 'is_active' => array('1' => 1, '2' => 1), 'price_set_id' => $priceset->id, 'is_enter_qty' => 1, 'financial_type_id' => 1);
     $priceField = CRM_Price_BAO_PriceField::create($paramsField);
     $priceFields = $this->callAPISuccess('PriceFieldValue', 'get', array('price_field_id' => $priceField->id));
     $contributionParams = array('total_amount' => 300, 'currency' => 'USD', 'contact_id' => $contactId, 'financial_type_id' => 1, 'contribution_status_id' => 1);
     foreach ($priceFields['values'] as $key => $priceField) {
         $lineItems[1][$key] = array('price_field_id' => $priceField['price_field_id'], 'price_field_value_id' => $priceField['id'], 'label' => $priceField['label'], 'field_title' => $priceField['label'], 'qty' => 1, 'unit_price' => $priceField['amount'], 'line_total' => $priceField['amount'], 'financial_type_id' => $priceField['financial_type_id']);
     }
     $contributionParams['line_item'] = $lineItems;
     $contributions = CRM_Contribute_BAO_Contribution::create($contributionParams);
     CRM_Financial_BAO_FinancialType::$_statusACLFt = array();
     $this->setACL();
     $this->setPermissions(array('view contributions of type Member Dues'));
     try {
         CRM_Financial_BAO_FinancialType::checkPermissionedLineItems($contributions->id, 'view');
         $this->fail("Missed expected exception");
     } catch (Exception $e) {
         $this->assertEquals("A fatal error was triggered: You do not have permission to access this page.", $e->getMessage());
     }
     $this->setPermissions(array('view contributions of type Donation'));
     $perm = CRM_Financial_BAO_FinancialType::checkPermissionedLineItems($contributions->id, 'view');
     $this->assertEquals($perm, TRUE, 'Verify that lineitems now have permission.');
 }