assertTrue( true ); } public function test_the_core_groups_are_registered(): void { WPDO_Post_Fields::register_entity_fields(); $expected = array( 'wp_core', 'attachment', 'nav_menu_item', ); foreach ( $expected as $group ) { $fields = WPDO_Entity_Registry::get_group_fields( 'post', $group ); $this->assertNotEmpty( $fields, "Group '{$group}' should have registered fields." ); } } public function test_user_entity_groups_are_not_touched(): void { // 🔒 Frozen contract: post fields registration must not register // any group under entity_type='user'. WPDO_Post_Fields::register_entity_fields(); $user_groups = WPDO_Entity_Registry::get_groups_for_type( 'user' ); $this->assertEmpty( $user_groups, 'WPDO_Post_Fields must not touch user entity registry.' ); } // ── wp_core group (cross post_type) ────────────────────────────────────── public function test_wp_core_group_has_expected_keys(): void { WPDO_Post_Fields::register_entity_fields(); $keys = $this->get_field_keys( 'wp_core' ); $this->assertContains( '_thumbnail_id', $keys ); $this->assertContains( '_wp_page_template', $keys ); $this->assertContains( '_edit_last', $keys ); } public function test_wp_core_thumbnail_is_searchable(): void { WPDO_Post_Fields::register_entity_fields(); $field = $this->find_field( 'wp_core', '_thumbnail_id' ); $this->assertNotNull( $field ); $this->assertSame( 'integer', $field['type'] ); $this->assertTrue( (bool) ( $field['searchable'] ?? false ) ); } // ── attachment group ───────────────────────────────────────────────────── public function test_attachment_group_has_expected_keys(): void { WPDO_Post_Fields::register_entity_fields(); $keys = $this->get_field_keys( 'attachment' ); $this->assertContains( '_wp_attached_file', $keys ); $this->assertContains( '_wp_attachment_metadata', $keys ); $this->assertContains( '_wp_attachment_image_alt', $keys ); } public function test_attachment_metadata_is_json_type(): void { WPDO_Post_Fields::register_entity_fields(); $field = $this->find_field( 'attachment', '_wp_attachment_metadata' ); $this->assertNotNull( $field ); $this->assertSame( 'json', $field['type'] ); } // ── WooCommerce products stay in native meta (2.2 PR-077) ─────────────── public function test_core_registers_no_woocommerce_product_group(): void { WPDO_Post_Fields::register_entity_fields(); $this->assertSame( array(), WPDO_Entity_Registry::get_group_fields( 'post', 'wc_product' ), 'WooCommerce reads and writes product meta directly (stock by SQL)' ); $this->assertNull( WPDO_Entity_Registry::get_field( 'post', '_price', 'product' ) ); $this->assertSame( array(), WPDO_Post_Fields::groups_for_post_type( 'product' ) ); } // ── HivePress groups moved to the HivePress AddOn ─────────────────────── public function test_core_registers_no_hivepress_groups(): void { WPDO_Post_Fields::register_entity_fields(); foreach ( array( 'hp_listing_core', 'hp_request_core', 'hp_vendor_core' ) as $group ) { $this->assertSame( array(), WPDO_Entity_Registry::get_group_fields( 'post', $group ), "{$group} is owned by the HivePress AddOn" ); } } // ── group ↔ post_type mapping ──────────────────────────────────────────── public function test_core_groups_map_to_their_post_types(): void { $this->assertSame( 'attachment', WPDO_Post_Fields::post_type_for_group( 'attachment' ) ); $this->assertSame( 'nav_menu_item', WPDO_Post_Fields::post_type_for_group( 'nav_menu_item' ) ); $this->assertNull( WPDO_Post_Fields::post_type_for_group( 'wp_core' ), 'wp_core spans every post type' ); } public function test_scoped_groups_map_through_the_registry(): void { WPDO_Entity_Registry::register_group( 'post', 'x_core', array( array( 'key' => 'x_price', 'type' => 'decimal' ) ), array( 'post_types' => array( 'x_type' ) ) ); $this->assertSame( 'x_type', WPDO_Post_Fields::post_type_for_group( 'x_core' ) ); $this->assertSame( array( 'x_core' ), WPDO_Post_Fields::groups_for_post_type( 'x_type' ) ); $this->assertNull( WPDO_Post_Fields::post_type_for_group( 'hp_listing_core' ), 'unregistered HivePress group is unknown to core' ); } // ── nav_menu_item group ────────────────────────────────────────────────── public function test_nav_menu_item_has_8_keys(): void { WPDO_Post_Fields::register_entity_fields(); $keys = $this->get_field_keys( 'nav_menu_item' ); $this->assertCount( 8, $keys ); $this->assertContains( '_menu_item_type', $keys ); $this->assertContains( '_menu_item_object_id', $keys ); $this->assertContains( '_menu_item_url', $keys ); } // ── Helpers ────────────────────────────────────────────────────────────── /** @return string[] */ private function get_field_keys( string $group ): array { $fields = WPDO_Entity_Registry::get_group_fields( 'post', $group ); return array_map( static fn( $f ) => $f['key'], $fields ); } private function find_field( string $group, string $key ): ?array { $fields = WPDO_Entity_Registry::get_group_fields( 'post', $group ); foreach ( $fields as $f ) { if ( ( $f['key'] ?? '' ) === $key ) { return $f; } } return null; } }