public function SchedulerFieldsDisplayTest::testHideSeconds in Scheduler 8
Same name and namespace in other branches
- 2.x tests/src/Functional/SchedulerFieldsDisplayTest.php \Drupal\Tests\scheduler\Functional\SchedulerFieldsDisplayTest::testHideSeconds()
Test the option to hide the seconds on the time input fields.
File
- tests/
src/ Functional/ SchedulerFieldsDisplayTest.php, line 205
Class
- SchedulerFieldsDisplayTest
- Tests the display of date entry fields and form elements.
Namespace
Drupal\Tests\scheduler\FunctionalCode
public function testHideSeconds() {
$this
->drupalLogin($this->schedulerUser);
$config = $this
->config('scheduler.settings');
// Check that the default is to show the seconds on the input fields.
$this
->drupalGet('node/add/' . $this->type);
$publish_time_field = $this
->xpath('//input[@id="edit-publish-on-0-value-time"]');
$unpublish_time_field = $this
->xpath('//input[@id="edit-unpublish-on-0-value-time"]');
$this
->assertEquals(1, $publish_time_field[0]
->getAttribute('step'), 'The input time step for publish-on is 1, so the seconds will be visible and usable.');
$this
->assertEquals(1, $unpublish_time_field[0]
->getAttribute('step'), 'The input time step for unpublish-on is 1, so the seconds will be visible and usable.');
// Set the config option to hide the seconds and thus set the input fields
// to the granularity of one minute.
$config
->set('hide_seconds', TRUE)
->save();
// Get the node-add page and check the input fields.
$this
->drupalGet('node/add/' . $this->type);
$publish_time_field = $this
->xpath('//input[@id="edit-publish-on-0-value-time"]');
$unpublish_time_field = $this
->xpath('//input[@id="edit-unpublish-on-0-value-time"]');
$this
->assertEquals(60, $publish_time_field[0]
->getAttribute('step'), 'The input time step for publish-on is 60, so the seconds will be hidden and not usable.');
$this
->assertEquals(60, $unpublish_time_field[0]
->getAttribute('step'), 'The input time step for unpublish-on is 60, so the seconds will be hidden and not usable.');
// @todo How can we check that the seconds element is not shown?
// Save with both dates entered, including seconds in the times.
$edit = [
'title[0][value]' => 'Hide the seconds',
'body[0][value]' => $this
->randomString(30),
'publish_on[0][value][date]' => date('Y-m-d', strtotime('+1 day', $this->requestTime)),
'publish_on[0][value][time]' => '01:02:03',
'unpublish_on[0][value][date]' => date('Y-m-d', strtotime('+1 day', $this->requestTime)),
'unpublish_on[0][value][time]' => '04:05:06',
];
$this
->submitForm($edit, 'Save');
$node = $this
->drupalGetNodeByTitle('Hide the seconds');
// Edit and check that the seconds have been set to zero.
$this
->drupalGet("node/{$node->id()}/edit");
$this
->assertSession()
->FieldValueEquals('publish_on[0][value][time]', '01:02:00');
$this
->assertSession()
->FieldValueEquals('unpublish_on[0][value][time]', '04:05:00');
}