public function SmsFrameworkUserSettingsTest::testSettingsForm in SMS Framework 2.x
Same name and namespace in other branches
- 8 modules/sms_user/tests/src/Functional/SmsFrameworkUserSettingsTest.php \Drupal\Tests\sms_user\Functional\SmsFrameworkUserSettingsTest::testSettingsForm()
- 2.1.x modules/sms_user/tests/src/Functional/SmsFrameworkUserSettingsTest.php \Drupal\Tests\sms_user\Functional\SmsFrameworkUserSettingsTest::testSettingsForm()
Tests saving form and verifying configuration is saved.
File
- modules/
sms_user/ tests/ src/ Functional/ SmsFrameworkUserSettingsTest.php, line 55
Class
- SmsFrameworkUserSettingsTest
- Tests SMS User settings user interface.
Namespace
Drupal\Tests\sms_user\FunctionalCode
public function testSettingsForm() {
$this
->drupalGet(Url::fromRoute('sms_user.options'));
$this
->assertResponse(200);
$this
->assertFieldByName('active_hours[status]');
$this
->assertNoFieldChecked('edit-active-hours-status');
// Ensure default select field values.
foreach ($this->days as $day) {
$this
->assertOptionSelected('edit-active-hours-days-' . $day . '-start', -1);
}
foreach ($this->days as $day) {
$this
->assertOptionSelected('edit-active-hours-days-' . $day . '-end', 24);
}
$edit = [
'active_hours[status]' => TRUE,
'active_hours[days][sunday][start]' => 2,
'active_hours[days][sunday][end]' => 22,
'active_hours[days][tuesday][start]' => 0,
'active_hours[days][tuesday][end]' => 24,
// This day wont save because start is set to disabled.
'active_hours[days][thursday][start]' => -1,
'active_hours[days][thursday][end]' => 18,
];
$this
->drupalPostForm(Url::fromRoute('sms_user.options'), $edit, 'Save configuration');
$this
->assertRaw('The configuration options have been saved.');
// Check values are saved and form reflects this.
$this
->assertFieldChecked('edit-active-hours-status');
$this
->assertOptionSelected('edit-active-hours-days-sunday-start', 2);
$this
->assertOptionSelected('edit-active-hours-days-sunday-end', 22);
$this
->assertOptionSelected('edit-active-hours-days-tuesday-start', 0);
$this
->assertOptionSelected('edit-active-hours-days-tuesday-end', 24);
$this
->assertOptionSelected('edit-active-hours-days-thursday-start', -1);
$this
->assertOptionSelected('edit-active-hours-days-thursday-end', 24);
$ranges_expected = [
[
'start' => 'sunday 2:00',
'end' => 'sunday 22:00',
],
[
'start' => 'tuesday 0:00',
'end' => 'tuesday +1 day',
],
];
$ranges_actual = \Drupal::config('sms_user.settings')
->get('active_hours.ranges');
$this
->assertEquals($ranges_expected, $ranges_actual);
}