Merge pull request #18774 from civicrm/5.31
[civicrm-core.git] / tests / phpunit / CRMTraits / Financial / PriceSetTrait.php
CommitLineData
53666099 1<?php
2/*
3 +--------------------------------------------------------------------+
7d61e75f 4 | Copyright CiviCRM LLC. All rights reserved. |
53666099 5 | |
7d61e75f
TO
6 | This work is published under the GNU AGPLv3 license with some |
7 | permitted exceptions and without any warranty. For full license |
8 | and copyright information, see https://civicrm.org/licensing |
53666099 9 +--------------------------------------------------------------------+
10 */
11
12/**
13 * Trait PriceSetTrait
14 *
15 * Trait for working with Price Sets in tests
16 */
17trait CRMTraits_Financial_PriceSetTrait {
18
19 /**
20 * Create a contribution with 2 line items.
21 *
22 * This also involves creating t
23 *
24 * @param $params
faba82fc 25 * @param array $lineItemFinancialTypes
26 * Financial Types, if an override is intended.
53666099 27 */
faba82fc 28 protected function createContributionWithTwoLineItemsAgainstPriceSet($params, $lineItemFinancialTypes = []) {
af595ac2 29 $params = array_merge(['total_amount' => 300, 'financial_type_id' => 'Donation', 'contribution_status_id' => 'Pending'], $params);
53666099 30 $priceFields = $this->createPriceSet('contribution');
31 foreach ($priceFields['values'] as $key => $priceField) {
faba82fc 32 $financialTypeID = (!empty($lineItemFinancialTypes) ? array_shift($lineItemFinancialTypes) : $priceField['financial_type_id']);
53666099 33 $params['line_items'][]['line_item'][$key] = [
34 'price_field_id' => $priceField['price_field_id'],
35 'price_field_value_id' => $priceField['id'],
36 'label' => $priceField['label'],
37 'field_title' => $priceField['label'],
38 'qty' => 1,
39 'unit_price' => $priceField['amount'],
40 'line_total' => $priceField['amount'],
faba82fc 41 'financial_type_id' => $financialTypeID,
53666099 42 'entity_table' => 'civicrm_contribution',
43 ];
44 }
af595ac2 45 $order = $this->callAPISuccess('Order', 'create', $params);
46 $this->callAPISuccess('Payment', 'create', ['contribution_id' => $order['id'], 'total_amount' => $params['total_amount']]);
53666099 47 }
48
49}