Skip to content

Commit

Permalink
QA: Unit testing Filter Class
Browse files Browse the repository at this point in the history
  • Loading branch information
TheWitness committed Dec 24, 2024
1 parent ef3d27f commit f5ce932
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 27 deletions.
11 changes: 8 additions & 3 deletions lib/html_filter.php
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,10 @@ public function add_row_element($row, $id, $filter) {
}

public function render() {
if (!cacti_sizeof($this->filter_array)) {
$this->filter_array = $this->create_default();
}

/* validate filter variables */
$this->sanitize_filter_variables();

Expand All @@ -225,8 +229,9 @@ public function render() {
}

public function sanitize() {
/* create the filter for the page */
$filter = $this->create_filter();
if (!cacti_sizeof($this->filter_array)) {
$this->filter_array = $this->create_default();
}

/* validate filter variables */
$this->sanitize_filter_variables();
Expand Down Expand Up @@ -817,7 +822,7 @@ private function create_javascript() {
$globalAdd .= "\t\t" . trim($this->filter_array['javascript']['global']) . PHP_EOL;
}

if ($this->has_refresh || isset_request_var('refresh')) {
if (!$this->has_refresh && isset_request_var('refresh') && get_request_var('refresh') > 0) {
$refreshMSeconds = get_request_var('refresh') * 1000;
}

Expand Down
9 changes: 4 additions & 5 deletions user_log.php
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,6 @@ function create_filter() {
ON ua.realm = ud.domain_id+1000
ORDER BY username, realm');


if (cacti_sizeof($users)) {
$users = array_rekey($users, 'id', 'name');
}
Expand Down Expand Up @@ -296,19 +295,19 @@ function create_filter() {
'method' => 'drop_array',
'friendly_name' => __('User'),
'filter' => FILTER_VALIDATE_INT,
'default' => '0',
'default' => '-1',
'pageset' => true,
'array' => $users,
'value' => '0'
'value' => '-1'
),
'result' => array(
'method' => 'drop_array',
'friendly_name' => __('Result'),
'filter' => FILTER_VALIDATE_INT,
'default' => '0',
'default' => '-1',
'pageset' => true,
'array' => $results,
'value' => '0'
'value' => '-1'
),
'rows' => array(
'method' => 'drop_array',
Expand Down
38 changes: 19 additions & 19 deletions utilities.php
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,7 @@ function create_data_query_filter() {
$sql_where = '';
$sql_params = array();

$host_id = get_request_var('host_id');
$host_id = get_filter_request_var('host_id');

if ($host_id > 0) {
/* for the templates dropdown */
Expand All @@ -250,17 +250,17 @@ function create_data_query_filter() {
FROM host
WHERE id = ?',
array($host_id));
} elseif ($host_id == 0) {
$host_id = '0';
$hostname = __('None');
} else {
} elseif ($host_id == '' || $host_id == '-1') {
$host_id = '-1';
$hostname = __('Any');
} else {
$host_id = '0';
$hostname = __('None');
}

if (get_request_var('site_id') >= 0) {
$sql_where = ($sql_where != '' ? ' AND ':'WHERE ') . 'site_id = ?';
$sql_params[] = get_request_var('site_id');
$sql_params[] = get_filter_request_var('site_id');
}

$data_queries = array_rekey(
Expand All @@ -272,14 +272,14 @@ function create_data_query_filter() {
ON hsc.host_id = h.id
$sql_where
ORDER by sq.name",
$sql_param),
$sql_params),
'id', 'name'
);

$data_queries = $any + $data_queries;

if (isset_request_var('with_index')) {
$value = get_request_var('with_index');
$value = get_nfilter_request_var('with_index');
} else {
$value = read_config_option('default_has') == 'on' ? 'true':'false';
}
Expand Down Expand Up @@ -469,7 +469,7 @@ function utilities_view_snmp_cache() {

html_start_box('', '100%', '', '3', 'center', '');

html_header($display_text);
html_header($display_text, 1);

$i = 0;

Expand All @@ -480,9 +480,9 @@ function utilities_view_snmp_cache() {
form_selectable_cell(filter_value($item['description'], get_request_var('filter')), $i);
form_selectable_cell(filter_value($item['name'], get_request_var('filter')), $i);
form_selectable_ecell($item['snmp_index'], $i);
form_selectable_cell(filter_value($item['field_name'], get_request_var('filter')), $i);
form_selectable_cell(filter_value($item['field_value'], get_request_var('filter')), $i);
form_selectable_cell(filter_value($item['oid'], get_request_var('filter')), $i);
form_selectable_ecell(filter_value($item['field_name'], get_request_var('filter')), $i);
form_selectable_ecell(filter_value($item['field_value'], get_request_var('filter')), $i);
form_selectable_ecell(filter_value($item['oid'], get_request_var('filter')), $i);

form_end_row();
}
Expand Down Expand Up @@ -691,26 +691,26 @@ function create_poller_cache_filter() {
$sql_where = '';
$sql_params = array();

$host_id = get_request_var('host_id');
$host_id = get_filter_request_var('host_id');

if ($host_id > 0) {
/* for the templates dropdown */
$sql_where = 'AND h.id = ?';
$sql_where = ($sql_where != '' ? ' AND ':'WHERE ') . 'h.id = ?';
$sql_params[] = $host_id;

$hostname = db_fetch_cell_prepared('SELECT description
FROM host
WHERE id = ?',
array($host_id));
} elseif ($host_id == 0) {
$host_id = '0';
$hostname = __('None');
} else {
} elseif ($host_id == '' || $host_id == '-1') {
$host_id = '-1';
$hostname = __('Any');
} else {
$host_id = '0';
$hostname = __('None');
}

if (get_request_var('site_id') >= 0) {
if (get_filter_request_var('site_id') >= 0) {
$sql_where = 'AND site_id = ?';
$sql_params[] = get_request_var('site_id');
}
Expand Down

0 comments on commit f5ce932

Please sign in to comment.