add missing comments - tests directory
[civicrm-core.git] / tests / phpunit / WebTest / Import / MemberTest.php
CommitLineData
6a488035
TO
1<?php
2/*
3 +--------------------------------------------------------------------+
06a1bc01 4 | CiviCRM version 4.5 |
6a488035 5 +--------------------------------------------------------------------+
06a1bc01 6 | Copyright CiviCRM LLC (c) 2004-2014 |
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 along with this program; if not, contact CiviCRM LLC |
21 | at info[AT]civicrm[DOT]org. If you have questions about the |
22 | GNU Affero General Public License or the licensing of CiviCRM, |
23 | see the CiviCRM license FAQ at http://civicrm.org/licensing |
24 +--------------------------------------------------------------------+
25*/
26
6a488035
TO
27require_once 'WebTest/Import/ImportCiviSeleniumTestCase.php';
28class WebTest_Import_MemberTest extends ImportCiviSeleniumTestCase {
29
30 protected function setUp() {
31 parent::setUp();
32 }
33
34 /*
35 * Test participant import for Individuals.
36 */
37 function testMemberImportIndividual() {
6a488035
TO
38
39 $this->webtestLogin();
40
41 // Get membership import data for Individuals.
42 list($headers, $rows, $fieldMapper) = $this->_memberIndividualCSVData();
43
44 // Import participants and check imported data.
45 $this->importCSVComponent('Membership', $headers, $rows, 'Individual', 'Skip', $fieldMapper);
46 }
47
48 /*
49 * Test participant import for Households.
50 */
51 function testMemberImportHousehold() {
6a488035
TO
52
53 $this->webtestLogin();
54
55 // Get membership import data for Households.
56 list($headers, $rows, $fieldMapper) = $this->_memberHouseholdCSVData();
57
58 // Import participants and check imported data.
59 $this->importCSVComponent('Membership', $headers, $rows, 'Household', 'Skip', $fieldMapper);
60 }
61
62 /*
63 * Test participant import for Organizations.
64 */
65 function testMemberImportOrganization() {
6a488035
TO
66
67 $this->webtestLogin();
68
69 // Get membership import data for Organizations.
70 list($headers, $rows, $fieldMapper) = $this->_memberOrganizationCSVData();
71
72 // Import participants and check imported data.
73 $this->importCSVComponent('Membership', $headers, $rows, 'Organization', 'Skip', $fieldMapper);
74 }
75
76 /*
77 * Helper function to provide data for Membeship import for Individuals.
78 */
4cbe18b8
EM
79 /**
80 * @return array
81 */
6a488035
TO
82 function _memberIndividualCSVData() {
83 $memTypeParams = $this->webtestAddMembershipType();
84
85 $firstName1 = substr(sha1(rand()), 0, 7);
86 $email1 = 'mail_' . substr(sha1(rand()), 0, 7) . '@example.com';
87 $this->webtestAddContact($firstName1, 'Anderson', $email1);
88 $startDate1 = date('Y-m-d');
89
90 $firstName2 = substr(sha1(rand()), 0, 7);
91 $email2 = 'mail_' . substr(sha1(rand()), 0, 7) . '@example.com';
92 $this->webtestAddContact($firstName2, 'Anderson', $email2);
93 $year = date('Y') - 1;
94 $startDate2 = date('Y-m-d', mktime(0, 0, 0, 9, 10, $year));
95
96 $headers = array(
97 'email' => 'Email',
98 'membership_type_id' => 'Membership Type',
99 'membership_start_date' => 'Membership Start Date',
100 );
101
102 $rows = array(
103 array(
104 'email' => $email1,
105 'membership_type_id' => $memTypeParams['membership_type'],
106 'membership_start_date' => $startDate1,
107 ),
108 array(
109 'email' => $email2,
110 'membership_type_id' => $memTypeParams['membership_type'],
111 'membership_start_date' => $startDate2,
112 ),
113 );
114
115 $fieldMapper = array(
116 'mapper[0][0]' => 'email',
117 'mapper[1][0]' => 'membership_type_id',
118 'mapper[2][0]' => 'membership_start_date',
119 );
120 return array($headers, $rows, $fieldMapper);
121 }
122
123 /*
124 * Helper function to provide data for Membeship import for Households.
125 */
4cbe18b8
EM
126 /**
127 * @return array
128 */
6a488035
TO
129 function _memberHouseholdCSVData() {
130 $memTypeParams = $this->webtestAddMembershipType();
131
132 $household1 = substr(sha1(rand()), 0, 7) . ' home';
133 $this->webtestAddHousehold($household1, TRUE);
134 $startDate1 = date('Y-m-d');
135
136 $household2 = substr(sha1(rand()), 0, 7) . ' home';
137 $this->webtestAddHousehold($household2, TRUE);
138 $year = date('Y') - 1;
139 $startDate2 = date('Y-m-d', mktime(0, 0, 0, 12, 31, $year));
140
141 $headers = array(
142 'household_name' => 'Household Name',
143 'membership_type_id' => 'Membership Type',
144 'membership_start_date' => 'Membership Start Date',
145 );
146
147 $rows = array(
148 array(
149 'household_name' => $household1,
150 'membership_type_id' => $memTypeParams['membership_type'],
151 'membership_start_date' => $startDate1,
152 ),
153 array(
154 'household_name' => $household2,
155 'membership_type_id' => $memTypeParams['membership_type'],
156 'membership_start_date' => $startDate2,
157 ),
158 );
159
160 $fieldMapper = array(
161 'mapper[0][0]' => 'household_name',
162 'mapper[1][0]' => 'membership_type_id',
163 'mapper[2][0]' => 'membership_start_date',
164 );
165 return array($headers, $rows, $fieldMapper);
166 }
167
168 /*
169 * Helper function to provide data for Membeship import for Organizations.
170 */
4cbe18b8
EM
171 /**
172 * @return array
173 */
6a488035
TO
174 function _memberOrganizationCSVData() {
175 $memTypeParams = $this->webtestAddMembershipType();
176
177 $organization1 = substr(sha1(rand()), 0, 7) . ' org';
178 $this->webtestAddOrganization($organization1, TRUE);
179 $startDate1 = date('Y-m-d');
180
181 $organization2 = substr(sha1(rand()), 0, 7) . ' org';
182 $this->webtestAddOrganization($organization2, TRUE);
183 $year = date('Y') - 1;
184 $startDate2 = date('Y-m-d', mktime(0, 0, 0, 12, 31, $year));
185
186 $headers = array(
187 'organization_name' => 'Organization Name',
188 'membership_type_id' => 'Membership Type',
189 'membership_start_date' => 'Membership Start Date',
190 );
191
192 $rows = array(
193 array(
194 'organization_name' => $organization1,
195 'membership_type_id' => $memTypeParams['membership_type'],
196 'membership_start_date' => $startDate1,
197 ),
198 array(
199 'organization_name' => $organization2,
200 'membership_type_id' => $memTypeParams['membership_type'],
201 'membership_start_date' => $startDate2,
202 ),
203 );
204
205 $fieldMapper = array(
206 'mapper[0][0]' => 'organization_name',
207 'mapper[1][0]' => 'membership_type_id',
208 'mapper[2][0]' => 'membership_start_date',
209 );
210 return array($headers, $rows, $fieldMapper);
211 }
212}
213