CRM-13072 also remove failing delete call from CRM layer - batch entry
[civicrm-core.git] / tests / phpunit / CRM / Batch / Form / EntryTest.php
1 <?php
2
3 /**
4 * File for the EntryTest class
5 *
6 * (PHP 5)
7 *
8 * @package CiviCRM
9 *
10 * This file is part of CiviCRM
11 *
12 * CiviCRM is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU Affero General Public License
14 * as published by the Free Software Foundation; either version 3 of
15 * the License, or (at your option) any later version.
16 *
17 * CiviCRM is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 * GNU Affero General Public License for more details.
21 *
22 * You should have received a copy of the GNU Affero General Public
23 * License along with this program. If not, see
24 * <http://www.gnu.org/licenses/>.
25 */
26
27 require_once 'CiviTest/CiviUnitTestCase.php';
28
29
30 /**
31 * Test CRM/Member/BAO Membership Log add , delete functions
32 *
33 * @package CiviCRM
34 */
35 class CRM_Batch_Form_EntryTest extends CiviUnitTestCase {
36
37 public $_eNoticeCompliant = TRUE;
38 /**
39 * Membership type name used in test function
40 * @var String
41 */
42 protected $_membershipTypeName = NULL;
43
44 /**
45 * Membership type id used in test function
46 * @var String
47 */
48 protected $_membershipTypeID = NULL;
49
50 /**
51 * Contact id used in test function
52 * @var String
53 */
54 protected $_contactID = NULL;
55 /**
56 * Contact id used in test function
57 * @var String
58 */
59 protected $_contactID2 = NULL;
60 /**
61 * Describe test class
62 * @return array
63 */
64 function get_info() {
65 return array(
66 'name' => 'MembershipParserTest',
67 'description' => 'Test import parser function',
68 'group' => 'CiviCRM BAO Tests',
69 );
70 }
71
72 function setUp() {
73 parent::setUp();
74
75 $params = array(
76 'contact_type_a' => 'Individual',
77 'contact_type_b' => 'Organization',
78 'name_a_b' => 'Test Employee of',
79 'name_b_a' => 'Test Employer of',
80 );
81 $this->_relationshipTypeId = $this->relationshipTypeCreate($params);
82 $this->_orgContactID = $this->organizationCreate();
83 $this->_financialTypeId = 1;
84 $this->_membershipTypeName = 'Mickey Mouse Club Member';
85 $params = array(
86 'name' => $this->_membershipTypeName,
87 'description' => NULL,
88 'minimum_fee' => 10,
89 'duration_unit' => 'year',
90 'member_of_contact_id' => $this->_orgContactID,
91 'period_type' => 'fixed',
92 'duration_interval' => 1,
93 'financial_type_id' => $this->_financialTypeId,
94 'relationship_type_id' => $this->_relationshipTypeId,
95 'visibility' => 'Public',
96 'is_active' => 1,
97 'fixed_period_start_day' => 101,
98 'fixed_period_rollover_day' => 1231
99 );
100 $membershipType = CRM_Member_BAO_MembershipType::add($params, $ids);
101 $this->_membershipTypeID = $membershipType->id;
102
103 $this->_mebershipStatusID = $this->membershipStatusCreate('test status');
104 $this->_contactID = $this->individualCreate();
105 $contact2Params = array(
106 'first_name' => 'Anthonita',
107 'middle_name' => 'J.',
108 'last_name' => 'Anderson',
109 'prefix_id' => 3,
110 'suffix_id' => 3,
111 'email' => 'b@c.com',
112 'contact_type' => 'Individual',
113 );
114 $this->_contactID2 = $this->individualCreate($contact2Params);
115 $session = CRM_Core_Session::singleton();
116 $session->set('dateTypes', 1);
117
118 }
119
120 /**
121 * Tears down the fixture, for example, closes a network connection.
122 * This method is called after a test is executed.
123 *
124 */
125 function tearDown() {
126 $tablesToTruncate = array('civicrm_membership', 'civicrm_membership_log', 'civicrm_contribution', 'civicrm_membership_payment');
127 $this->quickCleanup($tablesToTruncate);
128 $this->relationshipTypeDelete($this->_relationshipTypeId);
129 $this->membershipTypeDelete(array('id' => $this->_membershipTypeID));
130 $this->membershipStatusDelete($this->_mebershipStatusID);
131 $this->contactDelete($this->_contactID);
132 $this->contactDelete($this->_contactID2);
133 $this->contactDelete($this->_orgContactID);
134 }
135
136 /**
137 * Test Import
138 */
139 function testProcessMembership() {
140 $form = new CRM_Batch_Form_Entry();
141 $params = $this->getMembershipData();
142 $this->assertTrue($form->testProcessMembership($params));
143 $result = $this->callAPISuccess('membership', 'get', array());
144 $this->assertEquals(2, $result['count']);
145 }
146
147 /*
148 * data provider for test process membership
149 */
150 function getMembershipData() {
151
152 /*
153 Array (
154
155 );
156 */
157 return array(
158 'batch_id' => 4,
159 'primary_profiles' => array(1 => NULL, 2 => NULL),
160 'primary_contact_select_id' => Array (1 => $this->_contactID, 2 => $this->_contactID2),
161 'field' => array(
162 1 => array(
163 'membership_type' => Array (0 => 1, 1 => 1),// (I was unable to determine what these both mean but both are refered to in code
164 'join_date' => '07/22/2013',
165 'membership_start_date' => NULL,
166 'membership_end_date' => NULL,
167 'membership_source' => NULL,
168 'financial_type' => 2,
169 'total_amount' => 1,
170 'receive_date' => '07/24/2013',
171 'receive_date_time' => NULL,
172 'payment_instrument' => 1,
173 'check_number' => NULL,
174 'contribution_status_id' => 1,
175 ),
176 2 => array(
177 'membership_type' => Array (0 => 1, 1 => 1 ),
178 'join_date' => '07/03/2013',
179 'membership_start_date' => NULL,
180 'membership_end_date' => NULL,
181 'membership_source' => NULL,
182 'financial_type' => 2,
183 'total_amount' => 1,
184 'receive_date' => '07/17/2013',
185 'receive_date_time' => NULL,
186 'payment_instrument' => NULL,
187 'check_number' => NULL,
188 'contribution_status_id' => 1,
189 )
190 ),
191 'actualBatchTotal' => 0,
192 );
193 }
194 }
195