3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.7 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2017 |
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 * Class CRM_Contribute_BAO_ContributionRecurTest
32 class CRM_Contribute_BAO_ContributionRecurTest
extends CiviUnitTestCase
{
33 protected $_params = array();
35 public function setUp() {
37 $this->_ids
['payment_processor'] = $this->paymentProcessorCreate();
38 $this->_params
= array(
39 'contact_id' => $this->individualCreate(),
41 'frequency_unit' => 'week',
42 'frequency_interval' => 1,
44 'start_date' => 'yesterday',
45 'create_date' => 'yesterday',
46 'modified_date' => 'yesterday',
47 'cancel_date' => NULL,
48 'end_date' => '+ 2 weeks',
49 'processor_id' => '643411460836',
50 'trxn_id' => 'e0d0808e26f3e661c6c18eb7c039d363',
51 'invoice_id' => 'e0d0808e26f3e661c6c18eb7c039d363',
52 'contribution_status_id' => 1,
55 'next_sched_contribution_date' => '+ 1 week',
57 'failure_retry_date' => NULL,
60 'payment_processor_id' => $this->_ids
['payment_processor'],
61 'is_email_receipt' => 1,
62 'financial_type_id' => 1,
63 'payment_instrument_id' => 1,
64 'campaign_id' => NULL,
68 public function teardown() {
69 $this->quickCleanup(array('civicrm_contribution_recur', 'civicrm_payment_processor'));
73 * Test that an object can be retrieved & saved (per CRM-14986).
75 * This has been causing a DB error so we are checking for absence of error
77 public function testFindSave() {
78 $contributionRecur = $this->callAPISuccess('contribution_recur', 'create', $this->_params
);
79 $dao = new CRM_Contribute_BAO_ContributionRecur();
80 $dao->id
= $contributionRecur['id'];
82 $dao->is_email_receipt
= 0;
87 * Test cancellation works per CRM-14986.
89 * We are checking for absence of error.
91 public function testCancelRecur() {
92 $contributionRecur = $this->callAPISuccess('contribution_recur', 'create', $this->_params
);
93 CRM_Contribute_BAO_ContributionRecur
::cancelRecurContribution($contributionRecur['id'], NULL);
97 * Test checking if contribution recurr object can allow for changes to financial types.
100 public function testSupportFinancialTypeChange() {
101 $contributionRecur = $this->callAPISuccess('contribution_recur', 'create', $this->_params
);
102 $contribution = $this->callAPISuccess('contribution', 'create', array(
103 'contribution_recur_id' => $contributionRecur['id'],
104 'total_amount' => '3.00',
105 'financial_type_id' => 1,
106 'payment_instrument_id' => 1,
108 'contact_id' => $this->individualCreate(),
109 'contribution_status_id' => 1,
110 'recieve_date' => 'yesterday',
112 $this->assertTrue(CRM_Contribute_BAO_ContributionRecur
::supportsFinancialTypeChange($contributionRecur['id']));
116 * Test we don't change unintended fields on API edit
118 public function testUpdateRecur() {
119 $createParams = $this->_params
;
120 $createParams['currency'] = 'XAU';
121 $contributionRecur = $this->callAPISuccess('contribution_recur', 'create', $createParams);
123 'id' => $contributionRecur['id'],
124 'end_date' => '+ 4 weeks',
126 $contributionRecur = $this->callAPISuccess('contribution_recur', 'create', $editParams);
127 $dao = new CRM_Contribute_BAO_ContributionRecur();
128 $dao->id
= $contributionRecur['id'];
130 $this->assertEquals('XAU', $dao->currency
, 'Edit clobbered recur currency');