tests/phpunit/** - Remove unnecessary "require_once" statements
[civicrm-core.git] / tests / phpunit / api / v3 / MembershipPaymentTest.php
CommitLineData
6a488035 1<?php
6a488035
TO
2/*
3 +--------------------------------------------------------------------+
81621fee 4 | CiviCRM version 4.7 |
6a488035 5 +--------------------------------------------------------------------+
e7112fa7 6 | Copyright CiviCRM LLC (c) 2004-2015 |
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_membership_payment* functions
30 *
6c6e6187
TO
31 * @package CiviCRM_APIv3
32 * @subpackage API_Member
6a488035 33 */
6a488035
TO
34class api_v3_MembershipPaymentTest extends CiviUnitTestCase {
35 protected $_apiversion = 3;
36 protected $_contactID;
37 protected $_contributionTypeID;
38 protected $_membershipTypeID;
39 protected $_membershipStatusID;
40 protected $_contribution = array();
92915c55 41
00be9182 42 public function setUp() {
6a488035 43 parent::setUp();
fb0190bb 44 $this->useTransaction(TRUE);
6a488035
TO
45
46 $this->_contactID = $this->organizationCreate(NULL);
75638074 47 $this->_membershipTypeID = $this->membershipTypeCreate(array('member_of_contact_id' => $this->_contactID));
6a488035
TO
48 $this->_membershipStatusID = $this->membershipStatusCreate('test status');
49 $activityTypes = CRM_Core_PseudoConstant::activityType(TRUE, TRUE, TRUE, 'name');
50 $params = array(
51 'contact_id' => $this->_contactID,
52 'currency' => 'USD',
53 'financial_type_id' => 1,
54 'contribution_status_id' => 1,
55 'contribution_page_id' => NULL,
56 'payment_instrument_id' => 1,
57 'source' => 'STUDENT',
58 'receive_date' => '20080522000000',
59 'receipt_date' => '20080522000000',
60 'total_amount' => 200.00,
61 'trxn_id' => '22ereerwww322323',
62 'invoice_id' => '22ed39c9e9ee6ef6031621ce0eafe6da70',
63 'thankyou_date' => '20080522',
6a488035
TO
64 );
65
6c6e6187 66 $this->_contribution = $this->callAPISuccess('contribution', 'create', $params);
6a488035
TO
67 }
68
6a488035
TO
69 ///////////////// civicrm_membership_payment_create methods
70
71 /**
72 * Test civicrm_membership_payment_create with empty params.
73 */
74 public function testCreateEmptyParams() {
771f3245 75 $this->callAPIFailure('membership_payment', 'create', array(), 'Mandatory key(s) missing from params array: membership_id, contribution_id');
6a488035
TO
76 }
77
78 /**
79 * Test civicrm_membership_payment_create - success expected.
80 */
81 public function testCreate() {
e4d5f1e2 82 $contactId = $this->individualCreate();
6a488035 83
6a488035
TO
84 $params = array(
85 'contact_id' => $contactId,
86 'membership_type_id' => $this->_membershipTypeID,
87 'join_date' => '2006-01-21',
88 'start_date' => '2006-01-21',
89 'end_date' => '2006-12-21',
90 'source' => 'Payment',
91 'is_override' => 1,
92 'status_id' => $this->_membershipStatusID,
6a488035
TO
93 );
94
771f3245 95 $membership = $this->callAPISuccess('membership', 'create', $params);
6a488035
TO
96
97 $params = array(
98 'contribution_id' => $this->_contribution['id'],
99 'membership_id' => $membership['id'],
6a488035 100 );
771f3245 101 $result = $this->callAPIAndDocument('membership_payment', 'create', $params, __FUNCTION__, __FILE__);
6a488035
TO
102 $this->assertEquals($result['values'][$result['id']]['membership_id'], $membership['id'], 'Check Membership Id in line ' . __LINE__);
103 $this->assertEquals($result['values'][$result['id']]['contribution_id'], $this->_contribution['id'], 'Check Contribution Id in line ' . __LINE__);
104
105 }
106
107
108 ///////////////// civicrm_membershipPayment_get methods
109
110 /**
111 * Test civicrm_membershipPayment_get with wrong params type.
112 */
113 public function testGetWrongParamsType() {
114 $params = 'eeee';
771f3245 115 $GetWrongParamsType = $this->callAPIFailure('membership_payment', 'get', $params, 'Input variable `params` is not an array');
6a488035
TO
116 }
117
118 /**
119 * Test civicrm_membershipPayment_get - success expected.
120 */
121 public function testGet() {
e4d5f1e2 122 $contactId = $this->individualCreate();
6a488035
TO
123 $params = array(
124 'contact_id' => $contactId,
125 'membership_type_id' => $this->_membershipTypeID,
126 'source' => 'Payment',
127 'is_override' => 1,
128 'status_id' => $this->_membershipStatusID,
6a488035 129 );
771f3245 130
131 $membership = $this->callAPISuccess('membership', 'create', $params);
6a488035
TO
132
133 $params = array(
134 'contribution_id' => $this->_contribution['id'],
771f3245 135 'membership_id' => $membership['id'],
6a488035 136 );
771f3245 137 $this->callAPISuccess('membership_payment', 'create', $params);
6a488035 138
771f3245 139 $result = $this->callAPIAndDocument('membership_payment', 'get', $params, __FUNCTION__, __FILE__);
140 $this->assertEquals($result['values'][$result['id']]['membership_id'], $params['membership_id'], 'Check Membership Id');
141 $this->assertEquals($result['values'][$result['id']]['contribution_id'], $params['contribution_id'], 'Check Contribution Id');
6a488035 142 }
96025800 143
6a488035 144}