diff --git a/core/modules/search/search.module b/core/modules/search/search.module index af1d827b29..0b8e938b19 100644 --- a/core/modules/search/search.module +++ b/core/modules/search/search.module @@ -78,7 +78,7 @@ function search_help($route_name, RouteMatchInterface $route_match) { $output .= '

' . t('Uses') . '

'; $output .= '
'; $output .= '
' . t('Configuring search pages') . '
'; - $output .= '
' . t('To configure search pages, visit the Search pages page. In the Search pages section, you can add a new search page, edit the configuration of existing search pages, enable and disable search pages, and choose the default search page. Each enabled search page has a URL path starting with search, and each will appear as a tab or local task link on the search page; you can configure the text that is shown in the tab. In addition, some search page plugins have additional settings that you can configure for each search page.', [':search-settings' => Url::fromRoute('entity.search_page.collection')->toString(), ':search-url' => Url::fromRoute('search.view')->toString()]) . '
'; + $output .= '
' . t('To configure search pages, visit the Search pages page. In the Search pages section, you can add a new search page, edit the configuration of existing search pages, delete search pages, and choose the default search page. Each search page has a URL path starting with search, and each will appear as a tab or local task link on the search page; you can configure the text that is shown in the tab. In addition, some search page plugins have additional settings that you can configure for each search page.', [':search-settings' => Url::fromRoute('entity.search_page.collection')->toString(), ':search-url' => Url::fromRoute('search.view')->toString()]) . '
'; $output .= '
' . t('Managing the search index') . '
'; $output .= '
' . t('Some search page plugins, such as the core Content search page, index searchable text using the Drupal core search index, and will not work unless content is indexed. Indexing is done during cron runs, so it requires a cron maintenance task to be set up. There are also several settings affecting indexing that can be configured on the Search pages page: the number of items to index per cron run, the minimum word length to index, and how to handle Chinese, Japanese, and Korean characters.', [':cron' => Url::fromRoute('system.cron_settings')->toString(), ':search-settings' => Url::fromRoute('entity.search_page.collection')->toString()]) . '
'; $output .= '
' . t('Modules providing search page plugins generally ensure that content-related actions on your site (creating, editing, or deleting content and comments) automatically cause affected content items to be marked for indexing or reindexing at the next cron run. When content is marked for reindexing, the previous content remains in the index until cron runs, at which time it is replaced by the new content. However, there are some actions related to the structure of your site that do not cause affected content to be marked for reindexing. Examples of structure-related actions that affect content include deleting or editing taxonomy terms, enabling or disabling modules that add text to content (such as Taxonomy, Comment, and field-providing modules), and modifying the fields or display parameters of your content types. If you take one of these actions and you want to ensure that the search index is updated to reflect your changed site structure, you can mark all content for reindexing by clicking the "Re-index site" button on the Search pages page. If you have a lot of content on your site, it may take several cron runs for the content to be reindexed.', [':search-settings' => Url::fromRoute('entity.search_page.collection')->toString()]) . '
'; diff --git a/core/modules/search/src/SearchPageListBuilder.php b/core/modules/search/src/SearchPageListBuilder.php index 3821181356..f9601a2ba0 100644 --- a/core/modules/search/src/SearchPageListBuilder.php +++ b/core/modules/search/src/SearchPageListBuilder.php @@ -146,7 +146,7 @@ public function buildRow(EntityInterface $entity) { $row['label'] = $entity->label(); $row['url'] = [ '#type' => 'link', - '#title' => $row['url'], + '#title' => 'search/' . $entity->getPath(), '#url' => Url::fromRoute('search.view_' . $entity->id()), ]; @@ -317,9 +317,13 @@ public function getDefaultOperations(EntityInterface $entity) { /** @var $entity \Drupal\search\SearchPageInterface */ $operations = parent::getDefaultOperations($entity); - // Prevent the default search from being disabled or deleted. + // Do not allow enable/disable operations. + unset($operations['enable']); + unset($operations['disable']); + + // Prevent the default search from being deleted. if ($entity->isDefaultSearch()) { - unset($operations['disable'], $operations['delete']); + unset($operations['delete']); } else { $operations['default'] = [ diff --git a/core/modules/search/src/SearchPageRepository.php b/core/modules/search/src/SearchPageRepository.php index 4a7b270e85..d08fda7fbf 100644 --- a/core/modules/search/src/SearchPageRepository.php +++ b/core/modules/search/src/SearchPageRepository.php @@ -94,7 +94,6 @@ public function clearDefaultSearchPage() { */ public function setDefaultSearchPage(SearchPageInterface $search_page) { $this->configFactory->getEditable('search.settings')->set('default_page', $search_page->id())->save(); - $search_page->enable()->save(); } /** diff --git a/core/modules/search/tests/src/Functional/SearchConfigSettingsFormTest.php b/core/modules/search/tests/src/Functional/SearchConfigSettingsFormTest.php index f0c9422d6a..eb359c5276 100644 --- a/core/modules/search/tests/src/Functional/SearchConfigSettingsFormTest.php +++ b/core/modules/search/tests/src/Functional/SearchConfigSettingsFormTest.php @@ -126,93 +126,6 @@ public function testSearchModuleSettingsPage() { $this->assertTrue($this->xpath('//select[@id="edit-extra-type-settings-boost"]//option[@value="ii" and @selected="selected"]'), 'Module specific settings can be changed'); } - /** - * Verifies that you can disable individual search plugins. - */ - public function testSearchModuleDisabling() { - // Array of search plugins to test: 'keys' are the keywords to search for, - // and 'text' is the text to assert is on the results page. - $plugin_info = [ - 'node_search' => [ - 'keys' => 'pizza', - 'text' => $this->searchNode->label(), - ], - 'user_search' => [ - 'keys' => $this->searchUser->getAccountName(), - 'text' => $this->searchUser->getEmail(), - ], - 'dummy_search_type' => [ - 'keys' => 'foo', - 'text' => 'Dummy search snippet to display', - ], - ]; - $plugins = array_keys($plugin_info); - /** @var $entities \Drupal\search\SearchPageInterface[] */ - $entities = SearchPage::loadMultiple(); - // Disable all of the search pages. - foreach ($entities as $entity) { - $entity->disable()->save(); - } - - // Test each plugin if it's enabled as the only search plugin. - foreach ($entities as $entity_id => $entity) { - $this->setDefaultThroughUi($entity_id); - - // Run a search from the correct search URL. - $info = $plugin_info[$entity_id]; - $this->drupalGet('search/' . $entity->getPath(), ['query' => ['keys' => $info['keys']]]); - $this->assertResponse(200); - $this->assertNoText('no results', $entity->label() . ' search found results'); - $this->assertText($info['text'], 'Correct search text found'); - - // Verify that other plugin search tab labels are not visible. - foreach ($plugins as $other) { - if ($other != $entity_id) { - $label = $entities[$other]->label(); - $this->assertNoText($label, $label . ' search tab is not shown'); - } - } - - // Run a search from the search block on the node page. Verify you get - // to this plugin's search results page. - $terms = ['keys' => $info['keys']]; - $this->drupalPostForm('node', $terms, t('Search')); - $current = $this->getURL(); - $expected = Url::fromRoute('search.view_' . $entity->id(), [], ['query' => ['keys' => $info['keys']], 'absolute' => TRUE])->toString(); - $this->assertEqual($current, $expected, 'Block redirected to right search page'); - - // Try an invalid search path, which should 404. - $this->drupalGet('search/not_a_plugin_path'); - $this->assertResponse(404); - - $entity->disable()->save(); - } - - // Set the node search as default. - $this->setDefaultThroughUi('node_search'); - - // Test with all search plugins enabled. When you go to the search - // page or run search, all plugins should be shown. - foreach ($entities as $entity) { - $entity->enable()->save(); - } - - \Drupal::service('router.builder')->rebuild(); - - $paths = [ - ['path' => 'search/node', 'options' => ['query' => ['keys' => 'pizza']]], - ['path' => 'search/node', 'options' => []], - ]; - - foreach ($paths as $item) { - $this->drupalGet($item['path'], $item['options']); - foreach ($plugins as $entity_id) { - $label = $entities[$entity_id]->label(); - $this->assertText($label, new FormattableMarkup('%label search tab is shown', ['%label' => $label])); - } - } - } - /** * Tests the ordering of search pages on a clean install. */ @@ -269,7 +182,7 @@ public function testMultipleSearchPages() { $second_id = $second['id'] = strtolower($this->randomMachineName(8)); $second['path'] = strtolower($this->randomMachineName(8)); $this->drupalPostForm(NULL, $second, t('Save')); - $this->assertDefaultSearch($first_id, 'The default page matches the only search page.'); + $this->assertDefaultSearch($first_id, 'The default page matches the first search page.'); // Ensure both search pages have their tabs displayed. $this->drupalGet('search'); @@ -290,45 +203,28 @@ public function testMultipleSearchPages() { // Check the initial state of the search pages. $this->drupalGet('admin/config/search/pages'); - $this->verifySearchPageOperations($first_id, TRUE, FALSE, FALSE, FALSE); - $this->verifySearchPageOperations($second_id, TRUE, TRUE, TRUE, FALSE); + $this->verifySearchPageOperations($first_id, TRUE, FALSE); + $this->verifySearchPageOperations($second_id, TRUE, TRUE); // Change the default search page. $this->clickLink(t('Set as default')); $this->assertRaw(t('The default search page is now %label. Be sure to check the ordering of your search pages.', ['%label' => $second['label']])); - $this->verifySearchPageOperations($first_id, TRUE, TRUE, TRUE, FALSE); - $this->verifySearchPageOperations($second_id, TRUE, FALSE, FALSE, FALSE); - - // Disable the first search page. - $this->clickLink(t('Disable')); - $this->assertResponse(200); - $this->assertNoLink(t('Disable')); - $this->verifySearchPageOperations($first_id, TRUE, TRUE, FALSE, TRUE); - $this->verifySearchPageOperations($second_id, TRUE, FALSE, FALSE, FALSE); - - // Enable the first search page. - $this->clickLink(t('Enable')); - $this->assertResponse(200); - $this->verifySearchPageOperations($first_id, TRUE, TRUE, TRUE, FALSE); - $this->verifySearchPageOperations($second_id, TRUE, FALSE, FALSE, FALSE); + $this->verifySearchPageOperations($first_id, TRUE, TRUE); + $this->verifySearchPageOperations($second_id, TRUE, FALSE); // Test deleting. $this->clickLink(t('Delete')); $this->assertRaw(t('Are you sure you want to delete the search page %label?', ['%label' => $first['label']])); $this->drupalPostForm(NULL, [], t('Delete')); $this->assertRaw(t('The search page %label has been deleted.', ['%label' => $first['label']])); - $this->verifySearchPageOperations($first_id, FALSE, FALSE, FALSE, FALSE); + $this->verifySearchPageOperations($first_id, FALSE, FALSE); } /** - * Tests that the enable/disable/default routes are protected from CSRF. + * Tests that the set default route is protected from CSRF. */ public function testRouteProtection() { - // Ensure that the enable and disable routes are protected. - $this->drupalGet('admin/config/search/pages/manage/node_search/enable'); - $this->assertResponse(403); - $this->drupalGet('admin/config/search/pages/manage/node_search/disable'); - $this->assertResponse(403); + // Ensure that the set default route is protected. $this->drupalGet('admin/config/search/pages/manage/node_search/set-default'); $this->assertResponse(403); } @@ -342,12 +238,8 @@ public function testRouteProtection() { * Whether the edit link is expected. * @param bool $delete * Whether the delete link is expected. - * @param bool $disable - * Whether the disable link is expected. - * @param bool $enable - * Whether the enable link is expected. */ - protected function verifySearchPageOperations($id, $edit, $delete, $disable, $enable) { + protected function verifySearchPageOperations($id, $edit, $delete) { if ($edit) { $this->assertLinkByHref("admin/config/search/pages/manage/$id"); } @@ -360,18 +252,9 @@ protected function verifySearchPageOperations($id, $edit, $delete, $disable, $en else { $this->assertNoLinkByHref("admin/config/search/pages/manage/$id/delete"); } - if ($disable) { - $this->assertLinkByHref("admin/config/search/pages/manage/$id/disable"); - } - else { - $this->assertNoLinkByHref("admin/config/search/pages/manage/$id/disable"); - } - if ($enable) { - $this->assertLinkByHref("admin/config/search/pages/manage/$id/enable"); - } - else { - $this->assertNoLinkByHref("admin/config/search/pages/manage/$id/enable"); - } + // There should never be enable/disable operations. + $this->assertNoLinkByHref("admin/config/search/pages/manage/$id/enable"); + $this->assertNoLinkByHref("admin/config/search/pages/manage/$id/disable"); } /** @@ -394,7 +277,7 @@ protected function assertDefaultSearch($expected, $message = '', $group = 'Other * Sets a search page as the default in the UI. * * @param string $entity_id - * The search page entity ID to enable. + * The search page entity ID to set as default. */ protected function setDefaultThroughUi($entity_id) { $this->drupalGet('admin/config/search/pages'); diff --git a/core/modules/search/tests/src/Kernel/Migrate/d7/MigrateSearchPageTest.php b/core/modules/search/tests/src/Kernel/Migrate/d7/MigrateSearchPageTest.php index d1f9723c3b..abc3bee017 100644 --- a/core/modules/search/tests/src/Kernel/Migrate/d7/MigrateSearchPageTest.php +++ b/core/modules/search/tests/src/Kernel/Migrate/d7/MigrateSearchPageTest.php @@ -21,7 +21,7 @@ class MigrateSearchPageTest extends MigrateDrupal7TestBase { public static $modules = ['search']; /** - * Asserts various aspects of an SearchPage entity. + * Asserts various aspects of a SearchPage entity. * * @param string $id * The expected search page ID. @@ -55,6 +55,13 @@ protected function assertEntity($id, $path, $status = FALSE, array $expected_con public function testSearchPage() { $this->enableModules(['node']); $this->installConfig(['search']); + // Remove existing search pages, if they exist. + foreach (['node_search', 'user_search'] as $id) { + $search_page = SearchPage::load($id); + if ($search_page) { + $search_page->delete(); + } + } $this->executeMigration('d7_search_page'); $configuration = [ 'rankings' => [ @@ -89,6 +96,13 @@ public function testSearchPage() { */ public function testModuleExists() { $this->installConfig(['search']); + // Remove existing search pages, if they exist. + foreach (['node_search', 'user_search'] as $id) { + $search_page = SearchPage::load($id); + if ($search_page) { + $search_page->delete(); + } + } $this->executeMigration('d7_search_page'); $this->assertNull(SearchPage::load('node_search')); diff --git a/core/modules/search/tests/src/Kernel/Migrate/d7/SearchPageTest.php b/core/modules/search/tests/src/Kernel/Migrate/d7/SearchPageTest.php index d506eafb28..2e652abfd9 100644 --- a/core/modules/search/tests/src/Kernel/Migrate/d7/SearchPageTest.php +++ b/core/modules/search/tests/src/Kernel/Migrate/d7/SearchPageTest.php @@ -53,16 +53,10 @@ public function providerSource() { $tests[0]['expected_data'] = [ [ 'module' => 'node', - 'status' => 'node', 'module_exists' => FALSE, 'node_rank_comments' => '5', 'node_rank_promote' => '1', ], - [ - 'module' => 'user', - 'status' => 0, - 'module_exists' => TRUE, - ], ]; $tests[0]['expected_count'] = NULL; diff --git a/core/modules/search/tests/src/Unit/SearchPageRepositoryTest.php b/core/modules/search/tests/src/Unit/SearchPageRepositoryTest.php index 7db3703d68..fc8f0659f3 100644 --- a/core/modules/search/tests/src/Unit/SearchPageRepositoryTest.php +++ b/core/modules/search/tests/src/Unit/SearchPageRepositoryTest.php @@ -71,9 +71,6 @@ protected function setUp() { * Tests the getActiveSearchPages() method. */ public function testGetActiveSearchPages() { - $this->query->expects($this->once()) - ->method('condition') - ->will($this->returnValue($this->query)); $this->query->expects($this->once()) ->method('execute') ->will($this->returnValue(['test' => 'test', 'other_test' => 'other_test'])); @@ -94,9 +91,6 @@ public function testGetActiveSearchPages() { * Tests the isSearchActive() method. */ public function testIsSearchActive() { - $this->query->expects($this->once()) - ->method('condition') - ->will($this->returnValue($this->query)); $this->query->expects($this->once()) ->method('range') ->with(0, 1) @@ -112,9 +106,6 @@ public function testIsSearchActive() { * Tests the getIndexableSearchPages() method. */ public function testGetIndexableSearchPages() { - $this->query->expects($this->once()) - ->method('condition') - ->will($this->returnValue($this->query)); $this->query->expects($this->once()) ->method('execute') ->will($this->returnValue(['test' => 'test', 'other_test' => 'other_test'])); @@ -160,9 +151,6 @@ public function testClearDefaultSearchPage() { * Tests the getDefaultSearchPage() method when the default is active. */ public function testGetDefaultSearchPageWithActiveDefault() { - $this->query->expects($this->once()) - ->method('condition') - ->will($this->returnValue($this->query)); $this->query->expects($this->once()) ->method('execute') ->will($this->returnValue(['test' => 'test', 'other_test' => 'other_test'])); @@ -186,9 +174,6 @@ public function testGetDefaultSearchPageWithActiveDefault() { * Tests the getDefaultSearchPage() method when the default is inactive. */ public function testGetDefaultSearchPageWithInactiveDefault() { - $this->query->expects($this->once()) - ->method('condition') - ->will($this->returnValue($this->query)); $this->query->expects($this->once()) ->method('execute') ->will($this->returnValue(['test' => 'test'])); @@ -232,12 +217,6 @@ public function testSetDefaultSearchPage() { $search_page->expects($this->once()) ->method('id') ->will($this->returnValue($id)); - $search_page->expects($this->once()) - ->method('enable') - ->will($this->returnValue($search_page)); - $search_page->expects($this->once()) - ->method('save') - ->will($this->returnValue($search_page)); $this->searchPageRepository->setDefaultSearchPage($search_page); }