Merge pull request #209 from davecivicrm/CRM-12145
[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 require_once 'WebTest/Import/ImportCiviSeleniumTestCase.php';
28 class WebTest_Import_DateFormatTest extends ImportCiviSeleniumTestCase {
29
30 protected $captureScreenshotOnFailure = TRUE;
31 protected $screenshotPath = '/var/www/api.dev.civicrm.org/public/sc';
32 protected $screenshotUrl = 'http://api.dev.civicrm.org/sc/';
33
34 protected function setUp() {
35 parent::setUp();
36 }
37
38 /*
39 * Test contact import for yyyy_mm_dd date format.
40 */
41 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 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 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 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 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 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 function _individualCSVData_yyyy_mm_dd() {
157 $headers = array(
158 'first_name' => 'First Name',
159 'middle_name' => 'Middle Name',
160 'last_name' => 'Last Name',
161 'email' => 'Email',
162 'phone' => 'Phone',
163 'address_1' => 'Additional Address 1',
164 'address_2' => 'Additional Address 2',
165 'city' => 'City',
166 'state' => 'State',
167 'country' => 'Country',
168 'birth_date' => 'Birth Date',
169 );
170
171 $rows = array(
172 array('first_name' => substr(sha1(rand()), 0, 7),
173 'middle_name' => substr(sha1(rand()), 0, 7),
174 'last_name' => 'Anderson',
175 'email' => substr(sha1(rand()), 0, 7) . '@example.com',
176 'phone' => '6949912154',
177 'address_1' => 'Add 1',
178 'address_2' => 'Add 2',
179 'city' => 'Watson',
180 'state' => 'NY',
181 'country' => 'United States',
182 'birth_date' => '1998-12-25',
183 ),
184 array('first_name' => substr(sha1(rand()), 0, 7),
185 'middle_name' => substr(sha1(rand()), 0, 7),
186 'last_name' => 'Summerson',
187 'email' => substr(sha1(rand()), 0, 7) . '@example.com',
188 'phone' => '6944412154',
189 'address_1' => 'Add 1',
190 'address_2' => 'Add 2',
191 'city' => 'Watson',
192 'state' => 'NY',
193 'country' => 'United States',
194 'birth_date' => '1999-11-26',
195 ),
196 );
197
198 return array($headers, $rows);
199 }
200
201 /*
202 * Helper function to provide data for contact import for Individuals and mm/dd/yy OR mm-dd-yy dateformat.
203 */
204 function _individualCSVData_mm_dd_yy() {
205 $headers = array(
206 'first_name' => 'First Name',
207 'middle_name' => 'Middle Name',
208 'last_name' => 'Last Name',
209 'email' => 'Email',
210 'phone' => 'Phone',
211 'address_1' => 'Additional Address 1',
212 'address_2' => 'Additional Address 2',
213 'city' => 'City',
214 'state' => 'State',
215 'country' => 'Country',
216 'birth_date' => 'Birth Date',
217 );
218
219 $rows = array(
220 array('first_name' => substr(sha1(rand()), 0, 7),
221 'middle_name' => substr(sha1(rand()), 0, 7),
222 'last_name' => 'Anderson',
223 'email' => substr(sha1(rand()), 0, 7) . '@example.com',
224 'phone' => '6949912154',
225 'address_1' => 'Add 1',
226 'address_2' => 'Add 2',
227 'city' => 'Watson',
228 'state' => 'NY',
229 'country' => 'United States',
230 'birth_date' => '12/23/98',
231 ),
232 array('first_name' => substr(sha1(rand()), 0, 7),
233 'middle_name' => substr(sha1(rand()), 0, 7),
234 'last_name' => 'Summerson',
235 'email' => substr(sha1(rand()), 0, 7) . '@example.com',
236 'phone' => '6944412154',
237 'address_1' => 'Add 1',
238 'address_2' => 'Add 2',
239 'city' => 'Watson',
240 'state' => 'NY',
241 'country' => 'United States',
242 'birth_date' => '11/24/88',
243 ),
244 );
245
246 return array($headers, $rows);
247 }
248
249 /*
250 * Helper function to provide data for contact import for Individuals and mm/dd/yyyy OR mm-dd-yyyy dateformat.
251 */
252 function _individualCSVData_mm_dd_yyyy() {
253 $headers = array(
254 'first_name' => 'First Name',
255 'middle_name' => 'Middle Name',
256 'last_name' => 'Last Name',
257 'email' => 'Email',
258 'phone' => 'Phone',
259 'address_1' => 'Additional Address 1',
260 'address_2' => 'Additional Address 2',
261 'city' => 'City',
262 'state' => 'State',
263 'country' => 'Country',
264 'birth_date' => 'Birth Date',
265 );
266
267 $rows = array(
268 array('first_name' => substr(sha1(rand()), 0, 7),
269 'middle_name' => substr(sha1(rand()), 0, 7),
270 'last_name' => 'Anderson',
271 'email' => substr(sha1(rand()), 0, 7) . '@example.com',
272 'phone' => '6949912154',
273 'address_1' => 'Add 1',
274 'address_2' => 'Add 2',
275 'city' => 'Watson',
276 'state' => 'NY',
277 'country' => 'United States',
278 'birth_date' => '11/12/1995',
279 ),
280 array('first_name' => substr(sha1(rand()), 0, 7),
281 'middle_name' => substr(sha1(rand()), 0, 7),
282 'last_name' => 'Summerson',
283 'email' => substr(sha1(rand()), 0, 7) . '@example.com',
284 'phone' => '6944412154',
285 'address_1' => 'Add 1',
286 'address_2' => 'Add 2',
287 'city' => 'Watson',
288 'state' => 'NY',
289 'country' => 'United States',
290 'birth_date' => '12/12/1995',
291 ),
292 );
293
294 return array($headers, $rows);
295 }
296
297 /*
298 * Helper function to provide data for contact import for Individuals and Month dd, yyyy dateformat.
299 */
300 function _individualCSVData_Month_dd_yyyy() {
301 $headers = array(
302 'first_name' => 'First Name',
303 'middle_name' => 'Middle Name',
304 'last_name' => 'Last Name',
305 'email' => 'Email',
306 'phone' => 'Phone',
307 'address_1' => 'Additional Address 1',
308 'address_2' => 'Additional Address 2',
309 'city' => 'City',
310 'state' => 'State',
311 'country' => 'Country',
312 'birth_date' => 'Birth Date',
313 );
314
315 $rows = array(
316 array('first_name' => substr(sha1(rand()), 0, 7),
317 'middle_name' => substr(sha1(rand()), 0, 7),
318 'last_name' => 'Anderson',
319 'email' => substr(sha1(rand()), 0, 7) . '@example.com',
320 'phone' => '6949912154',
321 'address_1' => 'Add 1',
322 'address_2' => 'Add 2',
323 'city' => 'Watson',
324 'state' => 'NY',
325 'country' => 'United States',
326 'birth_date' => 'December 12, 1998',
327 ),
328 array('first_name' => substr(sha1(rand()), 0, 7),
329 'middle_name' => substr(sha1(rand()), 0, 7),
330 'last_name' => 'Summerson',
331 'email' => substr(sha1(rand()), 0, 7) . '@example.com',
332 'phone' => '6944412154',
333 'address_1' => 'Add 1',
334 'address_2' => 'Add 2',
335 'city' => 'Watson',
336 'state' => 'NY',
337 'country' => 'United States',
338 'birth_date' => 'December 13, 1998',
339 ),
340 );
341
342 return array($headers, $rows);
343 }
344
345 /*
346 * Helper function to provide data for contact import for Individuals and dd-mon-yy OR dd/mm/yy dateformat.
347 */
348 function _individualCSVData_dd_mon_yy() {
349 $headers = array(
350 'first_name' => 'First Name',
351 'middle_name' => 'Middle Name',
352 'last_name' => 'Last Name',
353 'email' => 'Email',
354 'phone' => 'Phone',
355 'address_1' => 'Additional Address 1',
356 'address_2' => 'Additional Address 2',
357 'city' => 'City',
358 'state' => 'State',
359 'country' => 'Country',
360 'birth_date' => 'Birth Date',
361 );
362
363 $rows = array(
364 array('first_name' => substr(sha1(rand()), 0, 7),
365 'middle_name' => substr(sha1(rand()), 0, 7),
366 'last_name' => 'Anderson',
367 'email' => substr(sha1(rand()), 0, 7) . '@example.com',
368 'phone' => '6949912154',
369 'address_1' => 'Add 1',
370 'address_2' => 'Add 2',
371 'city' => 'Watson',
372 'state' => 'NY',
373 'country' => 'United States',
374 'birth_date' => '25/12/98',
375 ),
376 array('first_name' => substr(sha1(rand()), 0, 7),
377 'middle_name' => substr(sha1(rand()), 0, 7),
378 'last_name' => 'Summerson',
379 'email' => substr(sha1(rand()), 0, 7) . '@example.com',
380 'phone' => '6944412154',
381 'address_1' => 'Add 1',
382 'address_2' => 'Add 2',
383 'city' => 'Watson',
384 'state' => 'NY',
385 'country' => 'United States',
386 'birth_date' => '26/12/99',
387 ),
388 );
389
390 return array($headers, $rows);
391 }
392
393 /*
394 * Helper function to provide data for contact import for Individuals and dd/mm/yyyy dateformat.
395 */
396 function _individualCSVData_dd_mm_yyyy() {
397 $headers = array(
398 'first_name' => 'First Name',
399 'middle_name' => 'Middle Name',
400 'last_name' => 'Last Name',
401 'email' => 'Email',
402 'phone' => 'Phone',
403 'address_1' => 'Additional Address 1',
404 'address_2' => 'Additional Address 2',
405 'city' => 'City',
406 'state' => 'State',
407 'country' => 'Country',
408 'birth_date' => 'Birth Date',
409 );
410
411 $rows = array(
412 array('first_name' => substr(sha1(rand()), 0, 7),
413 'middle_name' => substr(sha1(rand()), 0, 7),
414 'last_name' => 'Anderson',
415 'email' => substr(sha1(rand()), 0, 7) . '@example.com',
416 'phone' => '6949912154',
417 'address_1' => 'Add 1',
418 'address_2' => 'Add 2',
419 'city' => 'Watson',
420 'state' => 'NY',
421 'country' => 'United States',
422 'birth_date' => '25/12/1998',
423 ),
424 array('first_name' => substr(sha1(rand()), 0, 7),
425 'middle_name' => substr(sha1(rand()), 0, 7),
426 'last_name' => 'Summerson',
427 'email' => substr(sha1(rand()), 0, 7) . '@example.com',
428 'phone' => '6944412154',
429 'address_1' => 'Add 1',
430 'address_2' => 'Add 2',
431 'city' => 'Watson',
432 'state' => 'NY',
433 'country' => 'United States',
434 'birth_date' => '24/11/1996',
435 ),
436 );
437
438 return array($headers, $rows);
439 }
440 }
441