CRM-12274
[civicrm-core.git] / tests / phpunit / api / v3 / ContributionRecurTest.php
1 <?php
2 /*
3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.3 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2013 |
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 require_once 'CiviTest/CiviUnitTestCase.php';
29
30
31 /**
32 * Test APIv3 civicrm_contribute_recur* functions
33 *
34 * @package CiviCRM_APIv3
35 * @subpackage API_Contribution
36 */
37
38
39 class api_v3_ContributionRecurTest extends CiviUnitTestCase {
40 protected $_apiversion = 3;
41 protected $params;
42 protected $ids = array();
43 protected $_entity = 'contribution_recur';
44 public $_eNoticeCompliant = TRUE;
45 public $DBResetRequired = FALSE; function setUp() {
46 parent::setUp();
47 $this->ids['contact'][0] = $this->individualCreate();
48 $this->params = array(
49 'version' => 3,
50 'contact_id' => $this->ids['contact'][0],
51 'installments' => '12',
52 'frequency_interval' => '1',
53 'amount' => '500',
54 'contribution_status_id' => 1,
55 'start_date' => '2012-01-01 00:00:00',
56 'currency' => 'USD',
57 'frequency_unit' => 'day',
58 );
59 }
60
61 function tearDown() {
62 foreach ($this->ids as $entity => $entities) {
63 foreach ($entities as $id) {
64 civicrm_api($entity, 'delete', array('version' => $this->_apiversion, 'id' => $id));
65 }
66 }
67 $tablesToTruncate = array(
68 'civicrm_financial_type',
69 'civicrm_contribution',
70 'civicrm_contribution_recur',
71 'civicrm_membership',
72 );
73 $this->quickCleanup($tablesToTruncate);
74 }
75
76 public function testCreateContributionRecur() {
77 $result = civicrm_api($this->_entity, 'create', $this->params);
78 $this->documentMe($this->params, $result, __FUNCTION__, __FILE__);
79 $this->assertAPISuccess($result, 'In line ' . __LINE__);
80 $this->assertEquals(1, $result['count'], 'In line ' . __LINE__);
81 $this->assertNotNull($result['values'][$result['id']]['id'], 'In line ' . __LINE__);
82 $this->getAndCheck($this->params, $result['id'], $this->_entity);
83 }
84
85 public function testGetContributionRecur() {
86 $result = civicrm_api($this->_entity, 'create', $this->params);
87 $getParams = array(
88 'version' => $this->_apiversion,
89 'amount' => '500',
90 );
91 $result = civicrm_api($this->_entity, 'get', $getParams);
92 $this->documentMe($getParams, $result, __FUNCTION__, __FILE__);
93 $this->assertAPISuccess($result, 'In line ' . __LINE__);
94 $this->assertEquals(1, $result['count'], 'In line ' . __LINE__);
95 }
96
97 public function testDeleteContributionRecur() {
98 $result = civicrm_api($this->_entity, 'create', $this->params);
99 $deleteParams = array('version' => 3, 'id' => $result['id']);
100 $result = civicrm_api($this->_entity, 'delete', $deleteParams);
101 $this->documentMe($deleteParams, $result, __FUNCTION__, __FILE__);
102 $this->assertAPISuccess($result, 'In line ' . __LINE__);
103 $checkDeleted = civicrm_api($this->_entity, 'get', array(
104 'version' => 3,
105 ));
106 $this->assertEquals(0, $checkDeleted['count'], 'In line ' . __LINE__);
107 }
108
109 public function testGetFieldsContributionRecur() {
110 $result = civicrm_api($this->_entity, 'getfields', array('version' => 3, 'action' => 'create'));
111 $this->assertAPISuccess($result, 'In line ' . __LINE__);
112 $this->assertEquals(12, $result['values']['start_date']['type']);
113 }
114 }
115