diff --git a/core/modules/search/lib/Drupal/search/Tests/SearchConfigSettingsFormTest.php b/core/modules/search/lib/Drupal/search/Tests/SearchConfigSettingsFormTest.php index 066da60..1641a99 100644 --- a/core/modules/search/lib/Drupal/search/Tests/SearchConfigSettingsFormTest.php +++ b/core/modules/search/lib/Drupal/search/Tests/SearchConfigSettingsFormTest.php @@ -86,6 +86,49 @@ function testSearchSettingsPage() { } /** + * Verify module-supplied settings form. + */ + function testSearchModuleSettingsPage() { + + // Test that the settings form displays the correct count of items left to index. + $this->drupalGet('admin/config/search/settings'); + + // Ensure that the settings fieldset for the test module is not present on + // the page + $this->assertNoText(t('Extra type settings')); + $this->assertNoText(t('Boost method')); + + // Ensure that the test module is listed as an option + $this->assertTrue($this->xpath('//input[@id="edit-active-modules-search-extra-type"]'), 'Checkbox for activating search for an extra module is visible'); + $this->assertTrue($this->xpath('//input[@id="edit-default-module-search-extra-type"]'), 'Radio button for setting extra module as default search module is visible'); + + // Enable search for the test module + $edit['active_modules[search_extra_type]'] = 'search_extra_type'; + $edit['default_module'] = 'search_extra_type'; + $this->drupalPost('admin/config/search/settings', $edit, t('Save configuration')); + + // Ensure that the settings fieldset is visible after enabling search for + // the test module + $this->assertText(t('Extra type settings')); + $this->assertText(t('Boost method')); + + // Ensure that the default setting was picked up from the default config + $this->assertTrue($this->xpath('//select[@id="edit-extra-type-settings-boost"]//option[@value="bi" and @selected="selected"]'), 'Module specific settings are picked up from the default config'); + + // Change extra type setting and also modify a common search setting. + $edit = array( + 'extra_type_settings[boost]' => 'ii', + 'minimum_word_size' => 5, + ); + $this->drupalPost('admin/config/search/settings', $edit, t('Save configuration')); + + // Ensure that the modifications took effect. + $this->assertText(t('The configuration options have been saved.')); + $this->assertTrue($this->xpath('//select[@id="edit-extra-type-settings-boost"]//option[@value="ii" and @selected="selected"]'), 'Module specific settings can be changed'); + $this->assertTrue($this->xpath('//input[@id="edit-minimum-word-size" and @value="5"]'), 'Common search settings can be modified if a module-specific form is active'); + } + + /** * Verify that you can disable individual search modules. */ function testSearchModuleDisabling() { diff --git a/core/modules/search/tests/modules/search_extra_type/config/search_extra_type.settings.yml b/core/modules/search/tests/modules/search_extra_type/config/search_extra_type.settings.yml new file mode 100644 index 0000000..db64246 --- /dev/null +++ b/core/modules/search/tests/modules/search_extra_type/config/search_extra_type.settings.yml @@ -0,0 +1 @@ +boost: bi diff --git a/core/modules/search/tests/modules/search_extra_type/search_extra_type.module b/core/modules/search/tests/modules/search_extra_type/search_extra_type.module index 80c050c..a983b21 100644 --- a/core/modules/search/tests/modules/search_extra_type/search_extra_type.module +++ b/core/modules/search/tests/modules/search_extra_type/search_extra_type.module @@ -67,3 +67,38 @@ function search_extra_type_search_page($results) { return $output; } + +/** + * Implements hook_search_admin(). + */ +function search_extra_type_search_admin() { + // Output form for defining rank factor weights. + $form['extra_type_settings'] = array( + '#type' => 'fieldset', + '#title' => t('Extra type settings'), + '#tree' => TRUE, + ); + + $form['extra_type_settings']['boost'] = array( + '#type' => 'select', + '#title' => t('Boost method'), + '#options' => array( + 'bi' => t('Bistromathic'), + 'ii' => t('Infinite Improbability'), + ), + '#default_value' => config('search_extra_type.settings')->get('boost'), + ); + + $form['#submit'][] = 'search_extra_type_admin_submit'; + + return $form; +} + +/** + * Form API callback: Save admin settings + */ +function search_extra_type_admin_submit($form, &$form_state) { + config('search_extra_type.settings') + ->set('boost', $form_state['values']['extra_type_settings']['boost']) + ->save(); +}