Add initial plugin implementation per the CTO engineering handoff (geomonitor/threads/2026-06-ai-visibility-v1/01-cto-eng-handoff.md). ## What - PGM_Probe_Provider interface + PGM_Probe_Result value object - PGM_Perplexity_Provider (sonar via OpenRouter/CF AI Gateway) - PGM_OpenRouter_Provider (GPT-search + Gemini-search, generic parameterised) - PGM_Gateway_Client: shared HTTP + exponential-backoff retry (mirrors PRAB) - PGM_Citation_Detector: domain extraction, is_cited(), get_our_position() - PGM_Cost_Ledger: MTD cost from DB, can_afford() pre-check, hard monthly cap - PGM_Probe_Runner: peptides×intents×models run, budget abort, in-run cache - PGM_Table_Manager: pgm_ai_visibility dbDelta, schema-version, drop_table() - PGM_Config: typed getters, seed_defaults() (12 peptides, 3 intents, 3 models) - PGM_Cron: weekly pgm_weekly_probe schedule/clear - PGM_Data_Collector + PGM_Dashboard_Panel interfaces (seam for future panels) - PGM_Collector_Registry: singleton registry - PGM_Ai_Visibility_Collector: trendline, standings, MTD cost (score formula) - PGM_Ai_Visibility_Panel: proxy note, Chart.js trendline, standings table - PGM_Admin_Page: GEO Monitor menu, Run now POST handler (nonce+capability) - uninstall.php: DROP TABLE + DELETE pgm_* options + wp_clear_scheduled_hook - Unit tests (6 files): citation detection, score calc, cost ledger + budget abort, provider response parsing (mock HTTP), cron, uninstall purge - ARCHITECTURE.md, CONVENTIONS.md, CONTEXT.md (score formula), README.md, CHANGELOG.md — same-commit per DoD - CI workflow: PHP lint (8.1/8.2/8.3) + PHPCS + 300-line check ## Security - Secrets from wp-config constants only; none hardcoded - manage_options + nonce on every admin action - Input sanitized; output escaped Agent-Session: geomonitor v0.1.0
102 lines
4.6 KiB
PHP
102 lines
4.6 KiB
PHP
<?php
|
|
/**
|
|
* Tests for uninstall purge: table drop + options deletion.
|
|
*
|
|
* Exercises PGM_Table_Manager::drop_table() and verifies the uninstall
|
|
* script logic (simulated because it requires WP_UNINSTALL_PLUGIN).
|
|
*
|
|
* @package PeptideGeoMonitor
|
|
*/
|
|
|
|
declare(strict_types=1);
|
|
|
|
require_once __DIR__ . '/../bootstrap.php';
|
|
|
|
echo "=== PGM Uninstall Purge Tests ===\n";
|
|
|
|
// ── Mock $wpdb to track DROP calls ──────────────────────────────────────
|
|
|
|
$GLOBALS['pgm_test_state']['drop_calls'] = [];
|
|
|
|
// Extend the stub to record DROP statements.
|
|
global $wpdb;
|
|
$wpdb = new class extends stdClass_wpdb {
|
|
public function query( string $sql ): bool {
|
|
if ( str_contains( strtoupper( $sql ), 'DROP TABLE' ) ) {
|
|
$GLOBALS['pgm_test_state']['drop_calls'][] = $sql;
|
|
}
|
|
if ( str_contains( strtoupper( $sql ), 'DELETE FROM' ) && str_contains( $sql, "pgm\\_" ) ) {
|
|
$GLOBALS['pgm_test_state']['options_deleted'] = true;
|
|
}
|
|
return true;
|
|
}
|
|
};
|
|
|
|
// ── Test: drop_table issues DROP TABLE IF EXISTS ─────────────────────────
|
|
|
|
pgm_test_reset();
|
|
$GLOBALS['pgm_test_state']['drop_calls'] = [];
|
|
PGM_Table_Manager::drop_table();
|
|
|
|
pgm_assert( ! empty( $GLOBALS['pgm_test_state']['drop_calls'] ), 'drop_table: DROP TABLE query executed' );
|
|
$drop_sql = $GLOBALS['pgm_test_state']['drop_calls'][0] ?? '';
|
|
pgm_assert( str_contains( strtoupper( $drop_sql ), 'DROP TABLE IF EXISTS' ), 'drop_table: uses DROP TABLE IF EXISTS' );
|
|
pgm_assert( str_contains( $drop_sql, 'pgm_ai_visibility' ), 'drop_table: targets pgm_ai_visibility table' );
|
|
|
|
// ── Test: create_table sets the schema_version option ────────────────────
|
|
|
|
pgm_test_reset();
|
|
PGM_Table_Manager::create_table();
|
|
$schema_ver = get_option( 'pgm_schema_version' );
|
|
pgm_assert_equals( PGM_SCHEMA_VERSION, $schema_ver, 'create_table: pgm_schema_version option set after create' );
|
|
|
|
// ── Test: get_table_name returns prefixed name ───────────────────────────
|
|
|
|
pgm_test_reset();
|
|
$table = PGM_Table_Manager::get_table_name();
|
|
pgm_assert_equals( 'wp_pgm_ai_visibility', $table, 'get_table_name: returns wp_ prefixed table name' );
|
|
|
|
// ── Test: seed_defaults writes expected option keys ──────────────────────
|
|
|
|
pgm_test_reset();
|
|
PGM_Config::seed_defaults();
|
|
|
|
pgm_assert( isset( $GLOBALS['pgm_test_state']['options']['pgm_monthly_budget_usd'] ), 'seed_defaults: pgm_monthly_budget_usd set' );
|
|
pgm_assert( isset( $GLOBALS['pgm_test_state']['options']['pgm_peptides'] ), 'seed_defaults: pgm_peptides set' );
|
|
pgm_assert( isset( $GLOBALS['pgm_test_state']['options']['pgm_prompt_intents'] ), 'seed_defaults: pgm_prompt_intents set' );
|
|
pgm_assert( isset( $GLOBALS['pgm_test_state']['options']['pgm_models'] ), 'seed_defaults: pgm_models set' );
|
|
|
|
// ── Test: seed_defaults does not overwrite existing values ───────────────
|
|
|
|
pgm_test_reset();
|
|
$GLOBALS['pgm_test_state']['options']['pgm_monthly_budget_usd'] = 99.0;
|
|
PGM_Config::seed_defaults();
|
|
pgm_assert_equals( 99.0, $GLOBALS['pgm_test_state']['options']['pgm_monthly_budget_usd'], 'seed_defaults: does not overwrite existing pgm_monthly_budget_usd' );
|
|
|
|
// ── Test: default budget is PGM_DEFAULT_MONTHLY_BUDGET_USD ──────────────
|
|
|
|
pgm_test_reset();
|
|
PGM_Config::seed_defaults();
|
|
pgm_assert_equals( PGM_DEFAULT_MONTHLY_BUDGET_USD, $GLOBALS['pgm_test_state']['options']['pgm_monthly_budget_usd'], 'seed_defaults: default budget = PGM_DEFAULT_MONTHLY_BUDGET_USD (5.0)' );
|
|
|
|
// ── Test: default peptide count is 12 ───────────────────────────────────
|
|
|
|
pgm_test_reset();
|
|
$peptides = PGM_Config::get_peptides();
|
|
pgm_assert_equals( 12, count( $peptides ), 'get_peptides: default seed has 12 peptides' );
|
|
|
|
// ── Test: default prompt intent count is 3 ──────────────────────────────
|
|
|
|
pgm_test_reset();
|
|
$intents = PGM_Config::get_prompt_intents();
|
|
pgm_assert_equals( 3, count( $intents ), 'get_prompt_intents: default seed has 3 intents' );
|
|
|
|
// ── Test: default model count is 3 ──────────────────────────────────────
|
|
|
|
pgm_test_reset();
|
|
$models = PGM_Config::get_models();
|
|
pgm_assert_equals( 3, count( $models ), 'get_models: default seed has 3 models' );
|
|
pgm_assert( in_array( 'perplexity/sonar', $models, true ), 'get_models: perplexity/sonar in default models' );
|
|
|
|
exit( pgm_test_summary() );
|