diff --git a/includes/class-tmdo-hivepress-entity-groups.php b/includes/class-tmdo-hivepress-entity-groups.php index f0e5e58..798fba3 100644 --- a/includes/class-tmdo-hivepress-entity-groups.php +++ b/includes/class-tmdo-hivepress-entity-groups.php @@ -32,12 +32,22 @@ if ( ! defined( 'ABSPATH' ) ) { final class TMDO_HivePress_Entity_Groups { /** - * Hook into WPDO entity field registration. + * Hook into WPDO entity field registration and the REST default post type. * * @return void */ public static function register(): void { add_action( 'wpdo_register_entity_fields', array( __CLASS__, 'register_entity_fields' ) ); + add_filter( 'tmdo_rest_default_post_type', array( __CLASS__, 'rest_default_post_type' ) ); + } + + /** + * GET /wpdo/v1/listings serves HivePress listings when no post type is given. + * + * @return string + */ + public static function rest_default_post_type(): string { + return 'hp_listing'; } /** diff --git a/tests/unit/HivePressEntityGroupsTest.php b/tests/unit/HivePressEntityGroupsTest.php index 1273406..72fface 100644 --- a/tests/unit/HivePressEntityGroupsTest.php +++ b/tests/unit/HivePressEntityGroupsTest.php @@ -46,6 +46,7 @@ class HivePressEntityGroupsTest extends TestCase { protected function tearDown(): void { unset( $GLOBALS['_wp_options'][ TMDO_Entity_Registry::SCOPED_ROUTING_OPTION ] ); + unset( $GLOBALS['_wp_filter_callbacks']['tmdo_rest_default_post_type'] ); } public function test_definitions_match_persisted_schema_hashes(): void { @@ -74,6 +75,34 @@ class HivePressEntityGroupsTest extends TestCase { $this->assertNull( TMDO_Entity_Registry::get_field( 'post', 'hp_rating', 'post' ), 'HivePress keys stay native on other post types' ); } + public function test_reconciler_plans_the_eight_misrouted_hivepress_keys(): void { + $moves = array(); + foreach ( TMDO_Post_Group_Reconciler::plan() as $m ) { + $moves[] = "{$m['source']}>{$m['target']}:{$m['key']}"; + } + sort( $moves ); + + $this->assertSame( + array( + 'hp_request_core>hp_listing_core:hp_expired_time', + 'hp_request_core>hp_listing_core:hp_status', + 'hp_request_core>hp_listing_core:hp_view_count', + 'hp_vendor_core>hp_listing_core:hp_hourly_rate', + 'hp_vendor_core>hp_listing_core:hp_rating', + 'hp_vendor_core>hp_listing_core:hp_rating_count', + 'hp_vendor_core>hp_listing_core:hp_verified', + 'hp_vendor_core>hp_request_core:hp_user', + ), + $moves + ); + } + + public function test_rest_listings_default_to_hivepress_listings(): void { + TMDO_HivePress_Entity_Groups::register(); + + $this->assertSame( 'hp_listing', TMDO_REST_API::default_post_type() ); + } + public function test_core_adapter_does_not_register_a_conflicting_group(): void { ( new TMDO_HivePress_Core_Adapter() )->on_register_entity_fields();