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