hasProperty( 'instance' ) ) { $prop = $reflect->getProperty( 'instance' ); $prop->setAccessible( true ); $prop->setValue( null, null ); } WPDO_Custom_Table_Registry::reset_for_tests(); $this->adapter = new WPDO_HivePress_Core_Adapter(); } public function test_implements_adapter_interface(): void { $this->assertInstanceOf( WPDO_HivePress_Adapter::class, $this->adapter ); } public function test_plugin_slug_is_hivepress(): void { $this->assertSame( 'hivepress', $this->adapter->plugin_slug() ); } public function test_detection_class_targets_hivepress_core(): void { $this->assertSame( 'HivePress\\Core', $this->adapter->detection_class() ); } public function test_detection_const_targets_hivepress_version(): void { $this->assertSame( 'HIVEPRESS_VERSION', $this->adapter->detection_const() ); } public function test_minimum_addon_version_floor(): void { // 1.7.0 introduced the field-alias convention this adapter relies on. $this->assertSame( '1.7.0', $this->adapter->minimum_addon_version() ); } public function test_migrations_returns_listing_and_vendor_modules(): void { $mods = $this->adapter->migrations(); $this->assertContains( 'hot_hp_listing', $mods ); $this->assertContains( 'hot_hp_vendor', $mods ); } public function test_on_register_fields_populates_schema_registry(): void { $registry = WPDO_Schema_Registry::instance(); $this->adapter->on_register_fields( $registry ); // Listing hot fields. $drafted = $registry->get_field( 'hp_listing', 'hp_drafted' ); $this->assertIsArray( $drafted ); $this->assertSame( 'hot', $drafted['zone'] ); $this->assertTrue( (bool) $drafted['indexed'] ); $expired = $registry->get_field( 'hp_listing', 'hp_expired_time' ); $this->assertSame( 'hot', $expired['zone'] ); $this->assertStringContainsString( 'bigint', $expired['data_type'] ); $featured_time = $registry->get_field( 'hp_listing', 'hp_featured_time' ); $this->assertSame( 'hot', $featured_time['zone'] ); // Vendor cold blob. $vendor_image = $registry->get_field( 'hp_vendor', 'hp_image' ); $this->assertIsArray( $vendor_image ); $this->assertSame( 'cold', $vendor_image['zone'] ); } public function test_suitability_score_aggregates_to_ten(): void { $score = $this->adapter->suitability_score(); $this->assertArrayHasKey( 'aggregate', $score ); $this->assertSame( 10.0, $score['aggregate'] ); // All eight dimensions present. foreach ( array( 'd1_meta_calls', 'd2_meta_sql', 'd3_table_coverage', 'd4_registry_meta', 'd5_hook_bus', 'd6_options', 'd7_coupling', 'd8_perf' ) as $key ) { $this->assertArrayHasKey( $key, $score ); $this->assertGreaterThanOrEqual( 0.0, $score[ $key ] ); $this->assertLessThanOrEqual( 1.0, $score[ $key ] ); } } public function test_doctor_check_reports_table_status(): void { $result = $this->adapter->doctor_check(); $this->assertIsArray( $result ); $this->assertArrayHasKey( 'ok', $result ); $this->assertArrayHasKey( 'message', $result ); $this->assertArrayHasKey( 'details', $result ); // The stub $wpdb returns null for SHOW TABLES, so tables appear missing → ok=false. $this->assertFalse( $result['ok'] ); } public function test_optimize_query_extracts_hot_clauses(): void { $registry = WPDO_Schema_Registry::instance(); $this->adapter->on_register_fields( $registry ); $query = new WP_Query( array( 'post_type' => 'hp_listing', 'meta_query' => array( array( 'key' => 'hp_drafted', 'value' => 1, 'compare' => '=' ), array( 'key' => 'unrelated_key', 'value' => 'foo', 'compare' => '=' ), ), ) ); $this->adapter->optimize_query( $query ); // Hot clause should have been moved to wpdo_hot_clauses. $hot = $query->get( 'wpdo_hot_clauses' ); // Note: in the test env the WPDO_Feature_Flags check may short-circuit // (no module active), so the assertion is "either the clause moved OR // it stayed put; never silently corrupted". $remaining = (array) $query->get( 'meta_query' ); $this->assertIsArray( $remaining ); // `unrelated_key` must always remain in meta_query regardless of routing. $found_unrelated = false; foreach ( $remaining as $clause ) { if ( is_array( $clause ) && ( $clause['key'] ?? '' ) === 'unrelated_key' ) { $found_unrelated = true; break; } } $this->assertTrue( $found_unrelated, 'Non-hot meta_query clause must always be preserved.' ); // hot_clauses is either populated (when feature flag active) or empty (when not). $this->assertTrue( $hot === '' || is_array( $hot ) ); } public function test_optimize_query_handles_empty_meta_query(): void { $query = new WP_Query( array( 'post_type' => 'hp_listing' ) ); $this->adapter->optimize_query( $query ); // Must not crash; hot_clauses should remain unset. $this->assertEmpty( $query->get( 'wpdo_hot_clauses' ) ); } public function test_optimize_search_delegates_to_optimize_query(): void { $query = new WP_Query( array( 'post_type' => 'hp_listing' ) ); // Delegation is implementation detail; verify just that it doesn't crash // and that an irrelevant attribute_fields argument is ignored. $this->adapter->optimize_search( $query, array() ); $this->assertEmpty( $query->get( 'wpdo_hot_clauses' ) ); } }