Simpletest Coverage - modules/search/search.pages.inc

1 <?php
2 // $Id: search.pages.inc,v 1.10 2009/07/29 06:39:34 dries Exp $
3
4 /**
5 * @file
6 * User page callbacks for the search module.
7 */
8
9 /**
10 * Menu callback; presents the search form and/or search results.
11 */
12 function search_view($type = 'node') {
13 // Search form submits with POST but redirects to GET. This way we can keep
14 // the search query URL clean as a whistle:
15 // search/type/keyword+keyword
16 if (!isset($_POST['form_id'])) {
17 if ($type == '') {
18 // Note: search/node can not be a default tab because it would take on the
19 // path of its parent (search). It would prevent remembering keywords when
20 // switching tabs. This is why we drupal_goto to it from the parent instead.
21 drupal_goto('search/node');
22 }
23
24 $keys = search_get_keys();
25 // Only perform search if there is non-whitespace search term:
26 $results = '';
27 if (trim($keys)) {
28 // Log the search keys:
29 watchdog('search', '%keys (@type).', array('%keys' => $keys, '@type' => module_invoke($type, 'search', 'name')), WATCHDOG_NOTICE, l(t('results'), 'search/' . $type . '/' . $keys));
30
31 // Collect the search results:
32 $results = search_data($keys, $type);
33
34 // Construct the search form.
35 $build['search_form'] = drupal_get_form('search_form', NULL, $keys, $type);
36 $build['search_results'] = array(
37 '#theme' => 'search_results_listing',
38 '#title' => empty($results) ? t('Your search yielded no results') : t('Search results'),
39 '#content' => empty($results) ? search_help('search#noresults', drupal_help_arg()) : $results,
40 );
41
42 return $build;
43 }
44 }
45
46 return drupal_get_form('search_form', NULL, empty($keys) ? '' : $keys, $type);
47 }
48
49 /**
50 * Theme the listing of search results
51 *
52 * @param $title
53 * The subject of the listing.
54 * @param $content
55 * The content of the listing.
56 * @return
57 * A string containing the listing output.
58 */
59 function theme_search_results_listing($title, $content) {
60 $output = '<h2 class="title">' . $title . '</h2><div>' . $content . '</div>';
61 return $output;
62 }
63
64 /**
65 * Process variables for search-results.tpl.php.
66 *
67 * The $variables array contains the following arguments:
68 * - $results
69 * - $type
70 *
71 * @see search-results.tpl.php
72 */
73 function template_preprocess_search_results(&$variables) {
74 $variables['search_results'] = '';
75 foreach ($variables['results'] as $result) {
76 $variables['search_results'] .= theme('search_result', $result, $variables['type']);
77 }
78 $variables['pager'] = theme('pager', NULL);
79 // Provide alternate search results template.
80 $variables['template_files'][] = 'search-results-' . $variables['type'];
81 }
82
83 /**
84 * Process variables for search-result.tpl.php.
85 *
86 * The $variables array contains the following arguments:
87 * - $result
88 * - $type
89 *
90 * @see search-result.tpl.php
91 */
92 function template_preprocess_search_result(&$variables) {
93 $result = $variables['result'];
94 $variables['url'] = check_url($result['link']);
95 $variables['title'] = check_plain($result['title']);
96
97 $info = array();
98 if (!empty($result['type'])) {
99 $info['type'] = check_plain($result['type']);
100 }
101 if (!empty($result['user'])) {
102 $info['user'] = $result['user'];
103 }
104 if (!empty($result['date'])) {
105 $info['date'] = format_date($result['date'], 'small');
106 }
107 if (isset($result['extra']) && is_array($result['extra'])) {
108 $info = array_merge($info, $result['extra']);
109 }
110 // Check for existence. User search does not include snippets.
111 $variables['snippet'] = isset($result['snippet']) ? $result['snippet'] : '';
112 // Provide separated and grouped meta information..
113 $variables['info_split'] = $info;
114 $variables['info'] = implode(' - ', $info);
115 // Provide alternate search result template.
116 $variables['template_files'][] = 'search-result-' . $variables['type'];
117 }
118
119 /**
120 * As the search form collates keys from other modules hooked in via
121 * hook_form_alter, the validation takes place in _submit.
122 * search_form_validate() is used solely to set the 'processed_keys' form
123 * value for the basic search form.
124 */
125 function search_form_validate($form, &$form_state) {
126 form_set_value($form['basic']['inline']['processed_keys'], trim($form_state['values']['keys']), $form_state);
127 }
128
129 /**
130 * Process a search form submission.
131 */
132 function search_form_submit($form, &$form_state) {
133 $keys = $form_state['values']['processed_keys'];
134 if ($keys == '') {
135 form_set_error('keys', t('Please enter some keywords.'));
136 // Fall through to the drupal_goto() call.
137 }
138
139 $type = $form_state['values']['module'] ? $form_state['values']['module'] : 'node';
140 $form_state['redirect'] = 'search/' . $type . '/' . $keys;
141 return;
142 }
143

Legend

Missed
lines code that were not excersized during program execution.
Covered
lines code were excersized during program execution.
Comment/non executable
Comment or non-executable line of code.
Dead
lines of code that according to xdebug could not be executed. This is counted as coverage code because in almost all cases it is code that runnable.