[REF] Move handling of form elements back to the Form
[civicrm-core.git] / tests / phpunit / CRM / PCP / BAO / PCPTest.php
1 <?php
2 /*
3 +--------------------------------------------------------------------+
4 | Copyright CiviCRM LLC. All rights reserved. |
5 | |
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 +--------------------------------------------------------------------+
10 */
11
12 /**
13 * Test class for CRM_PCP_BAO_PCPTest BAO
14 *
15 * @package CiviCRM
16 * @group headless
17 */
18 class CRM_PCP_BAO_PCPTest extends CiviUnitTestCase {
19
20 use CRMTraits_PCP_PCPTestTrait;
21
22 /**
23 * Clean up after test.
24 *
25 * @throws \CRM_Core_Exception
26 */
27 public function tearDown() {
28 $this->quickCleanUpFinancialEntities();
29 parent::tearDown();
30 }
31
32 public function testAddPCPBlock() {
33
34 $params = $this->pcpBlockParams();
35 $pcpBlock = CRM_PCP_BAO_PCPBlock::create($params);
36
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.');
46 }
47
48 public function testAddPCP() {
49 $blockParams = $this->pcpBlockParams();
50 $pcpBlock = CRM_PCP_BAO_PCPBlock::create($blockParams);
51
52 $params = $this->pcpParams();
53 $params['pcp_block_id'] = $pcpBlock->id;
54
55 $pcp = CRM_PCP_BAO_PCP::create($params);
56
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.');
68 }
69
70 public function testAddPCPNoStatus() {
71 $blockParams = $this->pcpBlockParams();
72 $pcpBlock = CRM_PCP_BAO_PCPBlock::create($blockParams);
73
74 $params = $this->pcpParams();
75 $params['pcp_block_id'] = $pcpBlock->id;
76 unset($params['status_id']);
77
78 $pcp = CRM_PCP_BAO_PCP::create($params);
79
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.');
91 }
92
93 public function testDeletePCP() {
94
95 $pcp = CRM_Core_DAO::createTestObject('CRM_PCP_DAO_PCP');
96 $pcpId = $pcp->id;
97 CRM_PCP_BAO_PCP::deleteById($pcpId);
98 $this->assertDBRowNotExist('CRM_PCP_DAO_PCP', $pcpId, 'Database check PCP deleted successfully.');
99 }
100
101 /**
102 * Get getPCPDashboard info function.
103 *
104 * @throws \CRM_Core_Exception
105 */
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([
112 [],
113 [
114 [
115 'pageTitle' => $contributionPage['title'],
116 'action' => '<span><a href="/index.php?q=civicrm/pcp/info&amp;action=update&amp;reset=1&amp;id=' . $contributionPage['id'] . '&amp;component=contribute" class="action-item crm-hover-button" title=\'Configure\' >Edit Your Page</a><a href="/index.php?q=civicrm/friend&amp;eid=1&amp;blockId=1&amp;reset=1&amp;pcomponent=pcp&amp;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&amp;reset=1&amp;id=1&amp;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&amp;action=browse&amp;reset=1&amp;id=1&amp;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&amp;action=disable&amp;reset=1&amp;id=1&amp;component=contribute" class="action-item crm-hover-button" title=\'Disable\' >Disable</a></li><li><a href="/index.php?q=civicrm/pcp&amp;action=delete&amp;reset=1&amp;id=1&amp;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>',
117 'pcpId' => 1,
118 'pcpTitle' => 'pcp',
119 'pcpStatus' => 'Approved',
120 'class' => '',
121 ],
122 ],
123 ], CRM_PCP_BAO_PCP::getPcpDashboardInfo($contactID));
124 }
125
126 }