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