install_wpdb_mock(); $reflect = new ReflectionClass( WPDO_Schema_Registry::class ); $prop = $reflect->getProperty( 'instance' ); $prop->setAccessible( true ); $prop->setValue( null, null ); WPDO_Custom_Table_Registry::reset_for_tests(); $this->adapter = new WPDO_HivePress_Requests_Adapter(); } public function test_implements_adapter_interface(): void { $this->assertInstanceOf( WPDO_HivePress_Adapter::class, $this->adapter ); } public function test_identity(): void { $this->assertSame( 'hivepress-requests', $this->adapter->plugin_slug() ); $this->assertSame( 'HivePress\\Requests\\Plugin', $this->adapter->detection_class() ); $this->assertSame( 'hp_offer', WPDO_HivePress_Requests_Adapter::OFFER_COMMENT_TYPE ); } public function test_on_register_fields_registers_request_hot_columns(): void { $registry = WPDO_Schema_Registry::instance(); $this->adapter->on_register_fields( $registry ); $drafted = $registry->get_field( 'hp_request', 'hp_drafted' ); $this->assertSame( 'hot', $drafted['zone'] ); $this->assertTrue( (bool) $drafted['indexed'] ); $expired = $registry->get_field( 'hp_request', 'hp_expired_time' ); $this->assertSame( 'hot', $expired['zone'] ); $this->assertTrue( (bool) $expired['indexed'] ); } public function test_on_register_custom_tables_declares_offer_shadow(): void { $registry = WPDO_Custom_Table_Registry::instance(); $this->adapter->on_register_custom_tables( $registry ); $tables = $registry->all(); $cfg = reset( $tables ); $this->assertSame( 'wpdo_comment_hp_offer', $cfg['table_name'] ); $this->assertSame( 'hp_request', $cfg['post_type_link'] ); $this->assertArrayHasKey( 'idx_request_approved', $cfg['indexes'] ); } public function test_mirror_offer_insert_skips_other_comment_types(): void { global $wpdb; $wpdb->queries = array(); $comment = new stdClass(); $comment->comment_type = 'comment'; // ← not hp_offer $comment->comment_post_ID = 99; $comment->user_id = 1; $this->adapter->mirror_offer_insert( 1, $comment ); $this->assertSame( array(), $wpdb->queries ); } public function test_mirror_offer_insert_writes_for_hp_offer(): void { global $wpdb; $wpdb->queries = array(); $comment = new stdClass(); $comment->comment_type = 'hp_offer'; $comment->comment_post_ID = 42; $comment->user_id = 7; $comment->comment_approved = 0; $comment->comment_date = '2026-05-04 12:00:00'; $this->adapter->mirror_offer_insert( 100, $comment ); $this->assertCount( 1, $wpdb->queries ); $this->assertStringContainsString( 'INSERT INTO', $wpdb->queries[0] ); $this->assertStringContainsString( 'wpdo_comment_hp_offer', $wpdb->queries[0] ); } public function test_score_aggregates_to_perfect_ten(): void { $this->assertSame( 10.0, $this->adapter->suitability_score()['aggregate'] ); } public function test_migrations_lists_request_and_offer_modules(): void { $mods = $this->adapter->migrations(); $this->assertContains( 'hot_hp_request', $mods ); $this->assertContains( 'comment_hp_offer', $mods ); } }