public function SmartTitleConfigTest::testSavedConfiguration in Smart Title 8
Test saved configuration.
@dataProvider providerSettingsTestCases
File
- tests/
src/ Functional/ SmartTitleConfigTest.php, line 44
Class
- SmartTitleConfigTest
- Tests the module's title hide functionality.
Namespace
Drupal\Tests\smart_title\FunctionalCode
public function testSavedConfiguration($input, $expectation) {
$invalid_values = [];
$this
->drupalGet('admin/structure/types/manage/test_page/display/teaser');
foreach ($input as $setting_key => $setting_value) {
switch ($setting_key) {
case 'smart_title__tag':
if (!isset(_smart_title_tag_options()[$input['smart_title__tag']])) {
$invalid_values[] = $setting_key;
}
break;
}
}
// Open Smart Title settings edit.
$this
->click('[name="smart_title_settings_edit"]');
if (!empty($invalid_values)) {
// Test that exception is thrown.
try {
$this
->drupalPostForm(NULL, [
"fields[smart_title][settings_edit_form][settings][smart_title__tag]" => $input['smart_title__tag'],
"fields[smart_title][settings_edit_form][settings][smart_title__classes]" => $input['smart_title__classes'],
"fields[smart_title][settings_edit_form][settings][smart_title__link]" => $input['smart_title__link'],
], 'Save');
$this
->fail('Expected exception has not been thrown.');
} catch (\Exception $e) {
$this
->pass('Expected exception has been thrown.');
}
// Let's save the other values.
$edit = [];
foreach ($input as $key => $value) {
if (in_array($key, $invalid_values)) {
continue;
}
$edit["fields[smart_title][settings_edit_form][settings][{$key}]"] = $value;
}
$this
->drupalPostForm(NULL, $edit, 'Save');
}
else {
$this
->drupalPostForm(NULL, [
"fields[smart_title][settings_edit_form][settings][smart_title__tag]" => $input['smart_title__tag'],
"fields[smart_title][settings_edit_form][settings][smart_title__classes]" => $input['smart_title__classes'],
"fields[smart_title][settings_edit_form][settings][smart_title__link]" => $input['smart_title__link'],
], 'Save');
}
// Verify saved settings.
$this
->assertSmartTitleExpectedConfigs($expectation);
// Re-save form again.
$this
->drupalGet('admin/structure/types/manage/test_page/display/teaser');
$this
->drupalPostForm(NULL, [], 'Save');
// Verify saved settings again.
$this
->assertSmartTitleExpectedConfigs($expectation);
}