mirror of
https://github.com/Cacti/plugin_thold.git
synced 2026-10-23 19:47:13 +09:00
* issue: shorten thold VRULE graph drilldown button title The graph action menu now renders each drilldown button's title as a visible label, so 'Toggle Threshold VRULES %s' reads as an overlong menu entry. Shorten it to 'Toggle VRULES %s', add a unit test exercising thold_graph_button()'s VRULE branch (with the two missing request-var stubs it needs) so the changed line stays covered, and regenerate locales/po/cacti.pot. * Update copyright notice in TholdGraphButtonTest.php Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com> * Fix Last-Translator entry in cacti.pot Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com> * test: cover the VRULEs-enabled 'Off' title branch for patch coverage --------- Co-authored-by: TheWitness <1439914+TheWitness@users.noreply.github.com> Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
82 lines
3.1 KiB
PHP
82 lines
3.1 KiB
PHP
<?php
|
|
/*
|
|
+-------------------------------------------------------------------------+
|
|
| Copyright (C) 2004-2026 The Cacti Group |
|
|
| |
|
|
| This program is free software; you can redistribute it and/or |
|
|
| modify it under the terms of the GNU General Public License |
|
|
| as published by the Free Software Foundation; either version 2 |
|
|
| of the License, or (at your option) any later version. |
|
|
+-------------------------------------------------------------------------+
|
|
| Cacti: The Complete RRDtool-based Graphing Solution |
|
|
+-------------------------------------------------------------------------+
|
|
| http://www.cacti.net/ |
|
|
+-------------------------------------------------------------------------+
|
|
*/
|
|
|
|
/**
|
|
* thold_graph_button() renders this plugin's graph-page drilldown action
|
|
* icons. This covers the VRULE toggle button's markup, including the
|
|
* 'Toggle Threshold VRULES On'/'Off' title that shows as a label in Cacti's
|
|
* graph action menu.
|
|
*/
|
|
final class TholdGraphButtonTest extends TestCase {
|
|
/**
|
|
* @return void
|
|
*/
|
|
public static function setUpBeforeClass(): void {
|
|
self::loadPluginSource('setup.php');
|
|
}
|
|
|
|
/**
|
|
* @return void
|
|
*/
|
|
protected function setUp(): void {
|
|
parent::setUp();
|
|
|
|
CactiStubs::reset();
|
|
}
|
|
|
|
/**
|
|
* @return void
|
|
*/
|
|
public function test_it_prints_the_vrule_button_with_the_shortened_title(): void {
|
|
// A threshold exists for the graph, so the VRULE toggle is shown; the
|
|
// aggregate lookup returns a row so the Create Threshold branch is skipped.
|
|
CactiStubs::willReturnFor('db_fetch_cell_prepared', 'thold_data', 123);
|
|
CactiStubs::willReturnFor('db_fetch_cell_prepared', 'aggregate_graphs', 5);
|
|
|
|
$_SERVER['REQUEST_URI'] = '/cacti/graph_view.php?action=preview';
|
|
$_SESSION = [];
|
|
|
|
ob_start();
|
|
thold_graph_button([1 => ['local_graph_id' => 10, 'rra' => 5]]);
|
|
$html = ob_get_clean();
|
|
|
|
$this->assertStringContainsString('iconLink tholdVRule', $html);
|
|
$this->assertStringContainsString('tholdVRules far fa-chart-bar', $html);
|
|
// Default state (no session/request var) resolves to the 'On' action and
|
|
// keeps the Thold-specific 'Threshold' reference.
|
|
$this->assertStringContainsString('Toggle Threshold VRULES On', $html);
|
|
$this->assertStringNotContainsString('Toggle VRULES', $html);
|
|
}
|
|
|
|
/**
|
|
* @return void
|
|
*/
|
|
public function test_it_shows_the_off_title_when_vrules_are_enabled(): void {
|
|
CactiStubs::willReturnFor('db_fetch_cell_prepared', 'thold_data', 123);
|
|
CactiStubs::willReturnFor('db_fetch_cell_prepared', 'aggregate_graphs', 5);
|
|
|
|
$_SERVER['REQUEST_URI'] = '/cacti/graph_view.php?action=preview';
|
|
// VRULEs already drawing (session on) resolves to the 'Off' action title.
|
|
$_SESSION = ['sess_config_array' => ['thold_draw_vrules' => 'on']];
|
|
|
|
ob_start();
|
|
thold_graph_button([1 => ['local_graph_id' => 10, 'rra' => 5]]);
|
|
$html = ob_get_clean();
|
|
|
|
$this->assertStringContainsString('Toggle Threshold VRULES Off', $html);
|
|
}
|
|
}
|