Commit | Line | Data |
---|---|---|
6a488035 TO |
1 | <?php |
2 | /* | |
3 | +--------------------------------------------------------------------+ | |
4 | | CiviCRM version 4.3 | | |
5 | +--------------------------------------------------------------------+ | |
6 | | Copyright CiviCRM LLC (c) 2004-2013 | | |
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 | require_once 'CiviTest/Contact.php'; | |
31 | ||
32 | /** | |
33 | * Test class for CRM_Pledge_BAO_Pledge BAO | |
34 | * | |
35 | * @package CiviCRM | |
36 | */ | |
37 | class CRM_Pledge_BAO_PledgeTest extends CiviUnitTestCase { | |
38 | ||
39 | /** | |
40 | * Sets up the fixture, for example, opens a network connection. | |
41 | * This method is called before a test is executed. | |
42 | * | |
43 | * @access protected | |
44 | */ | |
45 | protected function setUp() { | |
46 | parent::setUp(); | |
47 | $this->_contactId = Contact::createIndividual(); | |
48 | } | |
49 | ||
50 | /** | |
51 | * Tears down the fixture, for example, closes a network connection. | |
52 | * This method is called after a test is executed. | |
53 | * | |
54 | * @access protected | |
55 | */ | |
56 | protected function tearDown() {} | |
57 | ||
58 | /** | |
59 | * Test for Add/Update Pledge. | |
60 | */ | |
61 | function testAdd() { | |
62 | $params = array( | |
63 | 'contact_id' => $this->_contactId, | |
64 | 'frequency_unit' => 'month', | |
65 | 'original_installment_amount' => 25.00, | |
66 | 'frequency_interval' => 1, | |
67 | 'frequency_day' => 1, | |
68 | 'installments' => 12, | |
69 | 'financial_type_id' => 1, | |
70 | 'create_date' => '20100513000000', | |
71 | 'acknowledge_date' => '20100513000000', | |
72 | 'start_date' => '20100513000000', | |
73 | 'status_id' => 2, | |
74 | 'currency' => 'USD', | |
75 | 'amount' => 300, | |
76 | ); | |
77 | ||
78 | //do test for normal add. | |
79 | $pledge = CRM_Pledge_BAO_Pledge::add($params); | |
80 | ||
81 | foreach ($params as $param => $value) { | |
82 | $this->assertEquals($value, $pledge->$param); | |
83 | } | |
84 | } | |
85 | ||
86 | /** | |
87 | * Retrieve a pledge based on a pledge id = 0 | |
88 | */ | |
89 | function testRetrieveZeroPledeID() { | |
90 | $defaults = array(); | |
91 | $params = array('pledge_id' => 0); | |
92 | $pledgeId = CRM_Pledge_BAO_Pledge::retrieve($params, $defaults); | |
93 | ||
94 | $this->assertEquals(count($pledgeId), 0, "Pledge Id must be greater than 0"); | |
95 | } | |
96 | ||
97 | /** | |
98 | * Retrieve a payment based on a Null pledge id random string | |
99 | */ | |
100 | function testRetrieveStringPledgeID() { | |
101 | $defaults = array(); | |
102 | $params = array('pledge_id' => 'random text'); | |
103 | $pledgeId = CRM_Pledge_BAO_Pledge::retrieve($params, $defaults); | |
104 | ||
105 | $this->assertEquals(count($pledgeId), 0, "Pledge Id must be a string"); | |
106 | } | |
107 | ||
108 | /** | |
109 | * Test that payment retrieve wrks based on known pledge id | |
110 | */ | |
111 | function testRetrieveKnownPledgeID() { | |
112 | $params = array( | |
113 | 'contact_id' => $this->_contactId, | |
114 | 'frequency_unit' => 'month', | |
115 | 'frequency_interval' => 1, | |
116 | 'frequency_day' => 1, | |
117 | 'original_installment_amount' => 25.00, | |
118 | 'installments' => 12, | |
119 | 'financial_type_id' => 1, | |
120 | 'create_date' => '20100513000000', | |
121 | 'acknowledge_date' => '20100513000000', | |
122 | 'start_date' => '20100513000000', | |
123 | 'status_id' => 2, | |
124 | 'currency' => 'USD', | |
125 | 'amount' => 300, | |
126 | ); | |
127 | ||
128 | $pledge = CRM_Pledge_BAO_Pledge::add($params); | |
129 | ||
130 | $defaults = array(); | |
131 | $pledgeParams = array('pledge_id' => $pledge->id); | |
132 | ||
133 | $pledgeId = CRM_Pledge_BAO_Pledge::retrieve($pledgeParams, $defaults); | |
134 | ||
135 | $this->assertEquals(count($pledgeId), 1, "Pledge was retrieved"); | |
136 | } | |
137 | } | |
138 |