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