CRM-13014 support userLoginFinalize() for UF classes (fix civimobile)
[civicrm-core.git] / tests / phpunit / api / v3 / ContributionRecurTest.php
CommitLineData
6a488035
TO
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
28require_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
39class 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;
430ae6dd
TO
45 public $DBResetRequired = FALSE;
46
47 function setUp() {
6a488035
TO
48 parent::setUp();
49 $this->ids['contact'][0] = $this->individualCreate();
50 $this->params = array(
51 'version' => 3,
52 'contact_id' => $this->ids['contact'][0],
53 'installments' => '12',
54 'frequency_interval' => '1',
55 'amount' => '500',
56 'contribution_status_id' => 1,
57 'start_date' => '2012-01-01 00:00:00',
58 'currency' => 'USD',
59 'frequency_unit' => 'day',
60 );
61 }
62
63 function tearDown() {
64 foreach ($this->ids as $entity => $entities) {
65 foreach ($entities as $id) {
66 civicrm_api($entity, 'delete', array('version' => $this->_apiversion, 'id' => $id));
67 }
68 }
69 $tablesToTruncate = array(
70 'civicrm_financial_type',
71 'civicrm_contribution',
72 'civicrm_contribution_recur',
73 'civicrm_membership',
74 );
75 $this->quickCleanup($tablesToTruncate);
76 }
77
78 public function testCreateContributionRecur() {
79 $result = civicrm_api($this->_entity, 'create', $this->params);
80 $this->documentMe($this->params, $result, __FUNCTION__, __FILE__);
81 $this->assertAPISuccess($result, 'In line ' . __LINE__);
82 $this->assertEquals(1, $result['count'], 'In line ' . __LINE__);
83 $this->assertNotNull($result['values'][$result['id']]['id'], 'In line ' . __LINE__);
84 $this->getAndCheck($this->params, $result['id'], $this->_entity);
85 }
86
87 public function testGetContributionRecur() {
88 $result = civicrm_api($this->_entity, 'create', $this->params);
89 $getParams = array(
90 'version' => $this->_apiversion,
91 'amount' => '500',
92 );
93 $result = civicrm_api($this->_entity, 'get', $getParams);
94 $this->documentMe($getParams, $result, __FUNCTION__, __FILE__);
95 $this->assertAPISuccess($result, 'In line ' . __LINE__);
96 $this->assertEquals(1, $result['count'], 'In line ' . __LINE__);
97 }
98
99 public function testDeleteContributionRecur() {
100 $result = civicrm_api($this->_entity, 'create', $this->params);
101 $deleteParams = array('version' => 3, 'id' => $result['id']);
102 $result = civicrm_api($this->_entity, 'delete', $deleteParams);
103 $this->documentMe($deleteParams, $result, __FUNCTION__, __FILE__);
104 $this->assertAPISuccess($result, 'In line ' . __LINE__);
105 $checkDeleted = civicrm_api($this->_entity, 'get', array(
106 'version' => 3,
107 ));
108 $this->assertEquals(0, $checkDeleted['count'], 'In line ' . __LINE__);
109 }
110
111 public function testGetFieldsContributionRecur() {
112 $result = civicrm_api($this->_entity, 'getfields', array('version' => 3, 'action' => 'create'));
113 $this->assertAPISuccess($result, 'In line ' . __LINE__);
114 $this->assertEquals(12, $result['values']['start_date']['type']);
115 }
116}
117