Merge pull request #4789 from totten/master-test-tx
[civicrm-core.git] / tests / phpunit / CRM / PCP / BAO / PCPTest.php
1 <?php
2 /*
3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.6 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2014 |
7 +--------------------------------------------------------------------+
8 | This file is a part of CiviCRM. |
9 | |
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. |
13 | |
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. |
18 | |
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 +--------------------------------------------------------------------+
26 */
27
28
29 require_once 'CiviTest/CiviUnitTestCase.php';
30
31 /**
32 * Test class for CRM_PCP_BAO_PCPTest BAO
33 *
34 * @package CiviCRM
35 */
36 class CRM_PCP_BAO_PCPTest extends CiviUnitTestCase {
37
38 /**
39 * Sets up the fixture, for example, opens a network connection.
40 * This method is called before a test is executed.
41 *
42 * @access protected
43 */
44 protected function setUp() {
45 parent::setUp();
46 }
47
48 function testAddPCPBlock() {
49
50 $params = $this->pcpBlockParams();
51 $pcpBlock = CRM_PCP_BAO_PCP::add($params, TRUE);
52
53 $this->assertInstanceOf('CRM_PCP_DAO_PCPBlock', $pcpBlock, 'Check for created object');
54 $this->assertEquals($params['entity_table'], $pcpBlock->entity_table, 'Check for entity table.');
55 $this->assertEquals($params['entity_id'], $pcpBlock->entity_id, 'Check for entity id.');
56 $this->assertEquals($params['supporter_profile_id'], $pcpBlock->supporter_profile_id, 'Check for profile id .');
57 $this->assertEquals($params['is_approval_needed'], $pcpBlock->is_approval_needed, 'Check for approval needed .');
58 $this->assertEquals($params['is_tellfriend_enabled'], $pcpBlock->is_tellfriend_enabled, 'Check for tell friend on.');
59 $this->assertEquals($params['tellfriend_limit'], $pcpBlock->tellfriend_limit, 'Check for tell friend limit .');
60 $this->assertEquals($params['link_text'], $pcpBlock->link_text, 'Check for link text.');
61 $this->assertEquals($params['is_active'], $pcpBlock->is_active, 'Check for is_active.');
62 // Delete our test object
63 $delParams = array('id' => $pcpBlock->id);
64 // FIXME: Currently this delete fails with an FK constraint error: DELETE FROM civicrm_contribution_type WHERE ( civicrm_contribution_type.id = 5 )
65 // CRM_Core_DAO::deleteTestObjects( 'CRM_PCP_DAO_PCPBlock', $delParams );
66 }
67
68 function testAddPCP() {
69 $blockParams = $this->pcpBlockParams();
70 $pcpBlock = CRM_PCP_BAO_PCP::add($blockParams, TRUE);
71
72 $params = $this->pcpParams();
73 $params['pcp_block_id'] = $pcpBlock->id;
74
75 $pcp = CRM_PCP_BAO_PCP::add($params, FALSE);
76
77 $this->assertInstanceOf('CRM_PCP_DAO_PCP', $pcp, 'Check for created object');
78 $this->assertEquals($params['contact_id'], $pcp->contact_id, 'Check for entity table.');
79 $this->assertEquals($params['status_id'], $pcp->status_id, 'Check for status.');
80 $this->assertEquals($params['title'], $pcp->title, 'Check for title.');
81 $this->assertEquals($params['intro_text'], $pcp->intro_text, 'Check for intro_text.');
82 $this->assertEquals($params['page_text'], $pcp->page_text, 'Check for page_text.');
83 $this->assertEquals($params['donate_link_text'], $pcp->donate_link_text, 'Check for donate_link_text.');
84 $this->assertEquals($params['is_thermometer'], $pcp->is_thermometer, 'Check for is_thermometer.');
85 $this->assertEquals($params['is_honor_roll'], $pcp->is_honor_roll, 'Check for is_honor_roll.');
86 $this->assertEquals($params['goal_amount'], $pcp->goal_amount, 'Check for goal_amount.');
87 $this->assertEquals($params['is_active'], $pcp->is_active, 'Check for is_active.');
88
89 // Delete our test object
90 $delParams = array('id' => $pcp->id);
91 // FIXME: Currently this delete fails with an FK constraint error: DELETE FROM civicrm_contribution_type WHERE ( civicrm_contribution_type.id = 5 )
92 // CRM_Core_DAO::deleteTestObjects( 'CRM_PCP_DAO_PCP', $delParams );
93 }
94
95 function testAddPCPNoStatus() {
96 $blockParams = $this->pcpBlockParams();
97 $pcpBlock = CRM_PCP_BAO_PCP::add($blockParams, TRUE);
98
99 $params = $this->pcpParams();
100 $params['pcp_block_id'] = $pcpBlock->id;
101 unset($params['status_id']);
102
103 $pcp = CRM_PCP_BAO_PCP::add($params, FALSE);
104
105 $this->assertInstanceOf('CRM_PCP_DAO_PCP', $pcp, 'Check for created object');
106 $this->assertEquals($params['contact_id'], $pcp->contact_id, 'Check for entity table.');
107 $this->assertEquals(0, $pcp->status_id, 'Check for zero status when no status_id passed.');
108 $this->assertEquals($params['title'], $pcp->title, 'Check for title.');
109 $this->assertEquals($params['intro_text'], $pcp->intro_text, 'Check for intro_text.');
110 $this->assertEquals($params['page_text'], $pcp->page_text, 'Check for page_text.');
111 $this->assertEquals($params['donate_link_text'], $pcp->donate_link_text, 'Check for donate_link_text.');
112 $this->assertEquals($params['is_thermometer'], $pcp->is_thermometer, 'Check for is_thermometer.');
113 $this->assertEquals($params['is_honor_roll'], $pcp->is_honor_roll, 'Check for is_honor_roll.');
114 $this->assertEquals($params['goal_amount'], $pcp->goal_amount, 'Check for goal_amount.');
115 $this->assertEquals($params['is_active'], $pcp->is_active, 'Check for is_active.');
116
117 // Delete our test object
118 $delParams = array('id' => $pcp->id);
119 // FIXME: Currently this delete fails with an FK constraint error: DELETE FROM civicrm_contribution_type WHERE ( civicrm_contribution_type.id = 5 )
120 // CRM_Core_DAO::deleteTestObjects( 'CRM_PCP_DAO_PCP', $delParams );
121 }
122
123 function testDeletePCP() {
124
125 $pcp = CRM_Core_DAO::createTestObject('CRM_PCP_DAO_PCP');
126 $pcpId = $pcp->id;
127 $del = CRM_PCP_BAO_PCP::deleteById($pcpId);
128 $this->assertDBRowNotExist('CRM_PCP_DAO_PCP', $pcpId,
129 'Database check PCP deleted successfully.'
130 );
131 }
132
133 /**
134 * Build params
135 *
136 */
137 private function pcpBlockParams() {
138 $contribPage = CRM_Core_DAO::createTestObject('CRM_Contribute_DAO_ContributionPage');
139 $contribPageId = $contribPage->id;
140 $supporterProfile = CRM_Core_DAO::createTestObject('CRM_Core_DAO_UFGroup');
141 $supporterProfileId = $supporterProfile->id;
142
143 $params = array(
144 'entity_table' => 'civicrm_contribution_page',
145 'entity_id' => $contribPageId,
146 'supporter_profile_id' => $supporterProfileId,
147 'target_entity_id' => 1,
148 'is_approval_needed' => 1,
149 'is_tellfriend_enabled' => 1,
150 'tellfriend_limit' => 1,
151 'link_text' => 'Create your own PCP',
152 'is_active' => 1,
153 );
154
155 return $params;
156 }
157
158 /**
159 * Build params
160 *
161 */
162 private function pcpParams() {
163 $contact = CRM_Core_DAO::createTestObject('CRM_Contact_DAO_Contact');
164 $contactId = $contact->id;
165 $contribPage = CRM_Core_DAO::createTestObject('CRM_Contribute_DAO_ContributionPage');
166 $contribPageId = $contribPage->id;
167
168 $params = array(
169 'contact_id' => $contactId,
170 'status_id' => '1',
171 'title' => 'My PCP',
172 'intro_text' => 'Hey you, contribute now!',
173 'page_text' => 'You better give more.',
174 'donate_link_text' => 'Donate Now',
175 'page_id' => $contribPageId,
176 'is_thermometer' => 1,
177 'is_honor_roll' => 1,
178 'goal_amount' => 10000.00,
179 'is_active' => 1,
180 );
181
182 return $params;
183 }
184
185 /**
186 * Tears down the fixture, for example, closes a network connection.
187 * This method is called after a test is executed.
188 *
189 * @access protected
190 */
191 protected function tearDown() {}
192 }
193