1
|
<?php
|
2
|
|
3
|
/**
|
4
|
* @file
|
5
|
* Tests for Date Tools.
|
6
|
*/
|
7
|
|
8
|
class DateToolsTestCase extends DrupalWebTestCase {
|
9
|
protected $privileged_user;
|
10
|
|
11
|
/**
|
12
|
* @todo.
|
13
|
*/
|
14
|
public static function getInfo() {
|
15
|
return array(
|
16
|
'name' => 'Date Tools',
|
17
|
'description' => 'Test Date Wizard and other Date Tools.',
|
18
|
'group' => 'Date',
|
19
|
);
|
20
|
}
|
21
|
|
22
|
/**
|
23
|
* @todo.
|
24
|
*/
|
25
|
public function setUp() {
|
26
|
// Load the date_api module.
|
27
|
parent::setUp('field', 'field_ui', 'date_api', 'date', 'date_popup', 'date_tools');
|
28
|
|
29
|
// Create and log in our privileged user.
|
30
|
$this->privileged_user = $this->drupalCreateUser(
|
31
|
array('administer content types', 'administer nodes', 'bypass node access', 'administer date tools', 'administer fields')
|
32
|
);
|
33
|
$this->drupalLogin($this->privileged_user);
|
34
|
|
35
|
variable_set('date_format_long', 'D, m/d/Y - H:i');
|
36
|
}
|
37
|
|
38
|
/**
|
39
|
* Creates a date field using the Date Wizard.
|
40
|
*/
|
41
|
public function testTools() {
|
42
|
$form_values = array('label' => 'Test', 'field_type' => 'datetime', 'widget_type' => 'date_select', 'todate' => '');
|
43
|
$this->createDateWizard($form_values);
|
44
|
$this->dateForm($options = 'select');
|
45
|
$this->assertText('Thu, 10/07/2010 - 10:30', 'Found the correct date for the Date Wizard datetime field using the date_select widget.');
|
46
|
$this->deleteDateField();
|
47
|
}
|
48
|
|
49
|
/**
|
50
|
* Tests that date field functions properly.
|
51
|
*/
|
52
|
function dateForm($options) {
|
53
|
$edit = array();
|
54
|
$edit['title'] = $this->randomName(8);
|
55
|
$edit['body[und][0][value]'] = $this->randomName(16);
|
56
|
if ($options == 'select') {
|
57
|
$edit['field_test[und][0][value][year]'] = '2010';
|
58
|
$edit['field_test[und][0][value][month]'] = '10';
|
59
|
$edit['field_test[und][0][value][day]'] = '7';
|
60
|
$edit['field_test[und][0][value][hour]'] = '10';
|
61
|
$edit['field_test[und][0][value][minute]'] = '30';
|
62
|
}
|
63
|
elseif ($options == 'text') {
|
64
|
$edit['field_test[und][0][value][date]'] = '10/07/2010 - 10:30';
|
65
|
}
|
66
|
elseif ($options == 'popup') {
|
67
|
$edit['field_test[und][0][value][date]'] = '10/07/2010';
|
68
|
$edit['field_test[und][0][value][time]'] = '10:30';
|
69
|
}
|
70
|
$this->drupalPost('node/add/story', $edit, t('Save'));
|
71
|
$this->assertText($edit['body[und][0][value]'], 'Test node has been created');
|
72
|
}
|
73
|
|
74
|
/**
|
75
|
* @todo.
|
76
|
*/
|
77
|
function deleteDateField() {
|
78
|
$this->drupalGet('admin/structure/types/manage/story/fields');
|
79
|
$this->clickLink('delete');
|
80
|
$this->drupalPost(NULL, NULL, t('Delete'));
|
81
|
$this->assertText('The field Test has been deleted from the Story content type.', 'Removed date field.');
|
82
|
}
|
83
|
|
84
|
/**
|
85
|
* Creates a date field using the Date Wizard.
|
86
|
*/
|
87
|
function createDateWizard($edit) {
|
88
|
$edit += array(
|
89
|
'bundle' => 'story',
|
90
|
'name' => 'Story',
|
91
|
'type_description' => 'A test content type.',
|
92
|
'field_name' => 'test',
|
93
|
'label' => 'Test',
|
94
|
'widget_type' => 'date_select',
|
95
|
'todate' => 'optional',
|
96
|
'field_type' => 'date',
|
97
|
'granularity[]' => array('year', 'month', 'day', 'hour', 'minute'),
|
98
|
'tz_handling' => 'site',
|
99
|
'year_range' => '2010:+2',
|
100
|
);
|
101
|
$this->drupalPost('admin/config/date/tools/date_wizard', $edit, t('Save'));
|
102
|
$this->assertText('Your date field Test has been created.', 'Create a date field using the Date Wizard.');
|
103
|
}
|
104
|
|
105
|
}
|