diff --git a/includes/class-tmdo-hivepress-entity-groups.php b/includes/class-tmdo-hivepress-entity-groups.php index 42a78f8..6dc4071 100644 --- a/includes/class-tmdo-hivepress-entity-groups.php +++ b/includes/class-tmdo-hivepress-entity-groups.php @@ -266,8 +266,13 @@ final class TMDO_HivePress_Entity_Groups { // Only with core 1.3.0+ (ddl_allowed()): older cores run the ALTER // inside whatever request comes first, a visitor's included. 'indexes' => method_exists( 'TMDO_Schema_Manager', 'ddl_allowed' ) ? array( - 'hourly_rate' => array( 'hp_hourly_rate' ), - 'rating_count' => array( 'hp_rating_count' ), + 'hourly_rate' => array( 'hp_hourly_rate' ), + 'rating_count' => array( 'hp_rating_count' ), + // HivePress sorts: the value then the ID tie-break, which core 1.4.0 + // reads in order (flat-first) instead of sorting every match. + 'price_id' => array( 'hp_price', 'post_id' ), + 'rating_id' => array( 'hp_rating', 'post_id' ), + 'hourly_rate_id' => array( 'hp_hourly_rate', 'post_id' ), ) : array(), ) ); diff --git a/tests/unit/HivePressEntityGroupsTest.php b/tests/unit/HivePressEntityGroupsTest.php index e004493..2dffdc4 100644 --- a/tests/unit/HivePressEntityGroupsTest.php +++ b/tests/unit/HivePressEntityGroupsTest.php @@ -37,9 +37,15 @@ class HivePressEntityGroupsTest extends TestCase { 'hp_user' => 'hp_vendor_core', ); + private function post_adapter(): TMDO_Entity_Adapter_Interface { + $adapter = $this->createMock( TMDO_Entity_Adapter_Interface::class ); + $adapter->method( 'get_entity_id_column' )->willReturn( 'post_id' ); + return $adapter; + } + protected function setUp(): void { TMDO_Entity_Registry::init(); - TMDO_Entity_Registry::register_adapter( 'post', $this->createMock( TMDO_Entity_Adapter_Interface::class ) ); + TMDO_Entity_Registry::register_adapter( 'post', $this->post_adapter() ); TMDO_Entity_Registry::register_adapter( 'user', $this->createMock( TMDO_Entity_Adapter_Interface::class ) ); TMDO_HivePress_Entity_Groups::register_entity_fields(); } @@ -66,8 +72,12 @@ class HivePressEntityGroupsTest extends TestCase { public function test_listing_columns_filtered_and_sorted_on_are_indexed(): void { $this->assertSame( array( - 'hourly_rate' => array( 'hp_hourly_rate' ), - 'rating_count' => array( 'hp_rating_count' ), + 'hourly_rate' => array( 'hp_hourly_rate' ), + 'rating_count' => array( 'hp_rating_count' ), + // Sorts: the value then the ID tie-break, read in order (2.4 PR-119). + 'price_id' => array( 'hp_price', 'post_id' ), + 'rating_id' => array( 'hp_rating', 'post_id' ), + 'hourly_rate_id' => array( 'hp_hourly_rate', 'post_id' ), ), TMDO_Entity_Registry::get_group_indexes( 'post', 'hp_listing_core' ) ); @@ -94,7 +104,7 @@ class HivePressEntityGroupsTest extends TestCase { $GLOBALS['_wp_did_action']['after_setup_theme'] = 1; try { TMDO_Entity_Registry::init(); - TMDO_Entity_Registry::register_adapter( 'post', $this->createMock( TMDO_Entity_Adapter_Interface::class ) ); + TMDO_Entity_Registry::register_adapter( 'post', $this->post_adapter() ); TMDO_Entity_Registry::register_adapter( 'user', $this->createMock( TMDO_Entity_Adapter_Interface::class ) ); TMDO_HivePress_Entity_Groups::register_entity_fields(); } finally { @@ -118,7 +128,7 @@ class HivePressEntityGroupsTest extends TestCase { add_filter( 'tmdo_hp_listing_attribute_fields', static fn() => array( 'hp_warranty' => 'integer' ) ); try { TMDO_Entity_Registry::init(); - TMDO_Entity_Registry::register_adapter( 'post', $this->createMock( TMDO_Entity_Adapter_Interface::class ) ); + TMDO_Entity_Registry::register_adapter( 'post', $this->post_adapter() ); TMDO_Entity_Registry::register_adapter( 'user', $this->createMock( TMDO_Entity_Adapter_Interface::class ) ); TMDO_HivePress_Entity_Groups::register_entity_fields(); $this->assertSame( array(), TMDO_Entity_Registry::get_group_keys( 'post', 'hp_listing_attrs' ), 'plugins_loaded run: not yet' );