| 1 | <?php |
| 2 | /* |
| 3 | +--------------------------------------------------------------------+ |
| 4 | | CiviCRM version 4.7 | |
| 5 | +--------------------------------------------------------------------+ |
| 6 | | Copyright CiviCRM LLC (c) 2004-2015 | |
| 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 | * Test class for CRM_Pledge_BAO_Pledge BAO |
| 30 | * |
| 31 | * @package CiviCRM |
| 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. |
| 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. |
| 47 | */ |
| 48 | protected function tearDown() { |
| 49 | } |
| 50 | |
| 51 | /** |
| 52 | * Test for Add/Update Pledge. |
| 53 | */ |
| 54 | public function testAdd() { |
| 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 | */ |
| 82 | public function testRetrieveZeroPledeID() { |
| 83 | $defaults = array(); |
| 84 | $params = array('pledge_id' => 0); |
| 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 | /** |
| 91 | * Retrieve a payment based on a Null pledge id random string. |
| 92 | */ |
| 93 | public function testRetrieveStringPledgeID() { |
| 94 | $defaults = array(); |
| 95 | $params = array('pledge_id' => 'random text'); |
| 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 | /** |
| 102 | * Test that payment retrieve wrks based on known pledge id. |
| 103 | */ |
| 104 | public function testRetrieveKnownPledgeID() { |
| 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 | } |
| 130 | |
| 131 | } |