Update copyright date for 2020
[civicrm-core.git] / tests / phpunit / CRMTraits / Financial / PriceSetTrait.php
CommitLineData
53666099 1<?php
2/*
3 +--------------------------------------------------------------------+
4 | CiviCRM version 5 |
5 +--------------------------------------------------------------------+
f299f7db 6 | Copyright CiviCRM LLC (c) 2004-2020 |
53666099 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 */
33trait CRMTraits_Financial_PriceSetTrait {
34
35 /**
36 * Create a contribution with 2 line items.
37 *
38 * This also involves creating t
39 *
40 * @param $params
faba82fc 41 * @param array $lineItemFinancialTypes
42 * Financial Types, if an override is intended.
53666099 43 */
faba82fc 44 protected function createContributionWithTwoLineItemsAgainstPriceSet($params, $lineItemFinancialTypes = []) {
af595ac2 45 $params = array_merge(['total_amount' => 300, 'financial_type_id' => 'Donation', 'contribution_status_id' => 'Pending'], $params);
53666099 46 $priceFields = $this->createPriceSet('contribution');
47 foreach ($priceFields['values'] as $key => $priceField) {
faba82fc 48 $financialTypeID = (!empty($lineItemFinancialTypes) ? array_shift($lineItemFinancialTypes) : $priceField['financial_type_id']);
53666099 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'],
faba82fc 57 'financial_type_id' => $financialTypeID,
53666099 58 'entity_table' => 'civicrm_contribution',
59 ];
60 }
af595ac2 61 $order = $this->callAPISuccess('Order', 'create', $params);
62 $this->callAPISuccess('Payment', 'create', ['contribution_id' => $order['id'], 'total_amount' => $params['total_amount']]);
53666099 63 }
64
65}