public function SchedulerAdminSettingsTest::testAdminSettings in Scheduler 2.x
Same name and namespace in other branches
- 8 tests/src/Functional/SchedulerAdminSettingsTest.php \Drupal\Tests\scheduler\Functional\SchedulerAdminSettingsTest::testAdminSettings()
Test the admin settings page.
File
- tests/
src/ Functional/ SchedulerAdminSettingsTest.php, line 19
Class
- SchedulerAdminSettingsTest
- Tests the admin settings page of Scheduler.
Namespace
Drupal\Tests\scheduler\FunctionalCode
public function testAdminSettings() {
$this
->drupalLogin($this->adminUser);
// Check that we get the warning when no media types exist.
$this
->drupalGet('admin/config/content/scheduler');
$this
->assertSession()
->pageTextContains('No entity types returned by media module for use in Media Scheduler Plugin');
// Call the setUp functions for all entity types.
$this
->schedulerMediaSetUp();
$this
->SchedulerCommerceProductSetUp();
// Verify that the default values are as expected.
$this
->assertFalse($this
->config('scheduler.settings')
->get('allow_date_only'), 'The default setting for allow_date_only is False.');
$this
->assertEquals('00:00:00', $this
->config('scheduler.settings')
->get('default_time'), 'The default config setting for default_time is 00:00:00');
$this
->assertFalse($this
->config('scheduler.settings')
->get('hide_seconds'), 'The default setting for hide_seconds is False.');
// Check that a default time can be stored, and that the option is saved.
// In $settings use '6:30' not '06:30:00' to test flexibility.
$settings = [
'allow_date_only' => TRUE,
'default_time' => '6:30',
];
$this
->drupalGet('admin/config/content/scheduler');
$this
->submitForm($settings, 'Save configuration');
// Verify that the values have been saved correctly.
$this
->assertTrue($this
->config('scheduler.settings')
->get('allow_date_only'), 'The config setting for allow_date_only is stored correctly.');
$this
->assertEquals('06:30:00', $this
->config('scheduler.settings')
->get('default_time'), 'The config setting for default_time is stored correctly.');
// Try to save an invalid default time value.
$settings = [
'allow_date_only' => TRUE,
'default_time' => '123',
];
$this
->drupalGet('admin/config/content/scheduler');
$this
->submitForm($settings, 'Save configuration');
// Verify that the value has not been saved and an error is displayed.
$this
->assertEquals('06:30:00', $this
->config('scheduler.settings')
->get('default_time'), 'The config setting for default_time has not changed.');
$this
->assertSession()
->pageTextContains('The default time should be in the format HH:MM:SS');
// Select the option to hide seconds on time input.
$settings = [
'hide_seconds' => TRUE,
];
$this
->drupalGet('admin/config/content/scheduler');
$this
->submitForm($settings, 'Save configuration');
// Verify that the hide seconds option is saved and the default time is
// stored in HH:MM format with no seconds.
$this
->assertTrue($this
->config('scheduler.settings')
->get('hide_seconds'), 'The config setting for hide_seconds is stored correctly.');
$this
->assertEquals('06:30', $this
->config('scheduler.settings')
->get('default_time'), 'The config setting for default_time is stored correctly.');
// Try to save an invalid default time value.
$settings = [
'default_time' => '456',
];
$this
->drupalGet('admin/config/content/scheduler');
$this
->submitForm($settings, 'Save configuration');
// Verify that the value has not been saved, and that an error message is
// displayed showing the correct format HH:MM not HH:MM:SS.
$this
->assertEquals('06:30', $this
->config('scheduler.settings')
->get('default_time'), 'The config setting for default_time has not changed.');
$this
->assertSession()
->pageTextMatches('/The default time should be in the format HH:MM[^:S]/');
// Show the status report, which includes the Scheduler timecheck.
$this
->drupalGet('admin/reports/status');
}