3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.7 |
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';
30 require_once 'CiviTest/Contact.php';
33 * Test class for CRM_Pledge_BAO_Pledge BAO
37 class CRM_Pledge_BAO_PledgeTest
extends CiviUnitTestCase
{
40 * Sets up the fixture, for example, opens a network connection.
41 * This method is called before a test is executed.
43 protected function setUp() {
45 $this->_contactId
= Contact
::createIndividual();
49 * Tears down the fixture, for example, closes a network connection.
50 * This method is called after a test is executed.
52 protected function tearDown() {
56 * Test for Add/Update Pledge.
58 public function testAdd() {
60 'contact_id' => $this->_contactId
,
61 'frequency_unit' => 'month',
62 'original_installment_amount' => 25.00,
63 'frequency_interval' => 1,
66 'financial_type_id' => 1,
67 'create_date' => '20100513000000',
68 'acknowledge_date' => '20100513000000',
69 'start_date' => '20100513000000',
75 //do test for normal add.
76 $pledge = CRM_Pledge_BAO_Pledge
::add($params);
78 foreach ($params as $param => $value) {
79 $this->assertEquals($value, $pledge->$param);
84 * Retrieve a pledge based on a pledge id = 0
86 public function testRetrieveZeroPledeID() {
88 $params = array('pledge_id' => 0);
89 $pledgeId = CRM_Pledge_BAO_Pledge
::retrieve($params, $defaults);
91 $this->assertEquals(count($pledgeId), 0, "Pledge Id must be greater than 0");
95 * Retrieve a payment based on a Null pledge id random string.
97 public function testRetrieveStringPledgeID() {
99 $params = array('pledge_id' => 'random text');
100 $pledgeId = CRM_Pledge_BAO_Pledge
::retrieve($params, $defaults);
102 $this->assertEquals(count($pledgeId), 0, "Pledge Id must be a string");
106 * Test that payment retrieve wrks based on known pledge id.
108 public function testRetrieveKnownPledgeID() {
110 'contact_id' => $this->_contactId
,
111 'frequency_unit' => 'month',
112 'frequency_interval' => 1,
113 'frequency_day' => 1,
114 'original_installment_amount' => 25.00,
115 'installments' => 12,
116 'financial_type_id' => 1,
117 'create_date' => '20100513000000',
118 'acknowledge_date' => '20100513000000',
119 'start_date' => '20100513000000',
125 $pledge = CRM_Pledge_BAO_Pledge
::add($params);
128 $pledgeParams = array('pledge_id' => $pledge->id
);
130 $pledgeId = CRM_Pledge_BAO_Pledge
::retrieve($pledgeParams, $defaults);
132 $this->assertEquals(count($pledgeId), 1, "Pledge was retrieved");