Commit | Line | Data |
---|---|---|
301906ab | 1 | <?php |
2 | /* | |
3 | +--------------------------------------------------------------------+ | |
7d61e75f | 4 | | Copyright CiviCRM LLC. All rights reserved. | |
301906ab | 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 | | |
301906ab | 9 | +--------------------------------------------------------------------+ |
10 | */ | |
11 | ||
12 | /** | |
13 | * Trait PriceSetTrait | |
14 | * | |
15 | * Trait for working with Price Sets in tests | |
16 | */ | |
6d2e7dc0 | 17 | trait CRMTraits_Profile_ProfileTrait { |
301906ab | 18 | |
19 | /** | |
6d2e7dc0 | 20 | * Add a profile to a contribution page. |
301906ab | 21 | * |
6d2e7dc0 | 22 | * @param array $joinParams |
23 | * Must contain entity_id at minimum. | |
24 | * @param array $ufGroupParams | |
301906ab | 25 | */ |
6d2e7dc0 | 26 | protected function createJoinedProfile($joinParams, $ufGroupParams = []) { |
f736929b | 27 | $profileID = $this->createProfile($ufGroupParams); |
6d2e7dc0 | 28 | $joinParams = array_merge([ |
f736929b | 29 | 'uf_group_id' => $profileID, |
6d2e7dc0 | 30 | 'entity_table' => 'civicrm_contribution_page', |
31 | 'weight' => 1, | |
32 | ], $joinParams); | |
33 | if (empty($joinParams['module'])) { | |
34 | $joinParams['module'] = $joinParams['entity_table'] === 'civicrm_event' ? 'CiviEvent' : 'CiviContribute'; | |
35 | } | |
36 | if ($joinParams['module'] !== 'CiviContribute' && empty($joinParams['module_data'])) { | |
37 | $params['module_data'] = [$joinParams['module'] => []]; | |
301906ab | 38 | } |
6d2e7dc0 | 39 | $this->callAPISuccess('UFJoin', 'create', $joinParams); |
40 | } | |
41 | ||
42 | /** | |
43 | * Create a profile. | |
44 | * | |
45 | * @param $ufGroupParams | |
f736929b | 46 | * |
47 | * @return int | |
6d2e7dc0 | 48 | */ |
49 | protected function createProfile($ufGroupParams) { | |
50 | $profile = $this->callAPISuccess('UFGroup', 'create', array_merge([ | |
51 | 'group_type' => 'Contact', | |
52 | 'title' => 'Back end title', | |
53 | 'frontend_title' => 'Public title', | |
54 | 'name' => 'our profile', | |
55 | ||
56 | ], $ufGroupParams)); | |
57 | $this->ids['UFGroup'][$profile['values'][$profile['id']]['name']] = $profile['id']; | |
58 | ||
59 | $this->callAPISuccess('UFField', 'create', [ | |
60 | 'uf_group_id' => $profile['id'], | |
61 | 'field_name' => 'first_name', | |
62 | ]); | |
f736929b | 63 | return $profile['id']; |
64 | } | |
65 | ||
66 | /** | |
67 | * Ensure we don't have a profile with the id or one to ensure that we are not casting an array to it. | |
68 | */ | |
69 | protected function eliminateUFGroupOne() { | |
70 | $profileID = $this->createProfile(['name' => 'dummy_for_removing']); | |
71 | CRM_Core_DAO::executeQuery("UPDATE civicrm_uf_join SET uf_group_id = $profileID WHERE uf_group_id = 1"); | |
72 | CRM_Core_DAO::executeQuery("UPDATE civicrm_uf_field SET uf_group_id = $profileID WHERE uf_group_id = 1"); | |
73 | CRM_Core_DAO::executeQuery('UPDATE civicrm_uf_group SET id = 900 WHERE id = 1'); | |
74 | $this->ids['UFGroup']['dummy'] = $profileID; | |
75 | } | |
76 | ||
77 | /** | |
78 | * Bring back UF group one. | |
79 | */ | |
80 | protected function restoreUFGroupOne() { | |
81 | if (!isset($this->ids['UFGroup']['dummy'])) { | |
82 | return; | |
83 | } | |
84 | $profileID = $this->ids['UFGroup']['dummy']; | |
85 | CRM_Core_DAO::executeQuery('UPDATE civicrm_uf_group SET id = 1 WHERE id = 900'); | |
86 | CRM_Core_DAO::executeQuery("UPDATE civicrm_uf_join SET uf_group_id = 1 WHERE uf_group_id = $profileID"); | |
87 | CRM_Core_DAO::executeQuery("UPDATE civicrm_uf_field SET uf_group_id = 1 WHERE uf_group_id = $profileID"); | |
301906ab | 88 | } |
89 | ||
90 | } |