createMock( TMDO_Entity_Adapter_Interface::class ) ); $GLOBALS['_wp_options'] = array( TMDO_Entity_Registry::SCOPED_ROUTING_OPTION => '1' ); TMDO_Entity_Registry::register_group( 'post', 'site_core', array( array( 'key' => '_edit_lock', 'type' => 'text' ) ) ); TMDO_Entity_Registry::register_group( 'post', 'listing_core', array( array( 'key' => 'rating', 'type' => 'decimal' ), array( 'key' => 'price', 'type' => 'decimal' ), ), array( 'post_types' => array( 'hp_listing' ) ) ); TMDO_Entity_Registry::register_group( 'post', 'vendor_core', array( array( 'key' => 'rating', 'type' => 'decimal' ) ), array( 'post_types' => array( 'hp_vendor' ) ) ); } public function test_shared_key_resolves_to_the_group_of_the_post_type(): void { $this->assertSame( 'listing_core', TMDO_Entity_Registry::get_field( 'post', 'rating', 'hp_listing' )['group'] ); $this->assertSame( 'vendor_core', TMDO_Entity_Registry::get_field( 'post', 'rating', 'hp_vendor' )['group'] ); } public function test_scoped_key_is_unmanaged_for_other_post_types(): void { $this->assertNull( TMDO_Entity_Registry::get_field( 'post', 'rating', 'post' ) ); $this->assertNull( TMDO_Entity_Registry::get_field( 'post', 'price', 'hp_vendor' ) ); } public function test_unscoped_group_applies_to_every_post_type(): void { $this->assertSame( 'site_core', TMDO_Entity_Registry::get_field( 'post', '_edit_lock', 'hp_listing' )['group'] ); $this->assertSame( 'site_core', TMDO_Entity_Registry::get_field( 'post', '_edit_lock', 'page' )['group'] ); } public function test_lookup_without_post_type_keeps_legacy_last_wins(): void { $this->assertSame( 'vendor_core', TMDO_Entity_Registry::get_field( 'post', 'rating' )['group'] ); } public function test_scoping_is_off_until_the_option_enables_it(): void { $GLOBALS['_wp_options'][ TMDO_Entity_Registry::SCOPED_ROUTING_OPTION ] = '0'; $this->assertSame( 'vendor_core', TMDO_Entity_Registry::get_field( 'post', 'rating', 'hp_listing' )['group'] ); $this->assertSame( 'listing_core', TMDO_Entity_Registry::get_field( 'post', 'price', 'hp_vendor' )['group'] ); } public function test_scope_is_not_part_of_the_field_definition(): void { // Keeps schema hashes and PR-017 collision checks unchanged. $fields = TMDO_Entity_Registry::get_group_fields( 'post', 'vendor_core' ); $this->assertArrayNotHasKey( 'post_types', $fields[0] ); } public function test_scoped_routing_default_waits_for_reconcile_on_sites_with_post_flat_data(): void { // Existing flat rows may sit in the wrong group table (legacy routing); // switching lookups before they are reconciled would hide them. $this->assertSame( '0', TMDO_Installer::post_scoped_routing_default( 'aeav_only', true ) ); $this->assertSame( '0', TMDO_Installer::post_scoped_routing_default( 'dual_write', true ) ); $this->assertSame( '1', TMDO_Installer::post_scoped_routing_default( 'aeav_only', false ) ); $this->assertSame( '1', TMDO_Installer::post_scoped_routing_default( 'disabled', true ) ); } }