chore: initial snapshot of 2meet-data-optimizer v0.1.0
Baseline before backporting wp-data-optimizer v3.0.1-v3.4.6. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01TbG1keQQ7XBa7qMQY16KCY
This commit is contained in:
@@ -0,0 +1,76 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
/**
|
||||
* Unit tests for WPDO_Conflict_Monitor — production conflict surface.
|
||||
*
|
||||
* @covers WPDO_Conflict_Monitor
|
||||
*/
|
||||
class ConflictMonitorTest extends TestCase {
|
||||
|
||||
protected function setUp(): void {
|
||||
WPDO_Conflict_Monitor::reset_cache();
|
||||
WPDO_Hook_Bus_Bridge::reset_cache();
|
||||
$GLOBALS['_wp_options'] = array();
|
||||
$GLOBALS['wp_filter'] = array();
|
||||
}
|
||||
|
||||
public function test_scan_returns_empty_when_no_conflicts(): void {
|
||||
$result = WPDO_Conflict_Monitor::scan();
|
||||
$this->assertIsArray( $result );
|
||||
$this->assertEmpty( $result );
|
||||
}
|
||||
|
||||
public function test_get_summary_when_clean(): void {
|
||||
$summary = WPDO_Conflict_Monitor::get_summary();
|
||||
$this->assertSame( 0, $summary['total'] );
|
||||
$this->assertSame( 0, $summary['hook_overlap'] );
|
||||
$this->assertSame( 0, $summary['uaepg_overlap'] );
|
||||
}
|
||||
|
||||
public function test_get_all_conflicts_lazy_scans(): void {
|
||||
// First call populates the cache.
|
||||
$first = WPDO_Conflict_Monitor::get_all_conflicts();
|
||||
$this->assertIsArray( $first );
|
||||
|
||||
// Subsequent calls return the same reference (cached).
|
||||
$second = WPDO_Conflict_Monitor::get_all_conflicts();
|
||||
$this->assertSame( $first, $second );
|
||||
}
|
||||
|
||||
public function test_reset_cache_forces_rescan(): void {
|
||||
WPDO_Conflict_Monitor::scan();
|
||||
WPDO_Conflict_Monitor::reset_cache();
|
||||
|
||||
// Should not throw and should return empty (still no conflicts).
|
||||
$this->assertSame( array(), WPDO_Conflict_Monitor::scan() );
|
||||
}
|
||||
|
||||
public function test_summary_keys_always_present(): void {
|
||||
$summary = WPDO_Conflict_Monitor::get_summary();
|
||||
$this->assertArrayHasKey( 'total', $summary );
|
||||
$this->assertArrayHasKey( 'hook_overlap', $summary );
|
||||
$this->assertArrayHasKey( 'uaepg_overlap', $summary );
|
||||
}
|
||||
|
||||
public function test_admin_notice_is_silent_when_no_conflicts(): void {
|
||||
ob_start();
|
||||
WPDO_Conflict_Monitor::maybe_render_admin_notice();
|
||||
$output = ob_get_clean();
|
||||
$this->assertSame( '', $output );
|
||||
}
|
||||
|
||||
public function test_admin_bar_is_silent_when_no_conflicts(): void {
|
||||
// Pass a valid object stub to admin_bar handler — should no-op when count = 0.
|
||||
$stub = new class() {
|
||||
public array $nodes = array();
|
||||
public function add_node( array $node ): void {
|
||||
$this->nodes[] = $node;
|
||||
}
|
||||
};
|
||||
WPDO_Conflict_Monitor::maybe_render_admin_bar( $stub );
|
||||
$this->assertCount( 0, $stub->nodes );
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user