3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.6 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2015 |
7 +--------------------------------------------------------------------+
8 | This file is a part of CiviCRM. |
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. |
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. |
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 +--------------------------------------------------------------------+
29 require_once 'CiviTest/CiviUnitTestCase.php';
32 * Test class for CRM_PCP_BAO_PCPTest BAO
36 class CRM_PCP_BAO_PCPTest
extends CiviUnitTestCase
{
39 * Sets up the fixture, for example, opens a network connection.
40 * This method is called before a test is executed.
42 protected function setUp() {
46 public function testAddPCPBlock() {
48 $params = $this->pcpBlockParams();
49 $pcpBlock = CRM_PCP_BAO_PCP
::add($params, TRUE);
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 );
66 public function testAddPCP() {
67 $blockParams = $this->pcpBlockParams();
68 $pcpBlock = CRM_PCP_BAO_PCP
::add($blockParams, TRUE);
70 $params = $this->pcpParams();
71 $params['pcp_block_id'] = $pcpBlock->id
;
73 $pcp = CRM_PCP_BAO_PCP
::add($params, FALSE);
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.');
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 );
93 public function testAddPCPNoStatus() {
94 $blockParams = $this->pcpBlockParams();
95 $pcpBlock = CRM_PCP_BAO_PCP
::add($blockParams, TRUE);
97 $params = $this->pcpParams();
98 $params['pcp_block_id'] = $pcpBlock->id
;
99 unset($params['status_id']);
101 $pcp = CRM_PCP_BAO_PCP
::add($params, FALSE);
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.');
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 );
121 public function testDeletePCP() {
123 $pcp = CRM_Core_DAO
::createTestObject('CRM_PCP_DAO_PCP');
125 $del = CRM_PCP_BAO_PCP
::deleteById($pcpId);
126 $this->assertDBRowNotExist('CRM_PCP_DAO_PCP', $pcpId,
127 'Database check PCP deleted successfully.'
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
;
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',
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
;
165 'contact_id' => $contactId,
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,
182 * Tears down the fixture, for example, closes a network connection.
183 * This method is called after a test is executed.
185 protected function tearDown() {