Skip to content

test: add Unit/Integration coverage for setup.php lifecycle functions - #24

Merged
TheWitness merged 1 commit into
mainfrom
test/expand-coverage
Sep 23, 2026
Merged

TheWitness merged 1 commit into
mainfrom
test/expand-coverage

Conversation

@TheWitness

Copy link
Copy Markdown
Member

Summary

This plugin already had strong Security coverage (auth guards, output escaping, prepared-statement migration regression tests, redirect safety), but no coverage at all for setup.php's own lifecycle functions. This PR closes that gap.

Test coverage added

  • Unit: plugin_quicktree_version(), plugin_quicktree_uninstall()/check_config()/upgrade(), quicktree_check_upgrade() (page-guard, no-drift, and version-drift branches - including the plugin_config UPDATE and re-enabling the page_head hook), quicktree_setup_table() (page-style default clamping for unset/out-of-range/valid stored values), quicktree_config_settings()/quicktree_config_arrays() (settings-merge vs. fresh-array branches, console-menu-entry gating on page style), and quicktree_page_location() (all branch combinations).
  • Integration: plugin_quicktree_install() - verifies every one of its 8 hooks and its realm are actually registered, together with the table/config-option it provisions, in a single end-to-end pass.

Bootstrap changes (tests/bootstrap-unit.php)

  • api_plugin_register_hook/api_plugin_register_realm now exist and log calls (they weren't stubbed at all before).
  • read_config_option/set_config_option now share a real backing store instead of being hardcoded to a blank read / no-op write. Verified no existing test relied on the old hardcoded behavior before making this change.
  • db_fetch_cell_prepared now logs its calls and returns a settable fixture value instead of an unconditional empty string, needed to exercise quicktree_check_upgrade()'s version-drift branch.

Other fix

tests/.cacti-version was pinned to a stale exact release (1.2.31), which made every local/CI run fail its own bootstrap version-match guard against a newer Cacti checkout. Corrected to 1.2.x, matching what the CI workflow already expects.

Intentionally not covered

quicktree_show_tab(), quicktree_graph_buttons(), quicktree_page_head() - all three are print-heavy UI functions gated by api_user_realm_auth() against a real HTTP request context, consistent with the same category of functions skipped in other plugins' suites.

Result

Verified via a real WSL Cacti install:

Tests:    58 passed (192 assertions)
Duration: 0.73s

(up from 38 passed / 133 assertions before this PR)

This plugin already had strong Security coverage (auth guards, output
escaping, prepared-statement migration regression tests, redirect
safety) but no coverage at all for setup.php's own lifecycle
functions: plugin_quicktree_install/version/uninstall/check_config/
upgrade, quicktree_check_upgrade, quicktree_setup_table,
quicktree_config_settings/config_arrays, and quicktree_page_location.

Added:
- tests/Unit/QuicktreeVersionTest.php
- tests/Unit/QuicktreeLifecycleTest.php (uninstall/check_config/upgrade)
- tests/Unit/QuicktreeCheckUpgradeTest.php (page-guard, no-drift, and
  version-drift branches, including the plugin_config UPDATE)
- tests/Unit/QuicktreeSetupTableTest.php (page-style default clamping)
- tests/Unit/QuicktreeConfigSettingsAndArraysTest.php (settings merge
  vs. fresh-array branches, console-menu-entry gating)
- tests/Unit/QuicktreePageLocationTest.php (all branch combinations)
- tests/Integration/QuicktreeInstallHooksTest.php (verifies every hook
  and the realm plugin_quicktree_install() registers, together with
  its table/config-option provisioning, end-to-end)

Bootstrap additions needed for the above (tests/bootstrap-unit.php):
- api_plugin_register_hook/api_plugin_register_realm now log calls
  into $GLOBALS['__test_registered_hooks']/['__test_registered_realms']
  instead of not existing at all.
- read_config_option/set_config_option now share a real backing store
  ($GLOBALS['__test_config_options']) instead of being hardcoded to a
  blank read / no-op write. Verified no existing test relied on the
  old hardcoded behavior before making this change.
- db_fetch_cell_prepared now logs its calls and returns a settable
  fixture value (quicktree_test_set_db_fetch_cell_prepared_return())
  instead of an unconditional empty string, needed to exercise
  quicktree_check_upgrade()'s version-drift branch.

Also fixed a stale tests/.cacti-version pin (1.2.31 -> 1.2.x) that
made every local/CI run fail its own bootstrap version-match guard
against a newer Cacti checkout.

Intentionally not covered: quicktree_show_tab(), quicktree_graph_buttons(),
quicktree_page_head() - all three are print-heavy UI functions gated by
api_user_realm_auth() against a real HTTP request context, consistent
with the same category of functions skipped in other plugins' suites.

Verified via a real WSL Cacti install: 58 passed (192 assertions), up
from 38 passed (133 assertions).
@TheWitness
TheWitness requested review from bmfmancini and xmacan and a lite review from Copilot and removed request for Copilot September 22, 2026 11:23

@bmfmancini bmfmancini left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

LGTM

@TheWitness
TheWitness merged commit 17dd619 into main Sep 23, 2026
5 checks passed
@TheWitness
TheWitness deleted the test/expand-coverage branch September 25, 2026 07:03
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