Merge pull request #1277 from totten/master-reporttestcase
[civicrm-core.git] / tests / phpunit / CiviTest / PCP.php
CommitLineData
6a488035
TO
1<?php
2class PCPBlock extends PHPUnit_Framework_Testcase {
3 /**
4 * Helper function to create a PCP Block for Contribution Page
5 *
6 * @param int $contributionPageId - id of the Contribution Page
7 * to be deleted
8 * @return array of created pcp block
9 *
10 */
11 function create($contributionPageId) {
12 $profileParams = array(
13 'group_type' => 'Individual,Contact',
14 'title' => 'Test Supprorter Profile',
15 'help_pre' => 'Profle to PCP Contribution',
16 'is_active' => 1,
17 'is_cms_user' => 2,
18 );
19
20 $ufGroup = civicrm_api('uf_group', 'create', $profileParams);
21 $profileId = $ufGroup['id'];
22
23 $fieldsParams = array(
24 array(
25 'field_name' => 'first_name',
26 'field_type' => 'Individual',
27 'visibility' => 'Public Pages and Listings',
28 'weight' => 1,
29 'label' => 'First Name',
30 'is_required' => 1,
31 'is_active' => 1,
32 ),
33 array(
34 'field_name' => 'last_name',
35 'field_type' => 'Individual',
36 'visibility' => 'Public Pages and Listings',
37 'weight' => 2,
38 'label' => 'Last Name',
39 'is_required' => 1,
40 'is_active' => 1,
41 ),
42 array(
43 'field_name' => 'email',
44 'field_type' => 'Contact',
45 'visibility' => 'Public Pages and Listings',
46 'weight' => 3,
47 'label' => 'Email',
48 'is_required' => 1,
49 'is_active' => 1,
50 ),
51 );
52
53 foreach ($fieldsParams as $value) {
54 // we assume api v3.
55 $value['version'] = 3;
56 $value['uf_group_id'] = $profileId;
57 $ufField = civicrm_api('uf_field', 'create', $value);
58 }
59
60 $joinParams = array(
61 'module' => 'Profile',
62 'entity_table' => 'civicrm_contribution_page',
63 'entity_id' => 1,
64 'weight' => 1,
65 'uf_group_id' => $profileId,
66 'is_active' => 1,
67 );
68 $ufJoin = civicrm_api('uf_join', 'create', $joinParams);
69
70 $params = array(
71 'entity_table' => 'civicrm_contribution_page',
72 'entity_id' => $contributionPageId,
73 'supporter_profile_id' => $profileId,
74 'is_approval_needed' => 0,
75 'is_tellfriend_enabled' => 0,
76 'tellfriend_limit' => 0,
77 'link_text' => 'Create your own Personal Campaign Page!',
78 'is_active' => 1,
79 'notify_email' => 'info@civicrm.org',
80 );
81 require_once 'CRM/Contribute/BAO/PCP.php';
82 $blockPCP = CRM_Contribute_BAO_PCP::add($params);
83 return array('blockId' => $blockPCP->id, 'profileId' => $profileId);
84 }
85
86 /**
87 * Helper function to delete a PCP related stuff viz. Profile, PCP Block Entry
88 *
89 * @param array key value pair
90 * pcpBlockId - id of the PCP Block Id, profileID - id of Supporter Profile
91 * to be deleted
92 * @return boolean true if success, false otherwise
93 *
94 */
95 function delete($params) {
96
97 $delete_params = array('id' => $params['profileId']);
98 $resulProfile = civicrm_api('uf_group', 'delete', $delete_params);
99
100
101 require_once 'CRM/Contribute/DAO/PCPBlock.php';
102 $dao = new CRM_Contribute_DAO_PCPBlock();
103 $dao->id = $params['blockId'];
104 if ($dao->find(TRUE)) {
105 $resultBlock = $dao->delete();
106 }
107 if ($id = CRM_Utils_Array::value('pcpId', $params)) {
108 require_once 'CRM/Contribute/BAO/PCP.php';
109 CRM_Contribute_BAO_PCP::delete($id);
110 }
111 if ($resulProfile && $resultBlock) {
112 return TRUE;
113 }
114 return FALSE;
115 }
116}