public function SchedulerFieldsDisplayTest::testVerticalTabOrFieldset in Scheduler 8
Same name and namespace in other branches
- 2.x tests/src/Functional/SchedulerFieldsDisplayTest.php \Drupal\Tests\scheduler\Functional\SchedulerFieldsDisplayTest::testVerticalTabOrFieldset()
Tests date input is displayed as vertical tab or an expandable fieldset.
This test covers scheduler_form_node_form_alter().
File
- tests/
src/ Functional/ SchedulerFieldsDisplayTest.php, line 41
Class
- SchedulerFieldsDisplayTest
- Tests the display of date entry fields and form elements.
Namespace
Drupal\Tests\scheduler\FunctionalCode
public function testVerticalTabOrFieldset() {
$this
->drupalLogin($this->adminUser);
/** @var \Drupal\Tests\WebAssert $assert */
$assert = $this
->assertSession();
// Check that the dates are shown in a vertical tab by default.
$this
->drupalGet('node/add/' . $this->type);
$assert
->elementExists('xpath', '//div[contains(@class, "form-type-vertical-tabs")]//details[@id = "edit-scheduler-settings"]');
// Check that the dates are shown as a fieldset when configured to do so,
// and that fieldset is collapsed by default.
$this->nodetype
->setThirdPartySetting('scheduler', 'fields_display_mode', 'fieldset')
->save();
$this
->drupalGet('node/add/' . $this->type);
$assert
->elementNotExists('xpath', '//div[contains(@class, "form-type-vertical-tabs")]//details[@id = "edit-scheduler-settings"]');
$assert
->elementExists('xpath', '//details[@id = "edit-scheduler-settings" and not(@open = "open")]');
// Check that the fieldset is expanded if either of the scheduling dates
// are required.
$this->nodetype
->setThirdPartySetting('scheduler', 'publish_required', TRUE)
->save();
$this
->drupalGet('node/add/' . $this->type);
$assert
->elementExists('xpath', '//details[@id = "edit-scheduler-settings" and @open = "open"]');
$this->nodetype
->setThirdPartySetting('scheduler', 'publish_required', FALSE)
->setThirdPartySetting('scheduler', 'unpublish_required', TRUE)
->save();
$this
->drupalGet('node/add/' . $this->type);
$assert
->elementExists('xpath', '//details[@id = "edit-scheduler-settings" and @open = "open"]');
// Check that the fieldset is expanded if the 'always' option is set.
$this->nodetype
->setThirdPartySetting('scheduler', 'publish_required', FALSE)
->setThirdPartySetting('scheduler', 'unpublish_required', FALSE)
->setThirdPartySetting('scheduler', 'expand_fieldset', 'always')
->save();
$this
->drupalGet('node/add/' . $this->type);
$assert
->elementExists('xpath', '//details[@id = "edit-scheduler-settings" and @open = "open"]');
// Check that the fieldset is expanded if the node already has a publish-on
// date. This requires editing an existing scheduled node.
$this->nodetype
->setThirdPartySetting('scheduler', 'expand_fieldset', 'when_required')
->save();
$options = [
'title' => 'Contains Publish-on date ' . $this
->randomMachineName(10),
'type' => $this->type,
'publish_on' => strtotime('+1 day'),
];
$node = $this
->drupalCreateNode($options);
$this
->drupalGet('node/' . $node
->id() . '/edit');
$assert
->elementExists('xpath', '//details[@id = "edit-scheduler-settings" and @open = "open"]');
// Repeat the check with a timestamp value of zero. This is a valid date
// so the fieldset should be opened. It will not be used much on real sites
// but can occur when testing Rules which fail to set the date correctly and
// we get zero. Debugging Rules is easier if the fieldset opens as expected.
$options = [
'title' => 'Contains Publish-on date with timestamp value zero - ' . $this
->randomMachineName(10),
'type' => $this->type,
'publish_on' => 0,
];
$node = $this
->drupalCreateNode($options);
$this
->drupalGet('node/' . $node
->id() . '/edit');
$assert
->elementExists('xpath', '//details[@id = "edit-scheduler-settings" and @open = "open"]');
// Check that the fieldset is expanded if the node has an unpublish-on date.
$options = [
'title' => 'Contains Unpublish-on date ' . $this
->randomMachineName(10),
'type' => $this->type,
'unpublish_on' => strtotime('+1 day'),
];
$node = $this
->drupalCreateNode($options);
$this
->drupalGet('node/' . $node
->id() . '/edit');
$assert
->elementExists('xpath', '//details[@id = "edit-scheduler-settings" and @open = "open"]');
// Repeat with a timestamp value of zero.
$options = [
'title' => 'Contains Unpublish-on date with timestamp value zero - ' . $this
->randomMachineName(10),
'type' => $this->type,
'unpublish_on' => 0,
];
$node = $this
->drupalCreateNode($options);
$this
->drupalGet('node/' . $node
->id() . '/edit');
$assert
->elementExists('xpath', '//details[@id = "edit-scheduler-settings" and @open = "open"]');
// Check that the display reverts to a vertical tab again when specifically
// configured to do so.
$this->nodetype
->setThirdPartySetting('scheduler', 'fields_display_mode', 'vertical_tab')
->save();
$this
->drupalGet('node/add/' . $this->type);
$assert
->elementExists('xpath', '//div[contains(@class, "form-type-vertical-tabs")]//details[@id = "edit-scheduler-settings"]');
}