fix(2meet-data-optimizer-hivepress-addon): let transient timeouts outlive their values; register site attributes once themes load
- review F5: a timeout entry expired before its value (a day vs a week), and HivePress reads a missing timeout as "never expires", serving the stale value for up to six more days. The timeout now expires a minute after the later of MAX_CACHE_TTL and its own time, so HivePress sees it expire first - review F7: site attributes accept only types with a plain index (json and binary would fail the CREATE TABLE) - review F8: the hp_listing_attrs group is registered on the run after after_setup_theme (init:1), so a filter added in a theme counts and the group has one definition per request; only keys of other groups are skipped - Verify: TTL test, attribute group tests, unit 148, integration 53, phpcs - PR: PR-115 (2.3 acceptance correctness review)
This commit is contained in:
@@ -88,8 +88,10 @@ class HivePressEntityGroupsTest extends TestCase {
|
||||
'hp_price' => 'decimal', // Already in hp_listing_core.
|
||||
'warranty' => 'integer', // Not a HivePress key.
|
||||
'hp_color' => 'colour', // Unknown type.
|
||||
'hp_features' => 'json', // No plain index on LONGTEXT.
|
||||
);
|
||||
add_filter( 'tmdo_hp_listing_attribute_fields', $fields );
|
||||
$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 ) );
|
||||
@@ -97,6 +99,7 @@ class HivePressEntityGroupsTest extends TestCase {
|
||||
TMDO_HivePress_Entity_Groups::register_entity_fields();
|
||||
} finally {
|
||||
$GLOBALS['_wp_filter_callbacks']['tmdo_hp_listing_attribute_fields'] = array();
|
||||
unset( $GLOBALS['_wp_did_action'] );
|
||||
}
|
||||
|
||||
$this->assertSame( array( 'hp_warranty' ), TMDO_Entity_Registry::get_group_keys( 'post', 'hp_listing_attrs' ) );
|
||||
@@ -106,6 +109,31 @@ class HivePressEntityGroupsTest extends TestCase {
|
||||
$this->test_definitions_match_persisted_schema_hashes();
|
||||
}
|
||||
|
||||
/**
|
||||
* Registration runs twice (plugins_loaded, then init:1): the group is
|
||||
* registered on the run after themes load, so a theme's filter counts and
|
||||
* a filter that changed between runs cannot collide (review F8).
|
||||
*/
|
||||
public function test_site_listing_attributes_are_registered_once_themes_are_loaded(): void {
|
||||
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( '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' );
|
||||
|
||||
$GLOBALS['_wp_did_action']['after_setup_theme'] = 1;
|
||||
TMDO_HivePress_Entity_Groups::register_entity_fields();
|
||||
} finally {
|
||||
$GLOBALS['_wp_filter_callbacks']['tmdo_hp_listing_attribute_fields'] = array();
|
||||
unset( $GLOBALS['_wp_did_action'] );
|
||||
}
|
||||
|
||||
$this->assertSame( array( 'hp_warranty' ), TMDO_Entity_Registry::get_group_keys( 'post', 'hp_listing_attrs' ) );
|
||||
$this->assertSame( array(), TMDO_Entity_Registry::get_collisions() );
|
||||
}
|
||||
|
||||
public function test_shared_keys_keep_their_current_owner(): void {
|
||||
foreach ( self::SHARED_KEY_OWNERS as $key => $group ) {
|
||||
$this->assertSame( $group, TMDO_Entity_Registry::get_field( 'post', $key )['group'], $key );
|
||||
|
||||
Reference in New Issue
Block a user