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