refactor(2meet-data-optimizer-hivepress-addon): take ownership of hp_* entity groups
- Add TMDO_HivePress_Entity_Groups registering hp_listing_core / hp_request_core / hp_vendor_core / hp_user, copied verbatim from core (same order; schema hashes match the persisted wpdo_registry_meta rows) - Drop the core adapter's conflicting hp_user definition (hp_verified / hp_avatar_id — keys HivePress never writes) - Verify: HivePressEntityGroupsTest (identical to core, same shared-key resolution, no collisions); HP unit 144 / integration 49 OK; hashes = dev20 registry_meta - PR: PR-019
This commit is contained in:
@@ -45,6 +45,7 @@ $tmdo_hp_files = array(
|
||||
'includes/hivepress/class-tmdo-hivepress-rest.php',
|
||||
'includes/class-tmdo-hivepress-transient-filter.php',
|
||||
'includes/class-tmdo-hivepress-term-comment-fields.php',
|
||||
'includes/class-tmdo-hivepress-entity-groups.php',
|
||||
'includes/class-tmdo-hpct-import.php',
|
||||
'includes/class-tmdo-listing-stats.php',
|
||||
'admin/class-tmdo-admin-hivepress.php',
|
||||
|
||||
@@ -44,6 +44,7 @@ $tmdo_hp_files = array(
|
||||
'includes/hivepress/class-tmdo-hivepress-rest.php',
|
||||
'includes/class-tmdo-hivepress-transient-filter.php',
|
||||
'includes/class-tmdo-hivepress-term-comment-fields.php',
|
||||
'includes/class-tmdo-hivepress-entity-groups.php',
|
||||
'includes/class-tmdo-hpct-import.php',
|
||||
'admin/class-tmdo-admin-hivepress.php',
|
||||
'cli/class-tmdo-cli-hivepress.php',
|
||||
|
||||
@@ -0,0 +1,82 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
/**
|
||||
* The AddOn owns the HivePress entity groups core used to register.
|
||||
*
|
||||
* Their definitions are persisted (wpdo_registry_meta schema hash) and the
|
||||
* flat tables on live sites were built from core's version, so the AddOn must
|
||||
* register byte-identical definitions: any drift changes the schema hash and
|
||||
* would ALTER tables that hold aeav_only data once core stops registering
|
||||
* them (PR-020).
|
||||
*/
|
||||
class HivePressEntityGroupsTest extends TestCase {
|
||||
|
||||
private const GROUPS = array(
|
||||
array( 'post', 'hp_listing_core' ),
|
||||
array( 'post', 'hp_request_core' ),
|
||||
array( 'post', 'hp_vendor_core' ),
|
||||
array( 'user', 'hp_user' ),
|
||||
);
|
||||
|
||||
private function fresh_registry(): void {
|
||||
TMDO_Entity_Registry::init();
|
||||
TMDO_Entity_Registry::register_adapter( 'post', $this->createMock( TMDO_Entity_Adapter_Interface::class ) );
|
||||
TMDO_Entity_Registry::register_adapter( 'user', $this->createMock( TMDO_Entity_Adapter_Interface::class ) );
|
||||
}
|
||||
|
||||
private function register_core(): void {
|
||||
TMDO_Post_Fields::register_entity_fields();
|
||||
TMDO_Member_Fields::register_entity_fields();
|
||||
}
|
||||
|
||||
public function test_definitions_match_core_exactly(): void {
|
||||
$this->fresh_registry();
|
||||
$this->register_core();
|
||||
$core = array();
|
||||
foreach ( self::GROUPS as $g ) {
|
||||
$core[ $g[1] ] = TMDO_Entity_Registry::get_group_fields( $g[0], $g[1] );
|
||||
}
|
||||
|
||||
$this->fresh_registry();
|
||||
TMDO_HivePress_Entity_Groups::register_entity_fields();
|
||||
|
||||
foreach ( self::GROUPS as $g ) {
|
||||
$this->assertNotEmpty( $core[ $g[1] ], "core no longer registers {$g[1]}" );
|
||||
$this->assertSame( $core[ $g[1] ], TMDO_Entity_Registry::get_group_fields( $g[0], $g[1] ), "{$g[0]}/{$g[1]} drifted from core" );
|
||||
}
|
||||
}
|
||||
|
||||
public function test_shared_keys_resolve_to_the_same_group_as_core(): void {
|
||||
// hp_status / hp_user / hp_view_count … appear in several post groups and
|
||||
// field_index is last-registered-wins, so registration order matters.
|
||||
$this->fresh_registry();
|
||||
$this->register_core();
|
||||
$core = array();
|
||||
foreach ( self::GROUPS as $g ) {
|
||||
foreach ( TMDO_Entity_Registry::get_group_keys( $g[0], $g[1] ) as $key ) {
|
||||
$core[ $g[0] . ':' . $key ] = TMDO_Entity_Registry::get_field( $g[0], $key )['group'];
|
||||
}
|
||||
}
|
||||
|
||||
$this->fresh_registry();
|
||||
TMDO_HivePress_Entity_Groups::register_entity_fields();
|
||||
|
||||
foreach ( $core as $id => $group ) {
|
||||
list( $type, $key ) = explode( ':', $id, 2 );
|
||||
$this->assertSame( $group, TMDO_Entity_Registry::get_field( $type, $key )['group'], $id );
|
||||
}
|
||||
}
|
||||
|
||||
public function test_registering_alongside_core_raises_no_collision(): void {
|
||||
$this->fresh_registry();
|
||||
$this->register_core();
|
||||
|
||||
TMDO_HivePress_Entity_Groups::register_entity_fields();
|
||||
( new TMDO_HivePress_Core_Adapter() )->on_register_entity_fields();
|
||||
|
||||
$this->assertSame( array(), TMDO_Entity_Registry::get_collisions() );
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user