install_wpdb_mock(); WPDO_Custom_Table_Registry::reset_for_tests(); $this->adapter = new WPDO_HivePress_Favorites_Adapter(); } public function test_implements_adapter_interface(): void { $this->assertInstanceOf( WPDO_HivePress_Adapter::class, $this->adapter ); } public function test_identity(): void { $this->assertSame( 'hivepress-favorites', $this->adapter->plugin_slug() ); $this->assertSame( 'HivePress\\Favorites\\Plugin', $this->adapter->detection_class() ); $this->assertSame( 'HIVEPRESS_FAVORITES_VERSION', $this->adapter->detection_const() ); } public function test_constants_exposed(): void { $this->assertSame( 'hp_favorite', WPDO_HivePress_Favorites_Adapter::COMMENT_TYPE ); $this->assertSame( 'wpdo_comment_hp_favorite', WPDO_HivePress_Favorites_Adapter::TABLE ); } public function test_on_register_custom_tables_declares_shadow_table(): void { $registry = WPDO_Custom_Table_Registry::instance(); $this->adapter->on_register_custom_tables( $registry ); $tables = $registry->all(); $this->assertCount( 1, $tables ); $cfg = reset( $tables ); $this->assertSame( 'hivepress-favorites', $cfg['provider'] ); $this->assertSame( 'wpdo_comment_hp_favorite', $cfg['table_name'] ); $this->assertSame( 'comment_id', $cfg['primary_key'] ); $this->assertArrayHasKey( 'unique_user_listing', $cfg['indexes'] ); $this->assertStringContainsString( 'UNIQUE', $cfg['indexes']['unique_user_listing'] ); } public function test_mirror_insert_skips_non_favorite_comments(): void { // Stub $wpdb tracks queries. global $wpdb; $wpdb->queries = array(); $comment = new stdClass(); $comment->comment_type = 'comment'; // ← not hp_favorite $comment->user_id = 1; $comment->comment_post_ID = 99; $this->adapter->mirror_insert( 123, $comment ); $this->assertSame( array(), $wpdb->queries ); } public function test_mirror_insert_writes_for_hp_favorite(): void { global $wpdb; $wpdb->queries = array(); $comment = new stdClass(); $comment->comment_type = 'hp_favorite'; $comment->user_id = 7; $comment->comment_post_ID = 42; $comment->comment_date = '2026-05-04 12:00:00'; $this->adapter->mirror_insert( 100, $comment ); $this->assertCount( 1, $wpdb->queries ); $this->assertStringContainsString( 'INSERT IGNORE', $wpdb->queries[0] ); $this->assertStringContainsString( 'wpdo_comment_hp_favorite', $wpdb->queries[0] ); } public function test_mirror_insert_skips_when_user_or_listing_missing(): void { global $wpdb; $wpdb->queries = array(); $comment = new stdClass(); $comment->comment_type = 'hp_favorite'; $comment->user_id = 0; $comment->comment_post_ID = 99; $this->adapter->mirror_insert( 100, $comment ); $this->assertSame( array(), $wpdb->queries ); } public function test_doctor_check_reports_missing_table_in_stub_env(): void { $result = $this->adapter->doctor_check(); $this->assertFalse( $result['ok'] ); $this->assertStringContainsString( 'wpdo_comment_hp_favorite', $result['message'] ); } public function test_score_aggregates_to_perfect_ten(): void { $score = $this->adapter->suitability_score(); $this->assertSame( 10.0, $score['aggregate'] ); } public function test_migrations_lists_comment_module(): void { $this->assertSame( array( 'comment_hp_favorite' ), $this->adapter->migrations() ); } }