peptide-geo-monitor v0.1.0: internal AI-visibility dashboard (#1)
New internal plugin: weekly LLM probes of core peptides (Perplexity sonar + GPT/Gemini-search via OpenRouter/CF gateway) -> custom table -> wp-admin trendline + standings. Provider interface + cost ledger w/ hard $5/mo cap + collector/panel seam (AI-visibility only). v1 = AI-visibility only. QA: APPROVE-WITH-P2-NOTES — qa-reviews/peptide-geo-monitor/2026-06-13-f488f4a966cbb9e771d3abc20daee3fa49074520.md (P2 follow-ups: ltrim www display bug, PHPCS mandatory, dead cache) Agent-Session: geomonitor v0.1.0 merge
This commit is contained in:
64
tests/unit/test-cron.php
Normal file
64
tests/unit/test-cron.php
Normal file
@@ -0,0 +1,64 @@
|
||||
<?php
|
||||
/**
|
||||
* Tests for PGM_Cron: scheduling, clearing, and registration.
|
||||
*
|
||||
* @package PeptideGeoMonitor
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
require_once __DIR__ . '/../bootstrap.php';
|
||||
|
||||
echo "=== PGM Cron Tests ===\n";
|
||||
|
||||
// ── Test: schedule_weekly adds the event ────────────────────────────────
|
||||
|
||||
pgm_test_reset();
|
||||
pgm_assert( ! PGM_Cron::is_scheduled(), 'schedule_weekly: not scheduled before call' );
|
||||
|
||||
PGM_Cron::schedule_weekly();
|
||||
pgm_assert( PGM_Cron::is_scheduled(), 'schedule_weekly: event scheduled after call' );
|
||||
|
||||
// ── Test: schedule_weekly is idempotent ──────────────────────────────────
|
||||
|
||||
PGM_Cron::schedule_weekly(); // Second call should no-op.
|
||||
$events = $GLOBALS['pgm_test_state']['cron_events'];
|
||||
pgm_assert_equals( 1, count( $events ), 'schedule_weekly: idempotent — second call does not add duplicate' );
|
||||
|
||||
// ── Test: clear_schedule removes the event ──────────────────────────────
|
||||
|
||||
PGM_Cron::clear_schedule();
|
||||
pgm_assert( ! PGM_Cron::is_scheduled(), 'clear_schedule: event removed after clear' );
|
||||
|
||||
// ── Test: clear_schedule is safe when nothing scheduled ─────────────────
|
||||
|
||||
pgm_test_reset();
|
||||
PGM_Cron::clear_schedule(); // Should not throw.
|
||||
pgm_assert( ! PGM_Cron::is_scheduled(), 'clear_schedule: safe when nothing scheduled' );
|
||||
|
||||
// ── Test: register_hooks registers the cron hook action ─────────────────
|
||||
|
||||
pgm_test_reset();
|
||||
$cron = new PGM_Cron();
|
||||
$cron->register_hooks();
|
||||
|
||||
$hooks = array_column( $GLOBALS['pgm_test_state']['actions'], 'hook' );
|
||||
pgm_assert( in_array( PGM_CRON_HOOK, $hooks, true ), 'register_hooks: pgm_weekly_probe action registered' );
|
||||
|
||||
// ── Test: hook constant is correct string ────────────────────────────────
|
||||
|
||||
pgm_assert_equals( 'pgm_weekly_probe', PGM_CRON_HOOK, 'PGM_CRON_HOOK: constant value correct' );
|
||||
|
||||
// ── Test: PGM_Activator calls schedule_weekly ────────────────────────────
|
||||
|
||||
pgm_test_reset();
|
||||
// Seed options so seed_defaults() doesn't fail.
|
||||
PGM_Activator::activate();
|
||||
pgm_assert( PGM_Cron::is_scheduled(), 'PGM_Activator::activate: weekly cron scheduled after activation' );
|
||||
|
||||
// ── Test: PGM_Deactivator calls clear_schedule ───────────────────────────
|
||||
|
||||
PGM_Deactivator::deactivate();
|
||||
pgm_assert( ! PGM_Cron::is_scheduled(), 'PGM_Deactivator::deactivate: cron cleared after deactivation' );
|
||||
|
||||
exit( pgm_test_summary() );
|
||||
Reference in New Issue
Block a user