Preliminary cleanup - use CRM_Core_Exception, fix comments
[civicrm-core.git] / tests / phpunit / CRMTraits / Profile / ProfileTrait.php
1 <?php
2 /*
3 +--------------------------------------------------------------------+
4 | CiviCRM version 5 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2019 |
7 +--------------------------------------------------------------------+
8 | This file is a part of CiviCRM. |
9 | |
10 | CiviCRM is free software; you can copy, modify, and distribute it |
11 | under the terms of the GNU Affero General Public License |
12 | Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
13 | |
14 | CiviCRM is distributed in the hope that it will be useful, but |
15 | WITHOUT ANY WARRANTY; without even the implied warranty of |
16 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
17 | See the GNU Affero General Public License for more details. |
18 | |
19 | You should have received a copy of the GNU Affero General Public |
20 | License and the CiviCRM Licensing Exception along |
21 | with this program; if not, contact CiviCRM LLC |
22 | at info[AT]civicrm[DOT]org. If you have questions about the |
23 | GNU Affero General Public License or the licensing of CiviCRM, |
24 | see the CiviCRM license FAQ at http://civicrm.org/licensing |
25 +--------------------------------------------------------------------+
26 */
27
28 /**
29 * Trait PriceSetTrait
30 *
31 * Trait for working with Price Sets in tests
32 */
33 trait CRMTraits_Financial_PriceSetTrait {
34
35 /**
36 * Create a contribution with 2 line items.
37 *
38 * This also involves creating t
39 *
40 * @param $params
41 * @param array $lineItemFinancialTypes
42 * Financial Types, if an override is intended.
43 */
44 protected function createContributionWithTwoLineItemsAgainstPriceSet($params, $lineItemFinancialTypes = []) {
45 $params = array_merge(['total_amount' => 300, 'financial_type_id' => 'Donation'], $params);
46 $priceFields = $this->createPriceSet('contribution');
47 foreach ($priceFields['values'] as $key => $priceField) {
48 $financialTypeID = (!empty($lineItemFinancialTypes) ? array_shift($lineItemFinancialTypes) : $priceField['financial_type_id']);
49 $params['line_items'][]['line_item'][$key] = [
50 'price_field_id' => $priceField['price_field_id'],
51 'price_field_value_id' => $priceField['id'],
52 'label' => $priceField['label'],
53 'field_title' => $priceField['label'],
54 'qty' => 1,
55 'unit_price' => $priceField['amount'],
56 'line_total' => $priceField['amount'],
57 'financial_type_id' => $financialTypeID,
58 'entity_table' => 'civicrm_contribution',
59 ];
60 }
61 $this->callAPISuccess('order', 'create', $params);
62 }
63
64 }