'shadow_read', 'user' => 'disabled', 'term' => 'disabled', 'comment' => 'disabled', ) ); } private static function set_modes( ?array $modes ): void { $cache = ( new ReflectionClass( WPDO_Mode_Manager::class ) )->getProperty( 'cache' ); $cache->setAccessible( true ); $cache->setValue( null, $modes ); } private function drift( string $group, int $diff ): void { $GLOBALS['_wp_options'][ TMDO_Drift_Check::OPTION ]['post'][ $group ] = array( 'miss' => 0, 'diff' => $diff, 'extra' => 0, 'sample' => 0, 'checked_at' => '2026-09-27 00:00:00', ); } private function price_query( array $extra = array() ): WP_Query { $query = new WP_Query(); foreach ( array( 'post_type' => 'product', 'meta_query' => array( array( 'key' => '_price', 'value' => '50', 'compare' => '>=', 'type' => 'NUMERIC' ), ), ) + $extra as $k => $v ) { $query->set( $k, $v ); } return $query; } public function test_a_drifting_group_keeps_the_query_native(): void { $this->drift( 'wc_product', 3 ); $query = $this->price_query(); $original = $query->get( 'meta_query' ); ( new WPDO_Post_Query_Router() )->pre_get_posts( $query ); $this->assertSame( $original, $query->get( 'meta_query' ) ); $this->assertSame( '', $query->get( 'wpdo_post_clauses' ) ); } public function test_a_clean_group_is_routed(): void { $this->drift( 'wc_product', 0 ); $query = $this->price_query(); ( new WPDO_Post_Query_Router() )->pre_get_posts( $query ); $this->assertNotEmpty( $query->get( 'wpdo_post_clauses' ) ); } public function test_a_group_never_checked_is_routed(): void { $query = $this->price_query(); ( new WPDO_Post_Query_Router() )->pre_get_posts( $query ); $this->assertNotEmpty( $query->get( 'wpdo_post_clauses' ) ); } public function test_drift_in_another_group_does_not_matter(): void { $this->drift( 'hp_listing_core', 5 ); $query = $this->price_query(); ( new WPDO_Post_Query_Router() )->pre_get_posts( $query ); $this->assertNotEmpty( $query->get( 'wpdo_post_clauses' ) ); } public function test_sorting_by_a_drifting_key_stays_native(): void { $this->drift( 'wc_product', 1 ); $query = new WP_Query(); $query->set( 'post_type', 'product' ); $query->set( 'meta_key', '_price' ); $query->set( 'orderby', 'meta_value_num' ); ( new WPDO_Post_Query_Router() )->pre_get_posts( $query ); $this->assertSame( '_price', $query->get( 'meta_key' ) ); $this->assertSame( '', $query->get( 'wpdo_post_sort' ) ); } }