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