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