Index: modules/search/search.pages.inc =================================================================== RCS file: /cvs/drupal/drupal/modules/search/search.pages.inc,v retrieving revision 1.21 diff -u -r1.21 search.pages.inc --- modules/search/search.pages.inc 5 Aug 2010 07:11:15 -0000 1.21 +++ modules/search/search.pages.inc 6 Aug 2010 21:43:06 -0000 @@ -97,17 +97,21 @@ $variables['title'] = check_plain($result['title']); $info = array(); - if (!empty($result['type'])) { - $info['type'] = check_plain($result['type']); - } - if (!empty($result['user'])) { - $info['user'] = $result['user']; - } - if (!empty($result['date'])) { - $info['date'] = format_date($result['date'], 'short'); - } - if (isset($result['extra']) && is_array($result['extra'])) { - $info = array_merge($info, $result['extra']); + // If the item is a node, only display the post information if allowed by the + // theme. For any other type of item, display any available information. + if ($variables['type'] != 'node' || theme_get_setting('toggle_node_info_'. $result['node']->type)) { + if (!empty($result['type'])) { + $info['type'] = check_plain($result['type']); + } + if (!empty($result['user'])) { + $info['user'] = $result['user']; + } + if (!empty($result['date'])) { + $info['date'] = format_date($result['date'], 'short'); + } + if (isset($result['extra']) && is_array($result['extra'])) { + $info = array_merge($info, $result['extra']); + } } // Check for existence. User search does not include snippets. $variables['snippet'] = isset($result['snippet']) ? $result['snippet'] : ''; Index: modules/search/search-result.tpl.php =================================================================== RCS file: /cvs/drupal/drupal/modules/search/search-result.tpl.php,v retrieving revision 1.6 diff -u -r1.6 search-result.tpl.php --- modules/search/search-result.tpl.php 29 May 2010 07:50:33 -0000 1.6 +++ modules/search/search-result.tpl.php 6 Aug 2010 21:43:06 -0000 @@ -13,8 +13,9 @@ * - $url: URL of the result. * - $title: Title of the result. * - $snippet: A small preview of the result. Does not apply to user searches. - * - $info: String of all the meta information ready for print. Does not apply - * to user searches. + * - $info: String of all the meta information ready for print. Applies only to + * node searches, and then only for node types where theme settings allow post + * information to be displayed. * - $info_split: Contains same data as $info, split into a keyed array. * - $type: The type of search, e.g., "node" or "user". * @@ -29,9 +30,8 @@ * being the count. Depends on upload.module. * * Since $info_split is keyed, a direct print of the item is possible. - * This array does not apply to user searches so it is recommended to check - * for their existence before printing. The default keys of 'type', 'user' and - * 'date' always exist for node searches. Modules may provide other data. + * This array does not always apply, so it is recommended to check for its + * existence before printing. Modules may provide other data. * * * Index: modules/search/search.test =================================================================== RCS file: /cvs/drupal/drupal/modules/search/search.test,v retrieving revision 1.68 diff -u -r1.68 search.test --- modules/search/search.test 5 Aug 2010 23:53:38 -0000 1.68 +++ modules/search/search.test 6 Aug 2010 21:43:06 -0000 @@ -988,6 +988,77 @@ } } +class SearchNodeInformationTestCase extends DrupalWebTestCase { + /** + * Implementation of getInfo(). + */ + function getInfo() { + return array( + 'name' => t('Search result content'), + 'description' => t('Verifies that post information is displayed with search results in accordance with theme settings.'), + 'group' => t('Search'), + ); + } + + /** + * Implementation setUp(). + */ + function setUp() { + parent::setUp('search'); + } + + /** + * Test content returned in search results + */ + function testNodeInformation() { + // Login with sufficient privileges. + $user = $this->drupalCreateUser(array('create page content', 'search content', 'use advanced search')); + $this->drupalLogin($user); + + // Create node for testing. + $settings = array('type' => 'page', 'title' => 'Drupal rocks', 'body' => "Drupal's search rocks"); + $node = $this->drupalCreateNode($settings); + + // Update the search index. + node_update_index(); + search_update_totals(); + + $theme_settings = variable_get('theme_settings', array()); + $this->assertTrue(isset($theme_settings['toggle_node_info_page'])); + + if (isset($theme_settings['toggle_node_info_page'])) { + + // Make sure toggle_node_info_page is false. + $theme_settings['toggle_node_info_page'] = FALSE; + variable_set('theme_settings', $theme_settings); + cache_clear_all(); + $this->assertFalse(theme_get_setting('toggle_node_info_page', TRUE)); + + // Do the search. + $search_query['keys'] = 'rocks'; + $this->drupalPost('search/node', $search_query, 'Search'); + + // Parse result and look for

...

; there should not be any. + $this->parse(); + $this->assertFalse($this->elements->xpath('//p[@class="search-info"]')); + + // Make sure toggle_node_info_page is true. + $theme_settings['toggle_node_info_page'] = TRUE; + variable_set('theme_settings', $theme_settings); + cache_clear_all(); + $this->assertTrue(theme_get_setting('toggle_node_info_page', TRUE)); + + // Do the search. + $search_query['keys'] = 'rocks'; + $this->drupalPost('search/node', $search_query, 'Search'); + + // Parse result and look for

...

; there should be one. + $this->parse(); + $this->assertTrue($this->elements->xpath('//p[@class="search-info"]')); + } + } +} + /** * Test config page. */