3 +--------------------------------------------------------------------+
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2019 |
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 * Test APIv3 civicrm_contribute_recur* functions
31 * @package CiviCRM_APIv3
32 * @subpackage API_Contribution
35 class api_v3_ContributionRecurTest
extends CiviUnitTestCase
{
36 protected $_apiversion = 3;
39 protected $_entity = 'contribution_recur';
41 public $DBResetRequired = FALSE;
43 public function setUp() {
45 $this->useTransaction(TRUE);
46 $this->ids
['contact'][0] = $this->individualCreate();
48 'contact_id' => $this->ids
['contact'][0],
49 'installments' => '12',
50 'frequency_interval' => '1',
52 'contribution_status_id' => 1,
53 'start_date' => '2012-01-01 00:00:00',
55 'frequency_unit' => 'day',
59 public function testCreateContributionRecur() {
60 $result = $this->callAPIAndDocument($this->_entity
, 'create', $this->params
, __FUNCTION__
, __FILE__
);
61 $this->assertEquals(1, $result['count']);
62 $this->assertNotNull($result['values'][$result['id']]['id']);
63 $this->getAndCheck($this->params
, $result['id'], $this->_entity
);
66 public function testGetContributionRecur() {
67 $this->callAPISuccess($this->_entity
, 'create', $this->params
);
71 $result = $this->callAPIAndDocument($this->_entity
, 'get', $getParams, __FUNCTION__
, __FILE__
);
72 $this->assertEquals(1, $result['count']);
75 public function testCreateContributionRecurWithToken() {
77 $this->createLoggedInUser();
78 $token = $this->callAPISuccess('PaymentToken', 'create', [
79 'payment_processor_id' => $this->processorCreate(),
81 'contact_id' => $this->individualCreate(),
83 $params['payment_token_id'] = $token['id'];
84 $result = $this->callAPISuccess($this->_entity
, 'create', $this->params
);
85 $this->assertEquals(1, $result['count']);
86 $this->assertNotNull($result['values'][$result['id']]['id']);
87 $this->getAndCheck($this->params
, $result['id'], $this->_entity
);
90 public function testDeleteContributionRecur() {
91 $result = $this->callAPISuccess($this->_entity
, 'create', $this->params
);
92 $deleteParams = ['id' => $result['id']];
93 $this->callAPIAndDocument($this->_entity
, 'delete', $deleteParams, __FUNCTION__
, __FILE__
);
94 $checkDeleted = $this->callAPISuccess($this->_entity
, 'get', []);
95 $this->assertEquals(0, $checkDeleted['count']);
98 public function testGetFieldsContributionRecur() {
99 $result = $this->callAPISuccess($this->_entity
, 'getfields', ['action' => 'create']);
100 $this->assertEquals(12, $result['values']['start_date']['type']);
104 * Test that we can cancel a contribution and add a cancel_reason via the api.
106 public function testContributionRecurCancel() {
107 $result = $this->callAPISuccess($this->_entity
, 'create', $this->params
);
108 $this->callAPISuccess('ContributionRecur', 'cancel', ['id' => $result['id'], 'cancel_reason' => 'just cos', 'processor_message' => 'big fail']);
109 $cancelled = $this->callAPISuccess('ContributionRecur', 'getsingle', ['id' => $result['id']]);
110 $this->assertEquals('just cos', $cancelled['cancel_reason']);
111 $this->assertEquals(CRM_Core_PseudoConstant
::getKey('CRM_Contribute_BAO_ContributionRecur', 'contribution_status_id', 'Cancelled'), $cancelled['contribution_status_id']);
112 $this->assertEquals(date('Y-m-d'), date('Y-m-d', strtotime($cancelled['cancel_date'])));
113 $activity = $this->callAPISuccessGetSingle('Activity', ['activity_type_id' => 'Cancel Recurring Contribution', 'record_type_id' => $result['id']]);
114 $this->assertEquals('Recurring contribution cancelled', $activity['subject']);
115 $this->assertEquals('big fail<br/>The recurring contribution of 500.00, every 1 day has been cancelled.', $activity['details']);
116 $this->assertEquals(date('Y-m-d'), date('Y-m-d', strtotime($activity['activity_date_time'])));
117 $this->assertEquals($this->params
['contact_id'], $activity['source_contact_id']);
118 $this->assertEquals(CRM_Core_PseudoConstant
::getKey('CRM_Activity_BAO_Activity', 'status_id', 'Completed'), $activity['status_id']);