assertTrue( WPDO_Hook_Bus_Bridge::is_enabled() ); } public function test_is_enabled_when_option_set_to_string_one(): void { update_option( WPDO_Hook_Bus_Bridge::OPTION, '1' ); WPDO_Hook_Bus_Bridge::reset_cache(); $this->assertTrue( WPDO_Hook_Bus_Bridge::is_enabled() ); } public function test_is_enabled_when_option_set_to_bool_true(): void { update_option( WPDO_Hook_Bus_Bridge::OPTION, true ); WPDO_Hook_Bus_Bridge::reset_cache(); $this->assertTrue( WPDO_Hook_Bus_Bridge::is_enabled() ); } public function test_is_enabled_when_option_set_to_zero(): void { update_option( WPDO_Hook_Bus_Bridge::OPTION, '0' ); WPDO_Hook_Bus_Bridge::reset_cache(); $this->assertFalse( WPDO_Hook_Bus_Bridge::is_enabled() ); } public function test_is_enabled_caches_result(): void { update_option( WPDO_Hook_Bus_Bridge::OPTION, '1' ); WPDO_Hook_Bus_Bridge::reset_cache(); $first = WPDO_Hook_Bus_Bridge::is_enabled(); // Mutate the option, but cache should retain previous value until reset. update_option( WPDO_Hook_Bus_Bridge::OPTION, '0' ); $second = WPDO_Hook_Bus_Bridge::is_enabled(); $this->assertSame( $first, $second, 'Cache must be sticky within a request' ); // After explicit reset → new value visible. WPDO_Hook_Bus_Bridge::reset_cache(); $this->assertFalse( WPDO_Hook_Bus_Bridge::is_enabled() ); } // ── maybe_init_hook_bus() ─────────────────────────────────────────────── public function test_maybe_init_hook_bus_noop_when_disabled(): void { // Disabled → must not throw even if WPDO_Hook_Bus class missing. WPDO_Hook_Bus_Bridge::maybe_init_hook_bus(); $this->assertTrue( true ); } // ── detect_intra_wpdo_conflicts() ─────────────────────────────────────── public function test_detect_intra_wpdo_conflicts_returns_empty_when_no_filters(): void { // Stub bootstrap doesn't populate $wp_filter, so result is empty array. $conflicts = WPDO_Hook_Bus_Bridge::detect_intra_wpdo_conflicts(); $this->assertIsArray( $conflicts ); $this->assertEmpty( $conflicts ); } public function test_detect_intra_wpdo_conflicts_flags_multiple_wpdo_callbacks(): void { // Simulate $wp_filter with two WPDO_* callbacks on the same hook. $GLOBALS['wp_filter'] = array( 'update_post_metadata' => new class() { public array $callbacks; public function __construct() { $this->callbacks = array( 10 => array( array( 'function' => array( new class() { public function intercept_update() {} }, 'intercept_update', ), ), ), 8 => array( array( 'function' => array( new class() { public function intercept_update() {} }, 'intercept_update', ), ), ), ); } }, ); // The anonymous classes won't have WPDO_ prefix → must not flag conflict. $conflicts = WPDO_Hook_Bus_Bridge::detect_intra_wpdo_conflicts(); $this->assertEmpty( $conflicts, 'Non-WPDO classes must not be flagged' ); } }