Action schedule API modifications
[civicrm-core.git] / tests / phpunit / api / v3 / MembershipPaymentTest.php
CommitLineData
6a488035 1<?php
6a488035
TO
2
3/*
4 +--------------------------------------------------------------------+
232624b1 5 | CiviCRM version 4.4 |
6a488035
TO
6 +--------------------------------------------------------------------+
7 | Copyright CiviCRM LLC (c) 2004-2013 |
8 +--------------------------------------------------------------------+
9 | This file is a part of CiviCRM. |
10 | |
11 | CiviCRM is free software; you can copy, modify, and distribute it |
12 | under the terms of the GNU Affero General Public License |
13 | Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
14 | |
15 | CiviCRM is distributed in the hope that it will be useful, but |
16 | WITHOUT ANY WARRANTY; without even the implied warranty of |
17 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
18 | See the GNU Affero General Public License for more details. |
19 | |
20 | You should have received a copy of the GNU Affero General Public |
21 | License and the CiviCRM Licensing Exception along |
22 | with this program; if not, contact CiviCRM LLC |
23 | at info[AT]civicrm[DOT]org. If you have questions about the |
24 | GNU Affero General Public License or the licensing of CiviCRM, |
25 | see the CiviCRM license FAQ at http://civicrm.org/licensing |
26 +--------------------------------------------------------------------+
27*/
28
29require_once 'CiviTest/CiviUnitTestCase.php';
30
31/**
32 * Test APIv3 civicrm_membership_payment* functions
33 *
34 * @package CiviCRM_APIv3
35 * @subpackage API_Member
36 */
37
38class api_v3_MembershipPaymentTest extends CiviUnitTestCase {
39 protected $_apiversion = 3;
40 protected $_contactID;
41 protected $_contributionTypeID;
42 protected $_membershipTypeID;
43 protected $_membershipStatusID;
44 protected $_contribution = array();
45 function setUp() {
46 parent::setUp();
47
48 $this->_contactID = $this->organizationCreate(NULL);
75638074 49 $this->_membershipTypeID = $this->membershipTypeCreate(array('member_of_contact_id' => $this->_contactID));
6a488035
TO
50 $this->_membershipStatusID = $this->membershipStatusCreate('test status');
51 $activityTypes = CRM_Core_PseudoConstant::activityType(TRUE, TRUE, TRUE, 'name');
52 $params = array(
53 'contact_id' => $this->_contactID,
54 'currency' => 'USD',
55 'financial_type_id' => 1,
56 'contribution_status_id' => 1,
57 'contribution_page_id' => NULL,
58 'payment_instrument_id' => 1,
59 'source' => 'STUDENT',
60 'receive_date' => '20080522000000',
61 'receipt_date' => '20080522000000',
62 'total_amount' => 200.00,
63 'trxn_id' => '22ereerwww322323',
64 'invoice_id' => '22ed39c9e9ee6ef6031621ce0eafe6da70',
65 'thankyou_date' => '20080522',
6a488035
TO
66 );
67
771f3245 68 $this->_contribution = $this->callAPISuccess('contribution','create', $params);
6a488035
TO
69 }
70
71 function tearDown() {
72 $this->quickCleanup(
73 array(
74 'civicrm_contact',
75 'civicrm_contribution',
76 'civicrm_membership',
77 'civicrm_membership_payment',
78 'civicrm_membership_status',
79 'civicrm_membership_type',
80 'civicrm_line_item',
81 )
82 );
6a488035
TO
83 }
84
85 ///////////////// civicrm_membership_payment_create methods
86
87 /**
88 * Test civicrm_membership_payment_create with empty params.
89 */
90 public function testCreateEmptyParams() {
771f3245 91 $this->callAPIFailure('membership_payment', 'create', array(), 'Mandatory key(s) missing from params array: membership_id, contribution_id');
6a488035
TO
92 }
93
94 /**
95 * Test civicrm_membership_payment_create - success expected.
96 */
97 public function testCreate() {
e4d5f1e2 98 $contactId = $this->individualCreate();
6a488035 99
6a488035
TO
100 $params = array(
101 'contact_id' => $contactId,
102 'membership_type_id' => $this->_membershipTypeID,
103 'join_date' => '2006-01-21',
104 'start_date' => '2006-01-21',
105 'end_date' => '2006-12-21',
106 'source' => 'Payment',
107 'is_override' => 1,
108 'status_id' => $this->_membershipStatusID,
6a488035
TO
109 );
110
771f3245 111 $membership = $this->callAPISuccess('membership', 'create', $params);
6a488035
TO
112
113 $params = array(
114 'contribution_id' => $this->_contribution['id'],
115 'membership_id' => $membership['id'],
6a488035 116 );
771f3245 117 $result = $this->callAPIAndDocument('membership_payment', 'create', $params, __FUNCTION__, __FILE__);
6a488035
TO
118 $this->assertEquals($result['values'][$result['id']]['membership_id'], $membership['id'], 'Check Membership Id in line ' . __LINE__);
119 $this->assertEquals($result['values'][$result['id']]['contribution_id'], $this->_contribution['id'], 'Check Contribution Id in line ' . __LINE__);
120
121 }
122
123
124 ///////////////// civicrm_membershipPayment_get methods
125
126 /**
127 * Test civicrm_membershipPayment_get with wrong params type.
128 */
129 public function testGetWrongParamsType() {
130 $params = 'eeee';
771f3245 131 $GetWrongParamsType = $this->callAPIFailure('membership_payment', 'get', $params, 'Input variable `params` is not an array');
6a488035
TO
132 }
133
134 /**
135 * Test civicrm_membershipPayment_get - success expected.
136 */
137 public function testGet() {
e4d5f1e2 138 $contactId = $this->individualCreate();
6a488035
TO
139 $params = array(
140 'contact_id' => $contactId,
141 'membership_type_id' => $this->_membershipTypeID,
142 'source' => 'Payment',
143 'is_override' => 1,
144 'status_id' => $this->_membershipStatusID,
6a488035 145 );
771f3245 146
147 $membership = $this->callAPISuccess('membership', 'create', $params);
6a488035
TO
148
149 $params = array(
150 'contribution_id' => $this->_contribution['id'],
771f3245 151 'membership_id' => $membership['id'],
6a488035 152 );
771f3245 153 $this->callAPISuccess('membership_payment', 'create', $params);
6a488035 154
771f3245 155 $result = $this->callAPIAndDocument('membership_payment', 'get', $params, __FUNCTION__, __FILE__);
156 $this->assertEquals($result['values'][$result['id']]['membership_id'], $params['membership_id'], 'Check Membership Id');
157 $this->assertEquals($result['values'][$result['id']]['contribution_id'], $params['contribution_id'], 'Check Contribution Id');
6a488035
TO
158 }
159}
160