Merge pull request #10946 from mattwire/CRM-21037_activity_sendsms_unittests
[civicrm-core.git] / tests / phpunit / api / v3 / ContributionRecurTest.php
CommitLineData
6a488035
TO
1<?php
2/*
3 +--------------------------------------------------------------------+
2fe49090 4 | CiviCRM version 5 |
6a488035 5 +--------------------------------------------------------------------+
8c9251b3 6 | Copyright CiviCRM LLC (c) 2004-2018 |
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 APIv3 civicrm_contribute_recur* functions
30 *
6c6e6187
TO
31 * @package CiviCRM_APIv3
32 * @subpackage API_Contribution
acb109b7 33 * @group headless
6a488035 34 */
6a488035
TO
35class api_v3_ContributionRecurTest extends CiviUnitTestCase {
36 protected $_apiversion = 3;
37 protected $params;
38 protected $ids = array();
39 protected $_entity = 'contribution_recur';
b7c9bc4c 40
430ae6dd
TO
41 public $DBResetRequired = FALSE;
42
00be9182 43 public function setUp() {
6a488035 44 parent::setUp();
5057e8e8 45 $this->useTransaction(TRUE);
6a488035
TO
46 $this->ids['contact'][0] = $this->individualCreate();
47 $this->params = array(
6a488035
TO
48 'contact_id' => $this->ids['contact'][0],
49 'installments' => '12',
50 'frequency_interval' => '1',
51 'amount' => '500',
52 'contribution_status_id' => 1,
53 'start_date' => '2012-01-01 00:00:00',
54 'currency' => 'USD',
55 'frequency_unit' => 'day',
56 );
57 }
58
6a488035 59 public function testCreateContributionRecur() {
fc928539 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']);
6a488035
TO
63 $this->getAndCheck($this->params, $result['id'], $this->_entity);
64 }
65
66 public function testGetContributionRecur() {
225d474b 67 $this->callAPISuccess($this->_entity, 'create', $this->params);
6a488035 68 $getParams = array(
6a488035
TO
69 'amount' => '500',
70 );
fc928539 71 $result = $this->callAPIAndDocument($this->_entity, 'get', $getParams, __FUNCTION__, __FILE__);
72 $this->assertEquals(1, $result['count']);
6a488035
TO
73 }
74
81c55926
RT
75 public function testCreateContributionRecurWithToken() {
76 // create token
77 $this->createLoggedInUser();
0cc123b5 78 $token = $this->callAPISuccess('PaymentToken', 'create', array(
8950ecdc 79 'payment_processor_id' => $this->processorCreate(),
0cc123b5
RT
80 'token' => 'hhh',
81 'contact_id' => $this->individualCreate(),
82 ));
81c55926
RT
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);
88 }
89
6a488035 90 public function testDeleteContributionRecur() {
fc928539 91 $result = $this->callAPISuccess($this->_entity, 'create', $this->params);
92 $deleteParams = array('id' => $result['id']);
225d474b 93 $this->callAPIAndDocument($this->_entity, 'delete', $deleteParams, __FUNCTION__, __FILE__);
6c6e6187 94 $checkDeleted = $this->callAPISuccess($this->_entity, 'get', array());
fc928539 95 $this->assertEquals(0, $checkDeleted['count']);
6a488035
TO
96 }
97
98 public function testGetFieldsContributionRecur() {
fc928539 99 $result = $this->callAPISuccess($this->_entity, 'getfields', array('action' => 'create'));
6a488035
TO
100 $this->assertEquals(12, $result['values']['start_date']['type']);
101 }
96025800 102
6a488035 103}