public function DateAllDayUiTestCase::testDateTimeTextFieldWidget in Date 7.3
Test the datetime field type with the text field widget.
File
- date_all_day/
tests/ DateAllDayUiTestCase.test, line 108 - Test Date All Day functionality.
Class
- DateAllDayUiTestCase
- Test Date All Day functionality.
Code
public function testDateTimeTextFieldWidget() {
// Change the field defintion to use the "text field" widget.
$this
->drupalGet('admin/structure/types/manage/test-datetime/fields/field_datetime/widget-type');
$this
->assertResponse(200);
$edit = array(
'widget_type' => 'date_text',
);
$this
->drupalPost(NULL, $edit, 'Continue');
$this
->assertResponse(200);
$this
->assertText('Changed the widget for field Date All Day.');
// A first node, with the "all day" option disabled.
$this
->drupalGet('node/add/test-datetime');
$this
->assertResponse(200);
// Confirm the 'date all day' field exists.
$this
->assertFieldByName('field_datetime[und][0][all_day]');
$this
->assertFieldByName('field_datetime[und][0][value][date]');
// Submit the node form.
$edit = array(
'title' => 'Testing the All Day text widget',
'field_datetime[und][0][all_day]' => FALSE,
'field_datetime[und][0][value][date]' => '02/11/2021 - 18:15',
);
$this
->drupalPost(NULL, $edit, 'Save');
$this
->assertResponse(200);
// Confirm the data is displayed correctly.
$this
->assertText('Testing the All Day text widget');
$this
->assertText('Date All Day');
$this
->assertText('Thu, 02/11/2021 - 18:15');
// A second node, this time with the "all day" option enabled.
$this
->drupalGet('node/add/test-datetime');
$this
->assertResponse(200);
// Submit the node form.
$edit = array(
'title' => 'Testing the All Day text widget again',
'field_datetime[und][0][all_day]' => TRUE,
'field_datetime[und][0][value][date]' => '02/11/2021 - 18:15',
);
$this
->drupalPost(NULL, $edit, 'Save');
$this
->assertResponse(200);
// Confirm the data is displayed correctly.
$this
->assertText('Testing the All Day text widget again');
$this
->assertText('Date All Day');
$this
->assertText('Thu, 02/11/2021 (All day)');
// Load the node and confirm the data is as expected.
$node = node_load(2);
$this
->verbose($node);
$this
->assertEqual($node->title, $edit['title']);
$this
->assertTrue(isset($node->field_datetime[LANGUAGE_NONE][0]['value']));
$this
->assertEqual($node->field_datetime[LANGUAGE_NONE][0]['value'], '2021-02-11 23:45:59');
}