assertTrue( true ); } public function test_all_seven_groups_are_registered(): void { WPDO_Post_Fields::register_entity_fields(); $expected = array( 'wp_core', 'attachment', 'wc_product', 'hp_listing_core', 'hp_request_core', 'hp_vendor_core', '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'] ); } // ── wc_product group ───────────────────────────────────────────────────── public function test_wc_product_group_has_19_keys(): void { WPDO_Post_Fields::register_entity_fields(); $keys = $this->get_field_keys( 'wc_product' ); $this->assertCount( 19, $keys, 'wc_product group should register exactly 19 keys.' ); } public function test_wc_product_critical_keys_present(): void { WPDO_Post_Fields::register_entity_fields(); $keys = $this->get_field_keys( 'wc_product' ); foreach ( array( '_price', '_regular_price', '_sale_price', '_stock', '_stock_status', '_sku' ) as $key ) { $this->assertContains( $key, $keys, "wc_product missing critical key: {$key}" ); } } public function test_wc_product_price_is_searchable_decimal(): void { WPDO_Post_Fields::register_entity_fields(); $field = $this->find_field( 'wc_product', '_price' ); $this->assertNotNull( $field ); $this->assertSame( 'decimal', $field['type'] ); $this->assertTrue( (bool) ( $field['searchable'] ?? false ) ); } public function test_wc_product_stock_status_is_enum_searchable(): void { WPDO_Post_Fields::register_entity_fields(); $field = $this->find_field( 'wc_product', '_stock_status' ); $this->assertNotNull( $field ); $this->assertSame( 'enum', $field['type'] ); $this->assertTrue( (bool) ( $field['searchable'] ?? false ) ); $this->assertContains( 'instock', $field['options'] ); $this->assertContains( 'outofstock', $field['options'] ); } // ── hp_listing_core group ──────────────────────────────────────────────── public function test_hp_listing_core_critical_keys_present(): void { WPDO_Post_Fields::register_entity_fields(); $keys = $this->get_field_keys( 'hp_listing_core' ); foreach ( array( 'hp_price', 'hp_status', 'hp_featured', 'hp_verified', 'hp_vendor' ) as $key ) { $this->assertContains( $key, $keys, "hp_listing_core missing critical key: {$key}" ); } } public function test_hp_listing_price_is_searchable_decimal(): void { WPDO_Post_Fields::register_entity_fields(); $field = $this->find_field( 'hp_listing_core', 'hp_price' ); $this->assertNotNull( $field ); $this->assertSame( 'decimal', $field['type'] ); $this->assertTrue( (bool) ( $field['searchable'] ?? false ) ); } // ── 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; } }