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 TO |
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 | * | |
6c6e6187 | 35 | * @package CiviCRM |
6a488035 TO |
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. | |
6a488035 TO |
42 | */ |
43 | protected function setUp() { | |
44 | parent::setUp(); | |
45 | $this->_contactId = Contact::createIndividual(); | |
46 | } | |
47 | ||
48 | /** | |
49 | * Tears down the fixture, for example, closes a network connection. | |
50 | * This method is called after a test is executed. | |
6a488035 | 51 | */ |
6c6e6187 TO |
52 | protected function tearDown() { |
53 | } | |
6a488035 TO |
54 | |
55 | /** | |
56 | * Test for Add/Update Pledge. | |
57 | */ | |
00be9182 | 58 | public function testAdd() { |
6a488035 TO |
59 | $params = array( |
60 | 'contact_id' => $this->_contactId, | |
61 | 'frequency_unit' => 'month', | |
62 | 'original_installment_amount' => 25.00, | |
63 | 'frequency_interval' => 1, | |
64 | 'frequency_day' => 1, | |
65 | 'installments' => 12, | |
66 | 'financial_type_id' => 1, | |
67 | 'create_date' => '20100513000000', | |
68 | 'acknowledge_date' => '20100513000000', | |
69 | 'start_date' => '20100513000000', | |
70 | 'status_id' => 2, | |
71 | 'currency' => 'USD', | |
72 | 'amount' => 300, | |
73 | ); | |
74 | ||
75 | //do test for normal add. | |
76 | $pledge = CRM_Pledge_BAO_Pledge::add($params); | |
77 | ||
78 | foreach ($params as $param => $value) { | |
79 | $this->assertEquals($value, $pledge->$param); | |
80 | } | |
81 | } | |
82 | ||
83 | /** | |
84 | * Retrieve a pledge based on a pledge id = 0 | |
85 | */ | |
00be9182 | 86 | public function testRetrieveZeroPledeID() { |
6a488035 | 87 | $defaults = array(); |
92915c55 | 88 | $params = array('pledge_id' => 0); |
6a488035 TO |
89 | $pledgeId = CRM_Pledge_BAO_Pledge::retrieve($params, $defaults); |
90 | ||
91 | $this->assertEquals(count($pledgeId), 0, "Pledge Id must be greater than 0"); | |
92 | } | |
93 | ||
94 | /** | |
eceb18cc | 95 | * Retrieve a payment based on a Null pledge id random string. |
6a488035 | 96 | */ |
00be9182 | 97 | public function testRetrieveStringPledgeID() { |
6a488035 | 98 | $defaults = array(); |
92915c55 | 99 | $params = array('pledge_id' => 'random text'); |
6a488035 TO |
100 | $pledgeId = CRM_Pledge_BAO_Pledge::retrieve($params, $defaults); |
101 | ||
102 | $this->assertEquals(count($pledgeId), 0, "Pledge Id must be a string"); | |
103 | } | |
104 | ||
105 | /** | |
eceb18cc | 106 | * Test that payment retrieve wrks based on known pledge id. |
6a488035 | 107 | */ |
00be9182 | 108 | public function testRetrieveKnownPledgeID() { |
6a488035 TO |
109 | $params = array( |
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', | |
120 | 'status_id' => 2, | |
121 | 'currency' => 'USD', | |
122 | 'amount' => 300, | |
123 | ); | |
124 | ||
125 | $pledge = CRM_Pledge_BAO_Pledge::add($params); | |
126 | ||
127 | $defaults = array(); | |
128 | $pledgeParams = array('pledge_id' => $pledge->id); | |
129 | ||
130 | $pledgeId = CRM_Pledge_BAO_Pledge::retrieve($pledgeParams, $defaults); | |
131 | ||
132 | $this->assertEquals(count($pledgeId), 1, "Pledge was retrieved"); | |
133 | } | |
96025800 | 134 | |
6a488035 | 135 | } |