3 +--------------------------------------------------------------------+
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2019 |
7 +--------------------------------------------------------------------+
8 | This file is a part of CiviCRM. |
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. |
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. |
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 +--------------------------------------------------------------------+
31 * Trait for working with Price Sets in tests
33 trait CRMTraits_Profile_ProfileTrait
{
36 * Add a profile to a contribution page.
38 * @param array $joinParams
39 * Must contain entity_id at minimum.
40 * @param array $ufGroupParams
42 protected function createJoinedProfile($joinParams, $ufGroupParams = []) {
43 $profileID = $this->createProfile($ufGroupParams);
44 $joinParams = array_merge([
45 'uf_group_id' => $profileID,
46 'entity_table' => 'civicrm_contribution_page',
49 if (empty($joinParams['module'])) {
50 $joinParams['module'] = $joinParams['entity_table'] === 'civicrm_event' ?
'CiviEvent' : 'CiviContribute';
52 if ($joinParams['module'] !== 'CiviContribute' && empty($joinParams['module_data'])) {
53 $params['module_data'] = [$joinParams['module'] => []];
55 $this->callAPISuccess('UFJoin', 'create', $joinParams);
61 * @param $ufGroupParams
65 protected function createProfile($ufGroupParams) {
66 $profile = $this->callAPISuccess('UFGroup', 'create', array_merge([
67 'group_type' => 'Contact',
68 'title' => 'Back end title',
69 'frontend_title' => 'Public title',
70 'name' => 'our profile',
73 $this->ids
['UFGroup'][$profile['values'][$profile['id']]['name']] = $profile['id'];
75 $this->callAPISuccess('UFField', 'create', [
76 'uf_group_id' => $profile['id'],
77 'field_name' => 'first_name',
79 return $profile['id'];
83 * Ensure we don't have a profile with the id or one to ensure that we are not casting an array to it.
85 protected function eliminateUFGroupOne() {
86 $profileID = $this->createProfile(['name' => 'dummy_for_removing']);
87 CRM_Core_DAO
::executeQuery("UPDATE civicrm_uf_join SET uf_group_id = $profileID WHERE uf_group_id = 1");
88 CRM_Core_DAO
::executeQuery("UPDATE civicrm_uf_field SET uf_group_id = $profileID WHERE uf_group_id = 1");
89 CRM_Core_DAO
::executeQuery('UPDATE civicrm_uf_group SET id = 900 WHERE id = 1');
90 $this->ids
['UFGroup']['dummy'] = $profileID;
94 * Bring back UF group one.
96 protected function restoreUFGroupOne() {
97 if (!isset($this->ids
['UFGroup']['dummy'])) {
100 $profileID = $this->ids
['UFGroup']['dummy'];
101 CRM_Core_DAO
::executeQuery('UPDATE civicrm_uf_group SET id = 1 WHERE id = 900');
102 CRM_Core_DAO
::executeQuery("UPDATE civicrm_uf_join SET uf_group_id = 1 WHERE uf_group_id = $profileID");
103 CRM_Core_DAO
::executeQuery("UPDATE civicrm_uf_field SET uf_group_id = 1 WHERE uf_group_id = $profileID");