2 class PCPBlock
extends PHPUnit_Framework_Testcase
{
4 * Helper function to create a PCP Block for Contribution Page
6 * @param int $contributionPageId - id of the Contribution Page
8 * @return array of created pcp block
11 function create($contributionPageId) {
12 $profileParams = array(
13 'group_type' => 'Individual,Contact',
14 'title' => 'Test Supprorter Profile',
15 'help_pre' => 'Profle to PCP Contribution',
20 $ufGroup = civicrm_api('uf_group', 'create', $profileParams);
21 $profileId = $ufGroup['id'];
23 $fieldsParams = array(
25 'field_name' => 'first_name',
26 'field_type' => 'Individual',
27 'visibility' => 'Public Pages and Listings',
29 'label' => 'First Name',
34 'field_name' => 'last_name',
35 'field_type' => 'Individual',
36 'visibility' => 'Public Pages and Listings',
38 'label' => 'Last Name',
43 'field_name' => 'email',
44 'field_type' => 'Contact',
45 'visibility' => 'Public Pages and Listings',
53 foreach ($fieldsParams as $value) {
55 $value['version'] = 3;
56 $value['uf_group_id'] = $profileId;
57 $ufField = civicrm_api('uf_field', 'create', $value);
61 'module' => 'Profile',
62 'entity_table' => 'civicrm_contribution_page',
65 'uf_group_id' => $profileId,
68 $ufJoin = civicrm_api('uf_join', 'create', $joinParams);
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!',
79 'notify_email' => 'info@civicrm.org',
81 require_once 'CRM/Contribute/BAO/PCP.php';
82 $blockPCP = CRM_Contribute_BAO_PCP
::add($params);
83 return array('blockId' => $blockPCP->id
, 'profileId' => $profileId);
87 * Helper function to delete a PCP related stuff viz. Profile, PCP Block Entry
89 * @param array key value pair
90 * pcpBlockId - id of the PCP Block Id, profileID - id of Supporter Profile
92 * @return boolean true if success, false otherwise
95 function delete($params) {
97 $delete_params = array('id' => $params['profileId']);
98 $resulProfile = civicrm_api('uf_group', 'delete', $delete_params);
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();
107 if ($id = CRM_Utils_Array
::value('pcpId', $params)) {
108 require_once 'CRM/Contribute/BAO/PCP.php';
109 CRM_Contribute_BAO_PCP
::delete($id);
111 if ($resulProfile && $resultBlock) {