Global webtest cleanup
[civicrm-core.git] / tests / phpunit / WebTest / Import / DateFormatTest.php
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_DateFormatTest extends ImportCiviSeleniumTestCase {
30
31 protected $captureScreenshotOnFailure = TRUE;
32 protected $screenshotPath = '/var/www/api.dev.civicrm.org/public/sc';
33 protected $screenshotUrl = 'http://api.dev.civicrm.org/sc/';
34
35 protected function setUp() {
36 parent::setUp();
37 }
38
39 /*
40 * Test contact import for yyyy_mm_dd date format.
41 */
42 function testDateFormat_yyyy_mm_dd() {
43 $this->webtestLogin();
44
45 // Get sample import data.
46 list($headers, $rows) = $this->_individualCSVData_yyyy_mm_dd();
47
48 // Import and check Individual contacts in Skip mode and yyyy-mm-dd OR yyyymmdd dateformat.
49 $other = array('dateFormat' => 'yyyy-mm-dd OR yyyymmdd');
50
51 $this->importContacts($headers, $rows, 'Individual', 'Skip', array(), $other);
52 }
53
54 /*
55 * Test contact import for mm_dd_yy date format.
56 */
57 function testDateFormat_mm_dd_yy() {
58 $this->webtestLogin();
59
60 // Get sample import data.
61 list($headers, $rows) = $this->_individualCSVData_mm_dd_yy();
62
63 // Import and check Individual contacts in Skip mode and
64 // mm/dd/yy OR mm-dd-yy date format.
65 $other = array('dateFormat' => 'mm/dd/yy OR mm-dd-yy');
66
67 $this->importContacts($headers, $rows, 'Individual', 'Skip', array(), $other);
68 }
69
70 /*
71 * Test contact import for mm_dd_yyyy date format.
72 */
73 function testDateFormat_mm_dd_yyyy() {
74 // Logging in. Remember to wait for page to load. In most cases,
75 // you can rely on 30000 as the value that allows your test to pass, however,
76 // sometimes your test might fail because of this. In such cases, it's better to pick one element
77 // somewhere at the end of page and use waitForElementPresent on it - this assures you, that whole
78 // page contents loaded
79 $this->webtestLogin();
80
81 // Get sample import data.
82 list($headers, $rows) = $this->_individualCSVData_mm_dd_yyyy();
83
84 // Import and check Individual contacts in Skip mode and
85 // mm/dd/yyyy OR mm-dd-yyyy date format.
86 $other = array('dateFormat' => 'mm/dd/yyyy OR mm-dd-yyyy');
87
88 $this->importContacts($headers, $rows, 'Individual', 'Skip', array(), $other);
89 }
90
91 /*
92 * Test contact import for Month_dd_yyyy date format.
93 */
94 function testDateFormat_Month_dd_yyyy() {
95 // Logging in. Remember to wait for page to load. In most cases,
96 // you can rely on 30000 as the value that allows your test to pass, however,
97 // sometimes your test might fail because of this. In such cases, it's better to pick one element
98 // somewhere at the end of page and use waitForElementPresent on it - this assures you, that whole
99 // page contents loaded
100 $this->webtestLogin();
101
102 // Get sample import data.
103 list($headers, $rows) = $this->_individualCSVData_Month_dd_yyyy();
104
105 // Import and check Individual contacts in Skip mode and
106 // Month dd, yyyy date format.
107 $other = array('dateFormat' => 'Month dd, yyyy');
108
109 $this->importContacts($headers, $rows, 'Individual', 'Skip', array(), $other);
110 }
111
112 /*
113 * Test contact import for dd_mon_yy date format.
114 */
115 function testDateFormat_dd_mon_yy() {
116 // Logging in. Remember to wait for page to load. In most cases,
117 // you can rely on 30000 as the value that allows your test to pass, however,
118 // sometimes your test might fail because of this. In such cases, it's better to pick one element
119 // somewhere at the end of page and use waitForElementPresent on it - this assures you, that whole
120 // page contents loaded
121 $this->webtestLogin();
122
123 // Get sample import data.
124 list($headers, $rows) = $this->_individualCSVData_dd_mon_yy();
125
126 // Import and check Individual contacts in Skip mode and
127 // dd-mon-yy OR dd/mm/yy date format.
128 $other = array('dateFormat' => 'dd-mon-yy OR dd/mm/yy');
129
130 $this->importContacts($headers, $rows, 'Individual', 'Skip', array(), $other);
131 }
132
133 /*
134 * Test contact import for dd_mm_yyyy date format.
135 */
136 function testDateFormat_dd_mm_yyyy() {
137 // Logging in. Remember to wait for page to load. In most cases,
138 // you can rely on 30000 as the value that allows your test to pass, however,
139 // sometimes your test might fail because of this. In such cases, it's better to pick one element
140 // somewhere at the end of page and use waitForElementPresent on it - this assures you, that whole
141 // page contents loaded
142 $this->webtestLogin();
143
144 // Get sample import data.
145 list($headers, $rows) = $this->_individualCSVData_dd_mm_yyyy();
146
147 // Import and check Individual contacts in Skip mode and
148 // dd/mm/yyyy date format.
149 $other = array('dateFormat' => 'dd/mm/yyyy');
150
151 $this->importContacts($headers, $rows, 'Individual', 'Skip', array(), $other);
152 }
153
154 /*
155 * Helper function to provide data for contact import for Individuals and yyyy-mm-dd OR yyyymmdd dateformat.
156 */
157 function _individualCSVData_yyyy_mm_dd() {
158 $headers = array(
159 'first_name' => 'First Name',
160 'middle_name' => 'Middle Name',
161 'last_name' => 'Last Name',
162 'email' => 'Email',
163 'phone' => 'Phone',
164 'address_1' => 'Additional Address 1',
165 'address_2' => 'Additional Address 2',
166 'city' => 'City',
167 'state' => 'State',
168 'country' => 'Country',
169 'birth_date' => 'Birth Date',
170 );
171
172 $rows = array(
173 array('first_name' => substr(sha1(rand()), 0, 7),
174 'middle_name' => substr(sha1(rand()), 0, 7),
175 'last_name' => 'Anderson',
176 'email' => substr(sha1(rand()), 0, 7) . '@example.com',
177 'phone' => '6949912154',
178 'address_1' => 'Add 1',
179 'address_2' => 'Add 2',
180 'city' => 'Watson',
181 'state' => 'NY',
182 'country' => 'United States',
183 'birth_date' => '1998-12-25',
184 ),
185 array('first_name' => substr(sha1(rand()), 0, 7),
186 'middle_name' => substr(sha1(rand()), 0, 7),
187 'last_name' => 'Summerson',
188 'email' => substr(sha1(rand()), 0, 7) . '@example.com',
189 'phone' => '6944412154',
190 'address_1' => 'Add 1',
191 'address_2' => 'Add 2',
192 'city' => 'Watson',
193 'state' => 'NY',
194 'country' => 'United States',
195 'birth_date' => '1999-11-26',
196 ),
197 );
198
199 return array($headers, $rows);
200 }
201
202 /*
203 * Helper function to provide data for contact import for Individuals and mm/dd/yy OR mm-dd-yy dateformat.
204 */
205 function _individualCSVData_mm_dd_yy() {
206 $headers = array(
207 'first_name' => 'First Name',
208 'middle_name' => 'Middle Name',
209 'last_name' => 'Last Name',
210 'email' => 'Email',
211 'phone' => 'Phone',
212 'address_1' => 'Additional Address 1',
213 'address_2' => 'Additional Address 2',
214 'city' => 'City',
215 'state' => 'State',
216 'country' => 'Country',
217 'birth_date' => 'Birth Date',
218 );
219
220 $rows = array(
221 array('first_name' => substr(sha1(rand()), 0, 7),
222 'middle_name' => substr(sha1(rand()), 0, 7),
223 'last_name' => 'Anderson',
224 'email' => substr(sha1(rand()), 0, 7) . '@example.com',
225 'phone' => '6949912154',
226 'address_1' => 'Add 1',
227 'address_2' => 'Add 2',
228 'city' => 'Watson',
229 'state' => 'NY',
230 'country' => 'United States',
231 'birth_date' => '12/23/98',
232 ),
233 array('first_name' => substr(sha1(rand()), 0, 7),
234 'middle_name' => substr(sha1(rand()), 0, 7),
235 'last_name' => 'Summerson',
236 'email' => substr(sha1(rand()), 0, 7) . '@example.com',
237 'phone' => '6944412154',
238 'address_1' => 'Add 1',
239 'address_2' => 'Add 2',
240 'city' => 'Watson',
241 'state' => 'NY',
242 'country' => 'United States',
243 'birth_date' => '11/24/88',
244 ),
245 );
246
247 return array($headers, $rows);
248 }
249
250 /*
251 * Helper function to provide data for contact import for Individuals and mm/dd/yyyy OR mm-dd-yyyy dateformat.
252 */
253 function _individualCSVData_mm_dd_yyyy() {
254 $headers = array(
255 'first_name' => 'First Name',
256 'middle_name' => 'Middle Name',
257 'last_name' => 'Last Name',
258 'email' => 'Email',
259 'phone' => 'Phone',
260 'address_1' => 'Additional Address 1',
261 'address_2' => 'Additional Address 2',
262 'city' => 'City',
263 'state' => 'State',
264 'country' => 'Country',
265 'birth_date' => 'Birth Date',
266 );
267
268 $rows = array(
269 array('first_name' => substr(sha1(rand()), 0, 7),
270 'middle_name' => substr(sha1(rand()), 0, 7),
271 'last_name' => 'Anderson',
272 'email' => substr(sha1(rand()), 0, 7) . '@example.com',
273 'phone' => '6949912154',
274 'address_1' => 'Add 1',
275 'address_2' => 'Add 2',
276 'city' => 'Watson',
277 'state' => 'NY',
278 'country' => 'United States',
279 'birth_date' => '11/12/1995',
280 ),
281 array('first_name' => substr(sha1(rand()), 0, 7),
282 'middle_name' => substr(sha1(rand()), 0, 7),
283 'last_name' => 'Summerson',
284 'email' => substr(sha1(rand()), 0, 7) . '@example.com',
285 'phone' => '6944412154',
286 'address_1' => 'Add 1',
287 'address_2' => 'Add 2',
288 'city' => 'Watson',
289 'state' => 'NY',
290 'country' => 'United States',
291 'birth_date' => '12/12/1995',
292 ),
293 );
294
295 return array($headers, $rows);
296 }
297
298 /*
299 * Helper function to provide data for contact import for Individuals and Month dd, yyyy dateformat.
300 */
301 function _individualCSVData_Month_dd_yyyy() {
302 $headers = array(
303 'first_name' => 'First Name',
304 'middle_name' => 'Middle Name',
305 'last_name' => 'Last Name',
306 'email' => 'Email',
307 'phone' => 'Phone',
308 'address_1' => 'Additional Address 1',
309 'address_2' => 'Additional Address 2',
310 'city' => 'City',
311 'state' => 'State',
312 'country' => 'Country',
313 'birth_date' => 'Birth Date',
314 );
315
316 $rows = array(
317 array('first_name' => substr(sha1(rand()), 0, 7),
318 'middle_name' => substr(sha1(rand()), 0, 7),
319 'last_name' => 'Anderson',
320 'email' => substr(sha1(rand()), 0, 7) . '@example.com',
321 'phone' => '6949912154',
322 'address_1' => 'Add 1',
323 'address_2' => 'Add 2',
324 'city' => 'Watson',
325 'state' => 'NY',
326 'country' => 'United States',
327 'birth_date' => 'December 12, 1998',
328 ),
329 array('first_name' => substr(sha1(rand()), 0, 7),
330 'middle_name' => substr(sha1(rand()), 0, 7),
331 'last_name' => 'Summerson',
332 'email' => substr(sha1(rand()), 0, 7) . '@example.com',
333 'phone' => '6944412154',
334 'address_1' => 'Add 1',
335 'address_2' => 'Add 2',
336 'city' => 'Watson',
337 'state' => 'NY',
338 'country' => 'United States',
339 'birth_date' => 'December 13, 1998',
340 ),
341 );
342
343 return array($headers, $rows);
344 }
345
346 /*
347 * Helper function to provide data for contact import for Individuals and dd-mon-yy OR dd/mm/yy dateformat.
348 */
349 function _individualCSVData_dd_mon_yy() {
350 $headers = array(
351 'first_name' => 'First Name',
352 'middle_name' => 'Middle Name',
353 'last_name' => 'Last Name',
354 'email' => 'Email',
355 'phone' => 'Phone',
356 'address_1' => 'Additional Address 1',
357 'address_2' => 'Additional Address 2',
358 'city' => 'City',
359 'state' => 'State',
360 'country' => 'Country',
361 'birth_date' => 'Birth Date',
362 );
363
364 $rows = array(
365 array('first_name' => substr(sha1(rand()), 0, 7),
366 'middle_name' => substr(sha1(rand()), 0, 7),
367 'last_name' => 'Anderson',
368 'email' => substr(sha1(rand()), 0, 7) . '@example.com',
369 'phone' => '6949912154',
370 'address_1' => 'Add 1',
371 'address_2' => 'Add 2',
372 'city' => 'Watson',
373 'state' => 'NY',
374 'country' => 'United States',
375 'birth_date' => '25/12/98',
376 ),
377 array('first_name' => substr(sha1(rand()), 0, 7),
378 'middle_name' => substr(sha1(rand()), 0, 7),
379 'last_name' => 'Summerson',
380 'email' => substr(sha1(rand()), 0, 7) . '@example.com',
381 'phone' => '6944412154',
382 'address_1' => 'Add 1',
383 'address_2' => 'Add 2',
384 'city' => 'Watson',
385 'state' => 'NY',
386 'country' => 'United States',
387 'birth_date' => '26/12/99',
388 ),
389 );
390
391 return array($headers, $rows);
392 }
393
394 /*
395 * Helper function to provide data for contact import for Individuals and dd/mm/yyyy dateformat.
396 */
397 function _individualCSVData_dd_mm_yyyy() {
398 $headers = array(
399 'first_name' => 'First Name',
400 'middle_name' => 'Middle Name',
401 'last_name' => 'Last Name',
402 'email' => 'Email',
403 'phone' => 'Phone',
404 'address_1' => 'Additional Address 1',
405 'address_2' => 'Additional Address 2',
406 'city' => 'City',
407 'state' => 'State',
408 'country' => 'Country',
409 'birth_date' => 'Birth Date',
410 );
411
412 $rows = array(
413 array('first_name' => substr(sha1(rand()), 0, 7),
414 'middle_name' => substr(sha1(rand()), 0, 7),
415 'last_name' => 'Anderson',
416 'email' => substr(sha1(rand()), 0, 7) . '@example.com',
417 'phone' => '6949912154',
418 'address_1' => 'Add 1',
419 'address_2' => 'Add 2',
420 'city' => 'Watson',
421 'state' => 'NY',
422 'country' => 'United States',
423 'birth_date' => '25/12/1998',
424 ),
425 array('first_name' => substr(sha1(rand()), 0, 7),
426 'middle_name' => substr(sha1(rand()), 0, 7),
427 'last_name' => 'Summerson',
428 'email' => substr(sha1(rand()), 0, 7) . '@example.com',
429 'phone' => '6944412154',
430 'address_1' => 'Add 1',
431 'address_2' => 'Add 2',
432 'city' => 'Watson',
433 'state' => 'NY',
434 'country' => 'United States',
435 'birth_date' => '24/11/1996',
436 ),
437 );
438
439 return array($headers, $rows);
440 }
441 }
442