1
|
<?php
|
2
|
|
3
|
/**
|
4
|
* @file
|
5
|
* Test date UI.
|
6
|
*/
|
7
|
|
8
|
class DateUITestCase extends DrupalWebTestCase {
|
9
|
protected $privileged_user;
|
10
|
|
11
|
/**
|
12
|
* @todo.
|
13
|
*/
|
14
|
public static function getInfo() {
|
15
|
return array(
|
16
|
'name' => 'Field UI',
|
17
|
'description' => 'Test creation of various date fields and widgets using Field UI.',
|
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')
|
32
|
);
|
33
|
$this->drupalLogin($this->privileged_user);
|
34
|
|
35
|
variable_set('date_format_long', 'D, m/d/Y - H:i');
|
36
|
}
|
37
|
|
38
|
/**
|
39
|
* @todo.
|
40
|
*/
|
41
|
public function testFieldUI() {
|
42
|
$edit = array();
|
43
|
$edit['name'] = 'Story';
|
44
|
$edit['type'] = 'story';
|
45
|
$this->drupalPost('admin/structure/types/add', $edit, t('Save content type'));
|
46
|
$this->assertText('The content type Story has been added.', 'Content type added.');
|
47
|
|
48
|
// Creates select list field stored as a date with default settings.
|
49
|
$this->createDateField($type = 'date', $widget = 'date_select');
|
50
|
$edit = array();
|
51
|
$this->drupalPost(NULL, $edit, t('Save field settings'));
|
52
|
$this->dateForm($options = 'select');
|
53
|
$this->assertText('Thu, 10/07/2010 - 10:30', 'Found the correct date for a date field using the date_select widget.');
|
54
|
$this->deleteDateField();
|
55
|
// Creates text field stored as a date with default settings.
|
56
|
$this->createDateField($type = 'date', $widget = 'date_text');
|
57
|
$edit = array();
|
58
|
$this->drupalPost(NULL, $edit, t('Save field settings'));
|
59
|
$this->dateForm($options = 'text');
|
60
|
$this->assertText('Thu, 10/07/2010 - 10:30', 'Found the correct date for a date field using the date_text widget.');
|
61
|
$this->deleteDateField();
|
62
|
// Creates popup field stored as a date with default settings.
|
63
|
$this->createDateField($type = 'date', $widget = 'date_popup');
|
64
|
$edit = array();
|
65
|
$this->drupalPost(NULL, $edit, t('Save field settings'));
|
66
|
$this->dateForm($options = 'popup');
|
67
|
$this->assertText('Thu, 10/07/2010 - 10:30', 'Found the correct date for a date field using the date_popup widget.');
|
68
|
$this->deleteDateField();
|
69
|
// Creates select list field stored as a datestamp with default settings.
|
70
|
$this->createDateField($type = 'datestamp', $widget = 'date_select');
|
71
|
$edit = array();
|
72
|
$this->drupalPost(NULL, $edit, t('Save field settings'));
|
73
|
$this->dateForm($options = 'select');
|
74
|
$this->assertText('Thu, 10/07/2010 - 10:30', 'Found the correct date for a datestamp field using the date_select widget.');
|
75
|
$this->deleteDateField();
|
76
|
// Creates text field stored as a datestamp with default settings.
|
77
|
$this->createDateField($type = 'datestamp', $widget = 'date_text');
|
78
|
$edit = array();
|
79
|
$this->drupalPost(NULL, $edit, t('Save field settings'));
|
80
|
$this->dateForm($options = 'text');
|
81
|
$this->assertText('Thu, 10/07/2010 - 10:30', 'Found the correct date for a datestamp field using the date_text widget.');
|
82
|
$this->deleteDateField();
|
83
|
// Creates popup field stored as a datestamp with default settings.
|
84
|
$this->createDateField($type = 'datestamp', $widget = 'date_popup');
|
85
|
$edit = array();
|
86
|
$this->drupalPost(NULL, $edit, t('Save field settings'));
|
87
|
$this->dateForm($options = 'popup');
|
88
|
$this->assertText('Thu, 10/07/2010 - 10:30', 'Found the correct date for a datestamp field using the date_popup widget.');
|
89
|
$this->deleteDateField();
|
90
|
// Creates select list field stored as a datetime with default settings.
|
91
|
$this->createDateField($type = 'datetime', $widget = 'date_select');
|
92
|
$edit = array();
|
93
|
$this->drupalPost(NULL, $edit, t('Save field settings'));
|
94
|
$this->dateForm($options = 'select');
|
95
|
$this->assertText('Thu, 10/07/2010 - 10:30', 'Found the correct date for a datetime field using the date_select widget.');
|
96
|
$this->deleteDateField();
|
97
|
// Creates text field stored as a datetime with default settings.
|
98
|
$this->createDateField($type = 'datetime', $widget = 'date_text');
|
99
|
$edit = array();
|
100
|
$this->drupalPost(NULL, $edit, t('Save field settings'));
|
101
|
$this->dateForm($options = 'text');
|
102
|
$this->assertText('Thu, 10/07/2010 - 10:30', 'Found the correct date for a datetime field using the date_text widget.');
|
103
|
$this->deleteDateField();
|
104
|
// Creates popup field stored as a datetime with default settings.
|
105
|
$this->createDateField($type = 'datetime', $widget = 'date_popup');
|
106
|
$edit = array();
|
107
|
$this->drupalPost(NULL, $edit, t('Save field settings'));
|
108
|
$this->dateForm($options = 'popup');
|
109
|
$this->assertText('Thu, 10/07/2010 - 10:30', 'Found the correct date for a datetime field using the date_popup widget.');
|
110
|
$this->deleteDateField();
|
111
|
|
112
|
// Test timezone handling validation on the field settings form.
|
113
|
$this->createDateField($type = 'date', $widget = 'date_select');
|
114
|
$edit = array('field[settings][granularity][hour]' => FALSE);
|
115
|
$this->drupalPost(NULL, $edit, t('Save field settings'));
|
116
|
$this->assertText("Dates without hours granularity must not use any timezone handling.", "Dates without hours granularity required to use timezone handling of 'none.'");
|
117
|
$this->deleteDateField();
|
118
|
}
|
119
|
|
120
|
/**
|
121
|
* @todo.
|
122
|
*/
|
123
|
function dateForm($options) {
|
124
|
// Tests that date field functions properly.
|
125
|
$edit = array();
|
126
|
$edit['title'] = $this->randomName(8);
|
127
|
$edit['body[und][0][value]'] = $this->randomName(16);
|
128
|
if ($options == 'select') {
|
129
|
$edit['field_test[und][0][value][year]'] = '2010';
|
130
|
$edit['field_test[und][0][value][month]'] = '10';
|
131
|
$edit['field_test[und][0][value][day]'] = '7';
|
132
|
$edit['field_test[und][0][value][hour]'] = '10';
|
133
|
$edit['field_test[und][0][value][minute]'] = '30';
|
134
|
}
|
135
|
elseif ($options == 'text') {
|
136
|
$edit['field_test[und][0][value][date]'] = '10/07/2010 - 10:30';
|
137
|
}
|
138
|
elseif ($options == 'popup') {
|
139
|
$edit['field_test[und][0][value][date]'] = '10/07/2010';
|
140
|
$edit['field_test[und][0][value][time]'] = '10:30';
|
141
|
}
|
142
|
$this->drupalPost('node/add/story', $edit, t('Save'));
|
143
|
$this->assertText($edit['body[und][0][value]'], 'Test node has been created');
|
144
|
}
|
145
|
|
146
|
/**
|
147
|
* @todo.
|
148
|
*/
|
149
|
function createDateField($type, $widget) {
|
150
|
$edit = array();
|
151
|
$edit['fields[_add_new_field][label]'] = 'Test';
|
152
|
$edit['fields[_add_new_field][field_name]'] = 'test';
|
153
|
$edit['fields[_add_new_field][weight]'] = '-4';
|
154
|
$edit['fields[_add_new_field][type]'] = $type;
|
155
|
$edit['fields[_add_new_field][widget_type]'] = $widget;
|
156
|
$this->drupalPost('admin/structure/types/manage/story/fields', $edit, t('Save'));
|
157
|
}
|
158
|
|
159
|
/**
|
160
|
* @todo.
|
161
|
*/
|
162
|
function deleteDateField() {
|
163
|
$this->drupalGet('admin/structure/types/manage/story/fields');
|
164
|
$this->clickLink('delete');
|
165
|
$this->drupalPost(NULL, NULL, t('Delete'));
|
166
|
$this->assertText('The field Test has been deleted from the Story content type.', 'Removed date field.');
|
167
|
}
|
168
|
}
|