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