0254e40d83
- ADR-003 step 4 (AddOn side): core, requests, bookings, memberships and marketplace adapters no longer register zone=hot fields or contribute hot_* FSM modules; their keys live in TMDO_HivePress_Entity_Groups. Cold/warm registrations are unchanged. - Hot-table doctor probes go with them (trait defaults apply). The hot-clause query rewrite and cron optimizer are now inert and are left for the ADR step-5 removal together with core's hot path. - New NoHotZoneRegistrationTest pins the invariant across all 13 adapters; per-adapter hot assertions removed. - Verify: HP unit 142 / integration 49 green, phpcs clean (WordPress) - PR: PR-037
120 lines
4.5 KiB
PHP
120 lines
4.5 KiB
PHP
<?php
|
|
declare(strict_types=1);
|
|
|
|
use PHPUnit\Framework\TestCase;
|
|
|
|
/**
|
|
* Tests for WPDO_HivePress_Core_Adapter — Listing / Vendor field registration.
|
|
*
|
|
* @covers WPDO_HivePress_Core_Adapter
|
|
*/
|
|
class HivePressCoreAdapterTest extends TestCase {
|
|
|
|
private WPDO_HivePress_Core_Adapter $adapter;
|
|
|
|
protected function setUp(): void {
|
|
// WPDO_Schema_Registry has no reset_for_tests() — use reflection to
|
|
// clear its singleton so each test starts with a fresh registry.
|
|
$reflect = new ReflectionClass( WPDO_Schema_Registry::class );
|
|
if ( $reflect->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_on_register_fields_populates_schema_registry(): void {
|
|
$registry = WPDO_Schema_Registry::instance();
|
|
$this->adapter->on_register_fields( $registry );
|
|
|
|
// 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_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' ) );
|
|
}
|
|
}
|