Skip to content

test: expand Unit coverage for plugin lifecycle, navigation, and menu setup - #270

Open
TheWitness wants to merge 1 commit into
developfrom
test/expand-coverage
Open

TheWitness wants to merge 1 commit into
developfrom
test/expand-coverage

Conversation

@TheWitness

Copy link
Copy Markdown
Member

This plugin already had extensive Security/Unit coverage (auth guards, output escaping, prepared-statement migration, listener port/command security, query building, core formatting helpers). The gap was setup.php's plugin-lifecycle functions, which were only checked for static existence. Closed the safely-testable part of that gap, running the full suite against a real Cacti install in WSL (composer-managed Pest, not a plugin-local vendor tree) until everything passed.

Added coverage

  • plugin_flowview_version()
  • plugin_flowview_check_config() (the no-config-file branch, which is the only one reachable without a configured Flowview database)
  • plugin_flowview_upgrade() and plugin_flowview_check_upgrade()'s page-guard
  • flowview_draw_navigation_text()
  • flowview_config_arrays() (menu registration under Import/Export)

Intentionally not covered

plugin_flowview_install(), plugin_flowview_uninstall(), flowview_setup_table(), and flowview_drop_table() all unconditionally call flowview_connect(), which performs a real database connection (or a fatal exit() on failure) and, via plugin_flowview_check_upgrade(), can include_once() Cacti core's real lib/poller.php — the same unconditionally-declared-core-function hazard documented for other plugins' poller_bottom-style functions in this fleet. Those functions are not safely testable without a real Flowview database.

Security

No new unserialize() hardening was needed: every unserialize() call in this plugin already goes through sanitize_unserialize_selected_items() or an explicit allowed_classes => false (including in the vendored Net\DNS2 library).

Test infrastructure

tests/bootstrap-unit.php gained api_plugin_register_hook/api_plugin_register_realm call-logging stubs (the existing plugin_test_reset/plugin_test_queue_db_result/plugin_test_db_result fixture convention was reused as-is).

Result

Tests: 77 passed (1200 assertions), up from 71.

… setup

This plugin already had extensive Security/Unit coverage (auth guards,
output escaping, prepared-statement migration, listener port/command
security, query building, core formatting helpers). The gap was
setup.php's plugin-lifecycle functions, which were only checked for
static existence. Closed the safely-testable part of that gap:

- plugin_flowview_version()
- plugin_flowview_check_config() (the no-config-file branch, which is
  the only one reachable without a configured Flowview database)
- plugin_flowview_upgrade() and plugin_flowview_check_upgrade()'s
  page-guard
- flowview_draw_navigation_text()
- flowview_config_arrays() (menu registration under Import/Export)

Intentionally left uncovered: plugin_flowview_install(),
plugin_flowview_uninstall(), flowview_setup_table(), and
flowview_drop_table() all unconditionally call flowview_connect(),
which performs a real database connection (or a fatal exit() on
failure) and, via plugin_flowview_check_upgrade(), can
include_once() Cacti core's real lib/poller.php - the same
unconditionally-declared-core-function hazard documented for other
plugins' poller_bottom-style functions in this fleet. Those functions
are not safely testable without a real Flowview database.

No new unserialize() hardening was needed: every unserialize() call in
this plugin already goes through sanitize_unserialize_selected_items()
or an explicit allowed_classes => false (including in the vendored
Net\DNS2 library).

tests/bootstrap-unit.php gained api_plugin_register_hook/
api_plugin_register_realm call-logging stubs (the existing
plugin_test_reset/plugin_test_queue_db_result/plugin_test_db_result
fixture convention was reused as-is).

Verified via a real WSL Cacti install (composer-managed Pest, not a
plugin-local vendor tree): 77 passed (1200 assertions), up from 71.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot review overview

🟡 Changes recommended

Reset registration logs between tests and add the required CHANGELOG.md entry.

Get a fresh assessment by requesting another Copilot review.

Review effort: Lite
Findings: 1 Medium severity

Open (1)
What changed in this PR

Expands FlowView unit coverage for lifecycle, navigation, version parsing, and menu setup.

Changes:

  • Adds four focused unit-test files.
  • Adds hook and realm registration logging stubs to the test bootstrap.
File Summary
tests/​Unit/​FlowviewVersionTest.php Tests plugin metadata parsing.
tests/​Unit/​FlowviewNavigationTest.php Tests navigation entries.
tests/​Unit/​FlowviewLifecycleTest.php Tests lifecycle guard behavior.
tests/​Unit/​FlowviewConfigArraysTest.php Tests menu registration.
tests/​bootstrap-unit.php Adds registration logging fixtures.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread tests/bootstrap-unit.php
}
}

$GLOBALS['__test_registered_hooks'] = array();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants