Révision 599a39cd
Ajouté par Assos Assos il y a environ 3 ans
drupal7/sites/all/modules/date/date_repeat/tests/date_repeat_form.test | ||
---|---|---|
5 | 5 |
* Test Date Repeat form. |
6 | 6 |
*/ |
7 | 7 |
|
8 |
/** |
|
9 |
* Test Date Repeat form. |
|
10 |
*/ |
|
8 | 11 |
class DateRepeatFormTestCase extends DrupalWebTestCase { |
9 | 12 |
protected $privileged_user; |
10 | 13 |
|
... | ... | |
17 | 20 |
} |
18 | 21 |
|
19 | 22 |
/** |
20 |
* Implements setUp().
|
|
23 |
* {@inheritdoc}
|
|
21 | 24 |
*/ |
22 |
public function setUp() { |
|
25 |
public function setUp(array $modules = array()) {
|
|
23 | 26 |
// Load the date_repeat module. |
24 |
parent::setUp('field', 'field_ui', 'date_api', 'date_repeat', 'date', 'date_popup', 'date_repeat_field'); |
|
27 |
$modules[] = 'field'; |
|
28 |
$modules[] = 'field_ui'; |
|
29 |
$modules[] = 'date_api'; |
|
30 |
$modules[] = 'date_repeat'; |
|
31 |
$modules[] = 'date'; |
|
32 |
$modules[] = 'date_popup'; |
|
33 |
$modules[] = 'date_repeat_field'; |
|
34 |
parent::setUp($modules); |
|
25 | 35 |
|
26 | 36 |
// Create and log in our privileged user. |
27 | 37 |
$this->privileged_user = $this->drupalCreateUser(array( |
28 |
'administer content types', 'administer nodes', 'bypass node access', 'view date repeats', 'administer fields' |
|
38 |
'administer content types', 'administer nodes', 'bypass node access', 'view date repeats', 'administer fields',
|
|
29 | 39 |
)); |
30 | 40 |
$this->drupalLogin($this->privileged_user); |
31 | 41 |
|
32 | 42 |
variable_set('date_format_short', 'Y-m-d H:i'); |
33 | 43 |
} |
34 | 44 |
|
45 |
/** |
|
46 |
* Test the Date Repeat form. |
|
47 |
*/ |
|
35 | 48 |
public function testDateRepeatForm() { |
36 | 49 |
$edit = array(); |
37 | 50 |
$edit['name'] = 'Date'; |
... | ... | |
84 | 97 |
$form_edit = $this->dateForm($options, 'daily_1', FALSE, 'exclude_include'); |
85 | 98 |
$this->verifyDateForm($form_edit); |
86 | 99 |
|
87 |
// Weekly tests |
|
88 |
|
|
100 |
// Weekly tests. |
|
89 | 101 |
$form_edit = $this->dateForm($options, 'weekly_1'); |
90 | 102 |
$this->verifyDateForm($form_edit); |
91 | 103 |
|
... | ... | |
110 | 122 |
$form_edit = $this->dateForm($options, 'weekly_4', TRUE); |
111 | 123 |
$this->verifyDateForm($form_edit); |
112 | 124 |
|
113 |
// Monthly tests |
|
114 |
|
|
125 |
// Monthly tests. |
|
115 | 126 |
$form_edit = $this->dateForm($options, 'monthly_1'); |
116 | 127 |
$this->verifyDateForm($form_edit); |
117 | 128 |
|
... | ... | |
148 | 159 |
$form_edit = $this->dateForm($options, 'monthly_6', TRUE); |
149 | 160 |
$this->verifyDateForm($form_edit); |
150 | 161 |
|
151 |
// Yearly tests |
|
152 |
|
|
162 |
// Yearly tests. |
|
153 | 163 |
$form_edit = $this->dateForm($options, 'yearly_1'); |
154 | 164 |
$this->verifyDateForm($form_edit); |
155 | 165 |
|
... | ... | |
197 | 207 |
$edit['body[und][0][value]'] = $this->randomName(16); |
198 | 208 |
$current_year = date('Y'); |
199 | 209 |
|
200 |
|
|
201 | 210 |
switch ($options) { |
202 | 211 |
case 'select': |
203 | 212 |
$edit['field_test[und][0][value][year]'] = $current_year; |
... | ... | |
206 | 215 |
$edit['field_test[und][0][value][hour]'] = '10'; |
207 | 216 |
$edit['field_test[und][0][value][minute]'] = '30'; |
208 | 217 |
break; |
218 |
|
|
209 | 219 |
case 'text': |
210 | 220 |
$edit['field_test[und][0][value][date]'] = format_string('!year-10-07 10:30', array('!year' => $current_year)); |
211 | 221 |
break; |
222 |
|
|
212 | 223 |
case 'popup': |
213 | 224 |
$edit['field_test[und][0][value][date]'] = format_string('!year-10-07', array('!year' => $current_year)); |
214 | 225 |
$edit['field_test[und][0][value][time]'] = '10:30'; |
215 | 226 |
break; |
216 | 227 |
} |
217 | 228 |
|
218 |
// Tests that Date repeat settings function properly |
|
229 |
// Tests that Date repeat settings function properly.
|
|
219 | 230 |
if ($test_id !== NULL) { |
220 | 231 |
$edit['field_test[und][0][show_repeat_settings]'] = TRUE; |
221 | 232 |
$count = 5; |
222 | 233 |
|
223 | 234 |
switch ($test_id) { |
224 |
// Daily test cases |
|
235 |
// Daily test cases.
|
|
225 | 236 |
case 'daily_1': |
226 | 237 |
$edit['field_test[und][0][rrule][FREQ]'] = 'DAILY'; |
227 | 238 |
$edit['field_test[und][0][rrule][daily][byday_radios]'] = 'INTERVAL'; |
228 | 239 |
$edit['field_test[und][0][rrule][daily][INTERVAL_child]'] = 2; |
229 | 240 |
break; |
241 |
|
|
230 | 242 |
case 'daily_2': |
231 | 243 |
$edit['field_test[und][0][rrule][FREQ]'] = 'DAILY'; |
232 | 244 |
$edit['field_test[und][0][rrule][daily][byday_radios]'] = 'every_weekday'; |
233 | 245 |
break; |
246 |
|
|
234 | 247 |
case 'daily_3': |
235 | 248 |
$edit['field_test[und][0][rrule][FREQ]'] = 'DAILY'; |
236 | 249 |
$edit['field_test[und][0][rrule][daily][byday_radios]'] = 'every_mo_we_fr'; |
237 | 250 |
break; |
251 |
|
|
238 | 252 |
case 'daily_4': |
239 | 253 |
$edit['field_test[und][0][rrule][FREQ]'] = 'DAILY'; |
240 | 254 |
$edit['field_test[und][0][rrule][daily][byday_radios]'] = 'every_tu_th'; |
241 | 255 |
break; |
242 | 256 |
|
243 |
// Weekly test cases |
|
257 |
// Weekly test cases.
|
|
244 | 258 |
case 'weekly_1': |
245 | 259 |
$edit['field_test[und][0][rrule][FREQ]'] = 'WEEKLY'; |
246 | 260 |
$edit['field_test[und][0][rrule][weekly][BYDAY][MO]'] = TRUE; |
247 | 261 |
$edit['field_test[und][0][rrule][weekly][BYDAY][WE]'] = TRUE; |
248 | 262 |
$edit['field_test[und][0][rrule][weekly][BYDAY][TH]'] = TRUE; |
249 | 263 |
break; |
264 |
|
|
250 | 265 |
case 'weekly_2': |
251 | 266 |
$edit['field_test[und][0][rrule][FREQ]'] = 'WEEKLY'; |
252 | 267 |
$edit['field_test[und][0][rrule][weekly][INTERVAL]'] = 1; |
253 | 268 |
$edit['field_test[und][0][rrule][weekly][BYDAY][MO]'] = TRUE; |
254 | 269 |
$edit['field_test[und][0][rrule][weekly][BYDAY][FR]'] = TRUE; |
255 | 270 |
break; |
271 |
|
|
256 | 272 |
case 'weekly_3': |
257 | 273 |
$edit['field_test[und][0][rrule][FREQ]'] = 'WEEKLY'; |
258 | 274 |
$edit['field_test[und][0][rrule][weekly][INTERVAL]'] = 2; |
259 | 275 |
$edit['field_test[und][0][rrule][weekly][BYDAY][TU]'] = TRUE; |
260 | 276 |
$edit['field_test[und][0][rrule][weekly][BYDAY][TH]'] = TRUE; |
261 | 277 |
break; |
278 |
|
|
262 | 279 |
case 'weekly_4': |
263 | 280 |
$edit['field_test[und][0][rrule][FREQ]'] = 'WEEKLY'; |
264 | 281 |
$edit['field_test[und][0][rrule][weekly][INTERVAL]'] = 10; |
... | ... | |
269 | 286 |
$edit['field_test[und][0][rrule][weekly][BYDAY][FR]'] = TRUE; |
270 | 287 |
break; |
271 | 288 |
|
272 |
// Monthly test cases |
|
289 |
// Monthly test cases.
|
|
273 | 290 |
case 'monthly_1': |
274 | 291 |
$edit['field_test[und][0][rrule][FREQ]'] = 'MONTHLY'; |
275 | 292 |
$edit['field_test[und][0][rrule][monthly][day_month]'] = 'BYDAY_BYMONTH'; |
276 | 293 |
$edit['field_test[und][0][rrule][monthly][BYDAY_BYMONTH_child][BYDAY_COUNT]'] = '+1'; |
277 | 294 |
$edit['field_test[und][0][rrule][monthly][BYDAY_BYMONTH_child][BYDAY_DAY]'] = 'FR'; |
278 | 295 |
break; |
296 |
|
|
279 | 297 |
case 'monthly_2': |
280 | 298 |
$edit['field_test[und][0][rrule][FREQ]'] = 'MONTHLY'; |
281 | 299 |
$edit['field_test[und][0][rrule][monthly][day_month]'] = 'BYDAY_BYMONTH'; |
... | ... | |
288 | 306 |
$edit['field_test[und][0][rrule][monthly][BYDAY_BYMONTH_child][BYMONTH][9]'] = TRUE; |
289 | 307 |
$edit['field_test[und][0][rrule][monthly][BYDAY_BYMONTH_child][BYMONTH][11]'] = TRUE; |
290 | 308 |
break; |
309 |
|
|
291 | 310 |
case 'monthly_3': |
292 | 311 |
$edit['field_test[und][0][rrule][FREQ]'] = 'MONTHLY'; |
293 | 312 |
$edit['field_test[und][0][rrule][monthly][day_month]'] = 'BYDAY_BYMONTH'; |
... | ... | |
296 | 315 |
$edit['field_test[und][0][rrule][monthly][BYDAY_BYMONTH_child][BYMONTH][6]'] = TRUE; |
297 | 316 |
$edit['field_test[und][0][rrule][monthly][BYDAY_BYMONTH_child][BYMONTH][12]'] = TRUE; |
298 | 317 |
break; |
318 |
|
|
299 | 319 |
case 'monthly_4': |
300 | 320 |
$edit['field_test[und][0][rrule][FREQ]'] = 'MONTHLY'; |
301 | 321 |
$edit['field_test[und][0][rrule][monthly][day_month]'] = 'BYMONTHDAY_BYMONTH'; |
302 | 322 |
$edit['field_test[und][0][rrule][monthly][BYMONTHDAY_BYMONTH_child][BYMONTHDAY]'] = '10'; |
303 | 323 |
break; |
324 |
|
|
304 | 325 |
case 'monthly_5': |
305 | 326 |
$edit['field_test[und][0][rrule][FREQ]'] = 'MONTHLY'; |
306 | 327 |
$edit['field_test[und][0][rrule][monthly][day_month]'] = 'BYMONTHDAY_BYMONTH'; |
... | ... | |
309 | 330 |
$edit['field_test[und][0][rrule][monthly][BYMONTHDAY_BYMONTH_child][BYMONTH][2]'] = TRUE; |
310 | 331 |
$edit['field_test[und][0][rrule][monthly][BYMONTHDAY_BYMONTH_child][BYMONTH][3]'] = TRUE; |
311 | 332 |
break; |
333 |
|
|
312 | 334 |
case 'monthly_6': |
313 | 335 |
$edit['field_test[und][0][rrule][FREQ]'] = 'MONTHLY'; |
314 | 336 |
$edit['field_test[und][0][rrule][monthly][day_month]'] = 'BYMONTHDAY_BYMONTH'; |
... | ... | |
318 | 340 |
$edit['field_test[und][0][rrule][monthly][BYMONTHDAY_BYMONTH_child][BYMONTH][6]'] = TRUE; |
319 | 341 |
break; |
320 | 342 |
|
321 |
// Yearly test cases |
|
343 |
// Yearly test cases.
|
|
322 | 344 |
case 'yearly_1': |
323 | 345 |
$edit['field_test[und][0][rrule][FREQ]'] = 'YEARLY'; |
324 | 346 |
$edit['field_test[und][0][rrule][yearly][day_month]'] = 'BYDAY_BYMONTH'; |
325 | 347 |
$edit['field_test[und][0][rrule][yearly][BYDAY_BYMONTH_child][BYDAY_COUNT]'] = '+1'; |
326 | 348 |
$edit['field_test[und][0][rrule][yearly][BYDAY_BYMONTH_child][BYDAY_DAY]'] = 'FR'; |
327 | 349 |
break; |
350 |
|
|
328 | 351 |
case 'yearly_2': |
329 | 352 |
$edit['field_test[und][0][rrule][FREQ]'] = 'YEARLY'; |
330 | 353 |
$edit['field_test[und][0][rrule][yearly][INTERVAL]'] = 2; |
... | ... | |
338 | 361 |
$edit['field_test[und][0][rrule][yearly][BYDAY_BYMONTH_child][BYMONTH][9]'] = TRUE; |
339 | 362 |
$edit['field_test[und][0][rrule][yearly][BYDAY_BYMONTH_child][BYMONTH][11]'] = TRUE; |
340 | 363 |
break; |
364 |
|
|
341 | 365 |
case 'yearly_3': |
342 | 366 |
$edit['field_test[und][0][rrule][FREQ]'] = 'YEARLY'; |
343 | 367 |
$edit['field_test[und][0][rrule][yearly][INTERVAL]'] = 3; |
... | ... | |
347 | 371 |
$edit['field_test[und][0][rrule][yearly][BYDAY_BYMONTH_child][BYMONTH][6]'] = TRUE; |
348 | 372 |
$edit['field_test[und][0][rrule][yearly][BYDAY_BYMONTH_child][BYMONTH][12]'] = TRUE; |
349 | 373 |
break; |
374 |
|
|
350 | 375 |
case 'yearly_4': |
351 | 376 |
$edit['field_test[und][0][rrule][FREQ]'] = 'YEARLY'; |
352 | 377 |
$edit['field_test[und][0][rrule][yearly][day_month]'] = 'BYMONTHDAY_BYMONTH'; |
353 | 378 |
$edit['field_test[und][0][rrule][yearly][BYMONTHDAY_BYMONTH_child][BYMONTHDAY]'] = '10'; |
354 | 379 |
break; |
380 |
|
|
355 | 381 |
case 'yearly_5': |
356 | 382 |
$edit['field_test[und][0][rrule][FREQ]'] = 'YEARLY'; |
357 | 383 |
$edit['field_test[und][0][rrule][yearly][INTERVAL]'] = 2; |
... | ... | |
361 | 387 |
$edit['field_test[und][0][rrule][yearly][BYMONTHDAY_BYMONTH_child][BYMONTH][2]'] = TRUE; |
362 | 388 |
$edit['field_test[und][0][rrule][yearly][BYMONTHDAY_BYMONTH_child][BYMONTH][3]'] = TRUE; |
363 | 389 |
break; |
390 |
|
|
364 | 391 |
case 'yearly_6': |
365 | 392 |
$edit['field_test[und][0][rrule][FREQ]'] = 'YEARLY'; |
366 | 393 |
$edit['field_test[und][0][rrule][yearly][INTERVAL]'] = 3; |
... | ... | |
372 | 399 |
break; |
373 | 400 |
} |
374 | 401 |
|
375 |
// Test COUNT or UNTIL (default) |
|
402 |
// Test COUNT or UNTIL (default).
|
|
376 | 403 |
if ($is_count) { |
377 | 404 |
$edit['field_test[und][0][rrule][range_of_repeat]'] = 'COUNT'; |
378 | 405 |
$edit['field_test[und][0][rrule][count_child]'] = $count; |
... | ... | |
382 | 409 |
$date = array( |
383 | 410 |
'year' => $current_year + 1, |
384 | 411 |
'month' => '10', |
385 |
'day' => '07' |
|
412 |
'day' => '07',
|
|
386 | 413 |
); |
387 | 414 |
$edit += $this->formatDateForRRULEInputs('field_test[und][0][rrule][until_child]', $options, $date); |
388 | 415 |
} |
389 | 416 |
|
390 |
// Test date exceptions and/or additions |
|
417 |
// Test date exceptions and/or additions.
|
|
391 | 418 |
if ($exclude_include !== NULL) { |
392 | 419 |
$exclude_include_edit = array(); |
393 | 420 |
switch ($exclude_include) { |
... | ... | |
396 | 423 |
$date = array( |
397 | 424 |
'year' => $current_year, |
398 | 425 |
'month' => '10', |
399 |
'day' => '07' |
|
426 |
'day' => '07',
|
|
400 | 427 |
); |
401 | 428 |
$exclude_include_edit += $this->formatDateForRRULEInputs('field_test[und][0][rrule][exceptions][EXDATE][0]', $options, $date); |
402 | 429 |
break; |
430 |
|
|
403 | 431 |
case 'include': |
404 | 432 |
$exclude_include_edit['field_test[und][0][rrule][show_additions]'] = TRUE; |
405 | 433 |
$date = array( |
406 | 434 |
'year' => $current_year + 3, |
407 | 435 |
'month' => '10', |
408 |
'day' => '07' |
|
436 |
'day' => '07',
|
|
409 | 437 |
); |
410 | 438 |
$exclude_include_edit += $this->formatDateForRRULEInputs('field_test[und][0][rrule][additions][RDATE][0]', $options, $date); |
411 | 439 |
break; |
440 |
|
|
412 | 441 |
case 'exclude_include': |
413 | 442 |
$exclude_include_edit['field_test[und][0][rrule][show_exceptions]'] = TRUE; |
414 | 443 |
$date = array( |
415 | 444 |
'year' => $current_year, |
416 | 445 |
'month' => '10', |
417 |
'day' => '07' |
|
446 |
'day' => '07',
|
|
418 | 447 |
); |
419 | 448 |
$exclude_include_edit += $this->formatDateForRRULEInputs('field_test[und][0][rrule][exceptions][EXDATE][0]', $options, $date); |
420 | 449 |
|
... | ... | |
422 | 451 |
$date = array( |
423 | 452 |
'year' => $current_year + 3, |
424 | 453 |
'month' => '10', |
425 |
'day' => '07' |
|
454 |
'day' => '07',
|
|
426 | 455 |
); |
427 | 456 |
$exclude_include_edit += $this->formatDateForRRULEInputs('field_test[und][0][rrule][additions][RDATE][0]', $options, $date); |
428 | 457 |
break; |
... | ... | |
434 | 463 |
$this->drupalPost('node/add/date', $edit, t('Save')); |
435 | 464 |
$this->assertText($edit['body[und][0][value]'], 'Test node has been created'); |
436 | 465 |
|
437 |
// Return the settings for later use in verification |
|
466 |
// Return the settings for later use in verification.
|
|
438 | 467 |
return $edit; |
439 | 468 |
} |
440 | 469 |
|
... | ... | |
456 | 485 |
$edit = array(); |
457 | 486 |
$edit['fields[_add_new_field][label]'] = 'Test'; |
458 | 487 |
$edit['fields[_add_new_field][field_name]'] = 'test'; |
459 |
$edit['fields[_add_new_field][weight]'] = '-4';
|
|
488 |
$edit['fields[_add_new_field][weight]'] = '-100';
|
|
460 | 489 |
$edit['fields[_add_new_field][type]'] = $type; |
461 | 490 |
$edit['fields[_add_new_field][widget_type]'] = $widget; |
462 | 491 |
|
... | ... | |
469 | 498 |
switch ($widget) { |
470 | 499 |
case 'select': |
471 | 500 |
case 'popup': |
472 |
$instance_edit['instance[widget][settings][year_range][years_back]'] = '-5'; |
|
473 |
$instance_edit['instance[widget][settings][year_range][years_forward]'] = '+5'; |
|
474 |
break; |
|
501 |
$instance_edit['instance[widget][settings][year_range][years_back]'] = '-5';
|
|
502 |
$instance_edit['instance[widget][settings][year_range][years_forward]'] = '+5';
|
|
503 |
break;
|
|
475 | 504 |
} |
476 | 505 |
|
477 | 506 |
if ($display_all_day) { |
... | ... | |
510 | 539 |
$return["{$form_field_name}[datetime][month]"] = $date['month']; |
511 | 540 |
$return["{$form_field_name}[datetime][day]"] = ltrim($date['day'], '0'); |
512 | 541 |
break; |
542 |
|
|
513 | 543 |
case 'text': |
514 | 544 |
case 'popup': |
515 | 545 |
$return["{$form_field_name}[datetime][date]"] = "{$date['year']}-{$date['month']}-{$date['day']}"; |
... | ... | |
518 | 548 |
|
519 | 549 |
return $return; |
520 | 550 |
} |
551 |
|
|
521 | 552 |
} |
Formats disponibles : Unified diff
Weekly update of contrib modules