whitespace cleanup
[civicrm-core.git] / tests / phpunit / WebTest / Import / MemberTest.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 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 */
79 function _memberIndividualCSVData() {
80 $memTypeParams = $this->webtestAddMembershipType();
81
82 $firstName1 = substr(sha1(rand()), 0, 7);
83 $email1 = 'mail_' . substr(sha1(rand()), 0, 7) . '@example.com';
84 $this->webtestAddContact($firstName1, 'Anderson', $email1);
85 $startDate1 = date('Y-m-d');
86
87 $firstName2 = substr(sha1(rand()), 0, 7);
88 $email2 = 'mail_' . substr(sha1(rand()), 0, 7) . '@example.com';
89 $this->webtestAddContact($firstName2, 'Anderson', $email2);
90 $year = date('Y') - 1;
91 $startDate2 = date('Y-m-d', mktime(0, 0, 0, 9, 10, $year));
92
93 $headers = array(
94 'email' => 'Email',
95 'membership_type_id' => 'Membership Type',
96 'membership_start_date' => 'Membership Start Date',
97 );
98
99 $rows = array(
100 array(
101 'email' => $email1,
102 'membership_type_id' => $memTypeParams['membership_type'],
103 'membership_start_date' => $startDate1,
104 ),
105 array(
106 'email' => $email2,
107 'membership_type_id' => $memTypeParams['membership_type'],
108 'membership_start_date' => $startDate2,
109 ),
110 );
111
112 $fieldMapper = array(
113 'mapper[0][0]' => 'email',
114 'mapper[1][0]' => 'membership_type_id',
115 'mapper[2][0]' => 'membership_start_date',
116 );
117 return array($headers, $rows, $fieldMapper);
118 }
119
120 /*
121 * Helper function to provide data for Membeship import for Households.
122 */
123 function _memberHouseholdCSVData() {
124 $memTypeParams = $this->webtestAddMembershipType();
125
126 $household1 = substr(sha1(rand()), 0, 7) . ' home';
127 $this->webtestAddHousehold($household1, TRUE);
128 $startDate1 = date('Y-m-d');
129
130 $household2 = substr(sha1(rand()), 0, 7) . ' home';
131 $this->webtestAddHousehold($household2, TRUE);
132 $year = date('Y') - 1;
133 $startDate2 = date('Y-m-d', mktime(0, 0, 0, 12, 31, $year));
134
135 $headers = array(
136 'household_name' => 'Household Name',
137 'membership_type_id' => 'Membership Type',
138 'membership_start_date' => 'Membership Start Date',
139 );
140
141 $rows = array(
142 array(
143 'household_name' => $household1,
144 'membership_type_id' => $memTypeParams['membership_type'],
145 'membership_start_date' => $startDate1,
146 ),
147 array(
148 'household_name' => $household2,
149 'membership_type_id' => $memTypeParams['membership_type'],
150 'membership_start_date' => $startDate2,
151 ),
152 );
153
154 $fieldMapper = array(
155 'mapper[0][0]' => 'household_name',
156 'mapper[1][0]' => 'membership_type_id',
157 'mapper[2][0]' => 'membership_start_date',
158 );
159 return array($headers, $rows, $fieldMapper);
160 }
161
162 /*
163 * Helper function to provide data for Membeship import for Organizations.
164 */
165 function _memberOrganizationCSVData() {
166 $memTypeParams = $this->webtestAddMembershipType();
167
168 $organization1 = substr(sha1(rand()), 0, 7) . ' org';
169 $this->webtestAddOrganization($organization1, TRUE);
170 $startDate1 = date('Y-m-d');
171
172 $organization2 = substr(sha1(rand()), 0, 7) . ' org';
173 $this->webtestAddOrganization($organization2, TRUE);
174 $year = date('Y') - 1;
175 $startDate2 = date('Y-m-d', mktime(0, 0, 0, 12, 31, $year));
176
177 $headers = array(
178 'organization_name' => 'Organization Name',
179 'membership_type_id' => 'Membership Type',
180 'membership_start_date' => 'Membership Start Date',
181 );
182
183 $rows = array(
184 array(
185 'organization_name' => $organization1,
186 'membership_type_id' => $memTypeParams['membership_type'],
187 'membership_start_date' => $startDate1,
188 ),
189 array(
190 'organization_name' => $organization2,
191 'membership_type_id' => $memTypeParams['membership_type'],
192 'membership_start_date' => $startDate2,
193 ),
194 );
195
196 $fieldMapper = array(
197 'mapper[0][0]' => 'organization_name',
198 'mapper[1][0]' => 'membership_type_id',
199 'mapper[2][0]' => 'membership_start_date',
200 );
201 return array($headers, $rows, $fieldMapper);
202 }
203}
204