public function SchedulerFieldsDisplayTest::testDisabledFields in Scheduler 2.x
Same name and namespace in other branches
- 8 tests/src/Functional/SchedulerFieldsDisplayTest.php \Drupal\Tests\scheduler\Functional\SchedulerFieldsDisplayTest::testDisabledFields()
Tests the edit form when scheduler fields have been disabled.
This test covers _scheduler_entity_type_form_alter().
@dataProvider dataStandardEntityTypes()
File
- tests/
src/ Functional/ SchedulerFieldsDisplayTest.php, line 178
Class
- SchedulerFieldsDisplayTest
- Tests the display of date entry fields and form elements.
Namespace
Drupal\Tests\scheduler\FunctionalCode
public function testDisabledFields($entityTypeId, $bundle) {
$this
->drupalLogin($this->adminUser);
$entityType = $this
->entityTypeObject($entityTypeId, $bundle);
/** @var \Drupal\Tests\WebAssert $assert */
$assert = $this
->assertSession();
// 1. Set the publish_on field to 'hidden' in the entity edit form.
$edit = [
'fields[publish_on][region]' => 'hidden',
];
$form_display_url = Url::fromRoute("entity.entity_form_display.{$entityTypeId}.default", [
$entityType
->getEntityTypeId() => $bundle,
]);
$this
->drupalGet($form_display_url);
$this
->submitForm($edit, 'Save');
// Check that the scheduler details element is shown and that the
// unpublish_on field is shown, but the publish_on field is not shown.
$add_url = $this
->entityAddUrl($entityTypeId, $bundle);
$this
->drupalGet($add_url);
$assert
->elementExists('xpath', '//details[@id = "edit-scheduler-settings"]');
$this
->assertSession()
->FieldNotExists('publish_on[0][value][date]');
$this
->assertSession()
->FieldExists('unpublish_on[0][value][date]');
// 2. Set publish_on to be displayed but hide the unpublish_on field.
$edit = [
'fields[publish_on][region]' => 'content',
'fields[unpublish_on][region]' => 'hidden',
];
$this
->drupalGet($form_display_url);
$this
->submitForm($edit, 'Save');
// Check that the scheduler details element is shown and that the
// publish_on field is shown, but the unpublish_on field is not shown.
$this
->drupalGet($add_url);
$assert
->elementExists('xpath', '//details[@id = "edit-scheduler-settings"]');
$this
->assertSession()
->FieldExists('publish_on[0][value][date]');
$this
->assertSession()
->FieldNotExists('unpublish_on[0][value][date]');
// 3. Set both fields to be hidden.
$edit = [
'fields[publish_on][region]' => 'hidden',
'fields[unpublish_on][region]' => 'hidden',
];
$this
->drupalGet($form_display_url);
$this
->submitForm($edit, 'Save');
// Check that the scheduler details element is not shown when both of the
// date fields are set to be hidden.
$this
->drupalGet($add_url);
$assert
->elementNotExists('xpath', '//details[@id = "edit-scheduler-settings"]');
$this
->assertSession()
->FieldNotExists('publish_on[0][value][date]');
$this
->assertSession()
->FieldNotExists('unpublish_on[0][value][date]');
}