public function SchedulerJavascriptDefaultTimeTest::testTimeWhenSchedulingIsRequired in Scheduler 8
Same name and namespace in other branches
- 2.x tests/src/FunctionalJavascript/SchedulerJavascriptDefaultTimeTest.php \Drupal\Tests\scheduler\FunctionalJavascript\SchedulerJavascriptDefaultTimeTest::testTimeWhenSchedulingIsRequired()
Test the default time functionality when scheduling dates are required.
@dataProvider dataTimeWhenSchedulingIsRequired()
File
- tests/
src/ FunctionalJavascript/ SchedulerJavascriptDefaultTimeTest.php, line 53
Class
- SchedulerJavascriptDefaultTimeTest
- Tests the JavaScript functionality for default dates.
Namespace
Drupal\Tests\scheduler\FunctionalJavascriptCode
public function testTimeWhenSchedulingIsRequired($field) {
$config = $this
->config('scheduler.settings');
// This test is only relevant when the configuration allows a date only with
// a default time specified. Testing with 'allow_date_only' = false is
// covered in the browser test SchedulerDefaultTimeTest.
$config
->set('allow_date_only', TRUE)
->save();
// Use a default time of 19:30:20 (7:30pm and 20 seconds).
$default_time = '19:30:20';
$config
->set('default_time', $default_time)
->save();
// Create a DateTime object to hold the scheduling date. This is better than
// using a raw unix timestamp because it caters for daylight-saving.
$scheduling_time = new \DateTime();
$scheduling_time
->add(new \DateInterval('P1D'))
->setTime(19, 30, 20);
foreach ([
TRUE,
FALSE,
] as $required) {
// Set the publish-on/unpublish-on date to the $required setting.
$this->nodetype
->setThirdPartySetting('scheduler', $field . '_required', $required)
->save();
// Create a node.
$this
->drupalGet('node/add/' . $this->type);
$page = $this
->getSession()
->getPage();
$title = ucfirst($field) . ($required ? ' required ' : ' not required ') . $this
->randomString(12);
$page
->fillField('edit-title-0-value', $title);
$page
->fillField('edit-body-0-value', 'datepickerFormat = ' . $this->datepickerFormat);
$page
->clickLink('Scheduling options');
if ($required) {
// Fill in the date value but do nothing with the time field.
$page
->fillField('edit-' . $field . '-on-0-value-date', $scheduling_time
->format($this->datepickerFormat));
}
$page
->pressButton('Save');
// Test that the content has saved properly.
$this
->assertSession()
->pageTextContains(sprintf('%s %s has been created', $this->typeName, $title));
$node = $this
->drupalGetNodeByTitle($title);
$this
->assertNotEmpty($node, 'The node could not be found');
if ($required) {
// Check that the scheduled date and time are correct.
$this
->assertEquals($scheduling_time
->getTimestamp(), (int) $node->{$field . '_on'}->value);
}
else {
// Check that no scheduled date was stored.
$this
->assertEmpty($node->{$field . '_on'}->value);
}
}
}