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 +--------------------------------------------------------------------+
13 * Test class for CRM_PCP_BAO_PCPTest BAO
18 class CRM_PCP_BAO_PCPTest
extends CiviUnitTestCase
{
20 use CRMTraits_PCP_PCPTestTrait
;
23 * Clean up after test.
25 * @throws \CRM_Core_Exception
27 public function tearDown() {
28 $this->quickCleanUpFinancialEntities();
32 public function testAddPCPBlock() {
34 $params = $this->pcpBlockParams();
35 $pcpBlock = CRM_PCP_BAO_PCPBlock
::create($params);
37 $this->assertInstanceOf('CRM_PCP_DAO_PCPBlock', $pcpBlock, 'Check for created object');
38 $this->assertEquals($params['entity_table'], $pcpBlock->entity_table
, 'Check for entity table.');
39 $this->assertEquals($params['entity_id'], $pcpBlock->entity_id
, 'Check for entity id.');
40 $this->assertEquals($params['supporter_profile_id'], $pcpBlock->supporter_profile_id
, 'Check for profile id .');
41 $this->assertEquals($params['is_approval_needed'], $pcpBlock->is_approval_needed
, 'Check for approval needed .');
42 $this->assertEquals($params['is_tellfriend_enabled'], $pcpBlock->is_tellfriend_enabled
, 'Check for tell friend on.');
43 $this->assertEquals($params['tellfriend_limit'], $pcpBlock->tellfriend_limit
, 'Check for tell friend limit .');
44 $this->assertEquals($params['link_text'], $pcpBlock->link_text
, 'Check for link text.');
45 $this->assertEquals($params['is_active'], $pcpBlock->is_active
, 'Check for is_active.');
48 public function testAddPCP() {
49 $blockParams = $this->pcpBlockParams();
50 $pcpBlock = CRM_PCP_BAO_PCPBlock
::create($blockParams);
52 $params = $this->pcpParams();
53 $params['pcp_block_id'] = $pcpBlock->id
;
55 $pcp = CRM_PCP_BAO_PCP
::create($params);
57 $this->assertInstanceOf('CRM_PCP_DAO_PCP', $pcp, 'Check for created object');
58 $this->assertEquals($params['contact_id'], $pcp->contact_id
, 'Check for entity table.');
59 $this->assertEquals($params['status_id'], $pcp->status_id
, 'Check for status.');
60 $this->assertEquals($params['title'], $pcp->title
, 'Check for title.');
61 $this->assertEquals($params['intro_text'], $pcp->intro_text
, 'Check for intro_text.');
62 $this->assertEquals($params['page_text'], $pcp->page_text
, 'Check for page_text.');
63 $this->assertEquals($params['donate_link_text'], $pcp->donate_link_text
, 'Check for donate_link_text.');
64 $this->assertEquals($params['is_thermometer'], $pcp->is_thermometer
, 'Check for is_thermometer.');
65 $this->assertEquals($params['is_honor_roll'], $pcp->is_honor_roll
, 'Check for is_honor_roll.');
66 $this->assertEquals($params['goal_amount'], $pcp->goal_amount
, 'Check for goal_amount.');
67 $this->assertEquals($params['is_active'], $pcp->is_active
, 'Check for is_active.');
70 public function testAddPCPNoStatus() {
71 $blockParams = $this->pcpBlockParams();
72 $pcpBlock = CRM_PCP_BAO_PCPBlock
::create($blockParams);
74 $params = $this->pcpParams();
75 $params['pcp_block_id'] = $pcpBlock->id
;
76 unset($params['status_id']);
78 $pcp = CRM_PCP_BAO_PCP
::create($params);
80 $this->assertInstanceOf('CRM_PCP_DAO_PCP', $pcp, 'Check for created object');
81 $this->assertEquals($params['contact_id'], $pcp->contact_id
, 'Check for entity table.');
82 $this->assertEquals(0, $pcp->status_id
, 'Check for zero status when no status_id passed.');
83 $this->assertEquals($params['title'], $pcp->title
, 'Check for title.');
84 $this->assertEquals($params['intro_text'], $pcp->intro_text
, 'Check for intro_text.');
85 $this->assertEquals($params['page_text'], $pcp->page_text
, 'Check for page_text.');
86 $this->assertEquals($params['donate_link_text'], $pcp->donate_link_text
, 'Check for donate_link_text.');
87 $this->assertEquals($params['is_thermometer'], $pcp->is_thermometer
, 'Check for is_thermometer.');
88 $this->assertEquals($params['is_honor_roll'], $pcp->is_honor_roll
, 'Check for is_honor_roll.');
89 $this->assertEquals($params['goal_amount'], $pcp->goal_amount
, 'Check for goal_amount.');
90 $this->assertEquals($params['is_active'], $pcp->is_active
, 'Check for is_active.');
93 public function testDeletePCP() {
95 $pcp = CRM_Core_DAO
::createTestObject('CRM_PCP_DAO_PCP');
97 CRM_PCP_BAO_PCP
::deleteById($pcpId);
98 $this->assertDBRowNotExist('CRM_PCP_DAO_PCP', $pcpId, 'Database check PCP deleted successfully.');
102 * Get getPCPDashboard info function.
104 * @throws \CRM_Core_Exception
106 public function testGetPcpDashboardInfo() {
107 $block = CRM_PCP_BAO_PCPBlock
::create($this->pcpBlockParams());
108 $contactID = $this->individualCreate();
109 $contributionPage = $this->callAPISuccessGetSingle('ContributionPage', []);
110 $this->callAPISuccess('Pcp', 'create', ['contact_id' => $contactID, 'title' => 'pcp', 'page_id' => $contributionPage['id'], 'pcp_block_id' => $block->id
, 'is_active' => TRUE, 'status_id' => 'Approved']);
111 $this->assertEquals([
115 'pageTitle' => $contributionPage['title'],
116 'action' => '<span><a href="/index.php?q=civicrm/pcp/info&action=update&reset=1&id=' . $contributionPage['id'] . '&component=contribute" class="action-item crm-hover-button" title=\'Configure\' >Edit Your Page</a><a href="/index.php?q=civicrm/friend&eid=1&blockId=1&reset=1&pcomponent=pcp&component=contribute" class="action-item crm-hover-button" title=\'Tell Friends\' >Tell Friends</a></span><span class=\'btn-slide crm-hover-button\'>more<ul class=\'panel\'><li><a href="/index.php?q=civicrm/pcp/info&reset=1&id=1&component=contribute" class="action-item crm-hover-button" title=\'URL for this Page\' >URL for this Page</a></li><li><a href="/index.php?q=civicrm/pcp/info&action=browse&reset=1&id=1&component=contribute" class="action-item crm-hover-button" title=\'Update Contact Information\' >Update Contact Information</a></li><li><a href="/index.php?q=civicrm/pcp&action=disable&reset=1&id=1&component=contribute" class="action-item crm-hover-button" title=\'Disable\' >Disable</a></li><li><a href="/index.php?q=civicrm/pcp&action=delete&reset=1&id=1&component=contribute" class="action-item crm-hover-button small-popup" title=\'Delete\' onclick = "return confirm(\'Are you sure you want to delete this Personal Campaign Page?\nThis action cannot be undone.\');">Delete</a></li></ul></span>',
119 'pcpStatus' => 'Approved',
123 ], CRM_PCP_BAO_PCP
::getPcpDashboardInfo($contactID));