refactor(2meet-data-optimizer-hivepress-addon): remove comment mirror writes to never-created tables

- Favorites/Messages adapters reduced to detection only; Requests keeps hot_hp_request fields, drops hp_offer mirror
- Delete TMDO_HivePress_Comment_Router (read path to wpdo_comment_hp_* tables that no installer creates)
- Verify: addon unit 141 OK, integration 52 OK; phpcs 41E/57W → 35E/48W
- PR: PR-013
This commit is contained in:
2026-09-25 22:58:34 +08:00
parent f089b0934b
commit 5777210184
17 changed files with 77 additions and 1108 deletions
+13 -61
View File
@@ -6,6 +6,9 @@ use PHPUnit\Framework\TestCase;
/**
* Tests for WPDO_HivePress_Messages_Adapter.
*
* The adapter no longer mirrors messages into a shadow table: that table was
* never created, so every mirror write failed.
*
* @covers WPDO_HivePress_Messages_Adapter
*/
class HivePressMessagesAdapterTest extends TestCase {
@@ -28,77 +31,26 @@ class HivePressMessagesAdapterTest extends TestCase {
$this->assertSame( 'hivepress-messages', $this->adapter->plugin_slug() );
$this->assertSame( 'HivePress\\Messages\\Plugin', $this->adapter->detection_class() );
$this->assertSame( 'hp_message', WPDO_HivePress_Messages_Adapter::COMMENT_TYPE );
$this->assertSame( 'wpdo_comment_hp_message', WPDO_HivePress_Messages_Adapter::TABLE );
}
public function test_on_register_custom_tables_declares_indexed_recipient(): void {
public function test_registers_no_shadow_table(): 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_message', $cfg['table_name'] );
$this->assertArrayHasKey( 'recipient_id', $cfg['expected_columns'] );
$this->assertArrayHasKey( 'idx_recipient_unread', $cfg['indexes'] );
$this->assertStringContainsString( 'recipient_id, is_read', $cfg['indexes']['idx_recipient_unread'] );
$this->assertSame( array(), $registry->all() );
}
public function test_mirror_insert_skips_non_message_comments(): void {
global $wpdb;
$wpdb->queries = array();
public function test_binds_no_comment_hooks(): void {
$GLOBALS['_wp_filter_callbacks'] = array();
$comment = new stdClass();
$comment->comment_type = 'comment';
$comment->user_id = 1;
$comment->comment_karma = 5;
$this->adapter->on_register_event_hooks();
$this->adapter->mirror_insert( 1, $comment );
$this->assertSame( array(), $wpdb->queries );
$this->assertArrayNotHasKey( 'wp_insert_comment', $GLOBALS['_wp_filter_callbacks'] );
$this->assertArrayNotHasKey( 'wp_set_comment_status', $GLOBALS['_wp_filter_callbacks'] );
$this->assertArrayNotHasKey( 'deleted_comment', $GLOBALS['_wp_filter_callbacks'] );
}
public function test_mirror_insert_promotes_recipient_from_comment_karma(): void {
global $wpdb;
$wpdb->queries = array();
$comment = new stdClass();
$comment->comment_type = 'hp_message';
$comment->user_id = 7; // sender
$comment->comment_karma = 42; // ← recipient hack lives here
$comment->comment_post_ID = 99;
$comment->comment_approved = 0;
$comment->comment_date = '2026-05-04 12:00:00';
$this->adapter->mirror_insert( 100, $comment );
$this->assertCount( 1, $wpdb->queries );
$sql = $wpdb->queries[0];
$this->assertStringContainsString( 'INSERT INTO', $sql );
$this->assertStringContainsString( 'wpdo_comment_hp_message', $sql );
// The promoted recipient_id should appear in the bound SQL.
$this->assertStringContainsString( '42', $sql );
}
public function test_mirror_insert_skips_when_sender_or_recipient_zero(): void {
global $wpdb;
$wpdb->queries = array();
$comment = new stdClass();
$comment->comment_type = 'hp_message';
$comment->user_id = 0; // bad sender
$comment->comment_karma = 42;
$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_message', $result['message'] );
}
public function test_score_aggregates_to_perfect_ten(): void {
$this->assertSame( 10.0, $this->adapter->suitability_score()['aggregate'] );
public function test_migrations_is_empty(): void {
$this->assertSame( array(), $this->adapter->migrations() );
}
}