3 +--------------------------------------------------------------------+
4 | Copyright CiviCRM LLC. All rights reserved. |
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 |
9 +--------------------------------------------------------------------+
15 * Trait for working with Price Sets in tests
17 trait CRMTraits_Profile_ProfileTrait
{
20 * Add a profile to a contribution page.
22 * @param array $joinParams
23 * Must contain entity_id at minimum.
24 * @param array $ufGroupParams
26 protected function createJoinedProfile($joinParams, $ufGroupParams = []) {
27 $profileID = $this->createProfile($ufGroupParams);
28 $joinParams = array_merge([
29 'uf_group_id' => $profileID,
30 'entity_table' => 'civicrm_contribution_page',
33 if (empty($joinParams['module'])) {
34 $joinParams['module'] = $joinParams['entity_table'] === 'civicrm_event' ?
'CiviEvent' : 'CiviContribute';
36 if ($joinParams['module'] !== 'CiviContribute' && empty($joinParams['module_data'])) {
37 $params['module_data'] = [$joinParams['module'] => []];
39 $this->callAPISuccess('UFJoin', 'create', $joinParams);
45 * @param $ufGroupParams
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',
57 $this->ids
['UFGroup'][$profile['values'][$profile['id']]['name']] = $profile['id'];
59 $this->callAPISuccess('UFField', 'create', [
60 'uf_group_id' => $profile['id'],
61 'field_name' => 'first_name',
63 return $profile['id'];
67 * Ensure we don't have a profile with the id or one to ensure that we are not casting an array to it.
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;
78 * Bring back UF group one.
80 protected function restoreUFGroupOne() {
81 if (!isset($this->ids
['UFGroup']['dummy'])) {
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");