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