From 2b0ea4b62302eabdfc43d8eddd0ff8f923d86338 Mon Sep 17 00:00:00 2001 From: priethor <27339341+priethor@users.noreply.github.com> Date: Mon, 10 Nov 2025 16:44:54 +0100 Subject: [PATCH] Fix post type schema --- schemas/post-type.schema.json | 6 +-- tests/php/PostTypeSchemaTest.php | 72 ++++++++++++++++++++++++++++---- 2 files changed, 66 insertions(+), 12 deletions(-) diff --git a/schemas/post-type.schema.json b/schemas/post-type.schema.json index d9a4744a..ae0b3a1e 100644 --- a/schemas/post-type.schema.json +++ b/schemas/post-type.schema.json @@ -249,8 +249,8 @@ "description": "[SCF Export Only] The order of this post type in the admin menu" }, "menu_position": { - "type": ["integer", "string"], - "description": "The position in the menu order. SCF exports as empty string when not set, integer when set. Import accepts both and casts to integer." + "type": ["integer", "string", "null"], + "description": "The position in the menu order. SCF exports as empty string or null when not set, integer when set. Import accepts all types and casts to integer." }, "menu_icon": { "oneOf": [ @@ -300,7 +300,7 @@ "description": "Core feature(s) the post type supports. Common values: 'title', 'editor', 'author', 'thumbnail', 'excerpt', 'trackbacks', 'custom-fields', 'comments', 'revisions', 'page-attributes', 'post-formats'. Custom supports are also allowed." }, "taxonomies": { - "oneOf": [ + "anyOf": [ { "type": "array", "items": { "type": "string" }, diff --git a/tests/php/PostTypeSchemaTest.php b/tests/php/PostTypeSchemaTest.php index b95933dd..31eccd73 100644 --- a/tests/php/PostTypeSchemaTest.php +++ b/tests/php/PostTypeSchemaTest.php @@ -67,7 +67,7 @@ public function test_post_type_schema_loads() { */ public function validPostTypesProvider() { return array( - 'basic valid' => array( + 'basic valid' => array( array( 'key' => 'post_type_book', 'title' => 'Book', @@ -75,7 +75,7 @@ public function validPostTypesProvider() { ), 'Basic post type should validate successfully', ), - 'array with two items' => array( + 'array with two items' => array( array( array( 'key' => 'post_type_book', @@ -90,7 +90,7 @@ public function validPostTypesProvider() { ), 'Array of two post types should validate successfully', ), - 'with dashes' => array( + 'with dashes' => array( array( 'key' => 'post_type_my_product', 'title' => 'My Product', @@ -98,7 +98,7 @@ public function validPostTypesProvider() { ), 'Post type with dashes should be valid', ), - 'with underscores' => array( + 'with underscores' => array( array( 'key' => 'post_type_my_product', 'title' => 'My Product', @@ -106,7 +106,7 @@ public function validPostTypesProvider() { ), 'Post type with underscores should be valid', ), - 'with numbers' => array( + 'with numbers' => array( array( 'key' => 'post_type_product123', 'title' => 'Product', @@ -114,7 +114,7 @@ public function validPostTypesProvider() { ), 'Post type with numbers should be valid', ), - 'custom supports' => array( + 'custom supports' => array( array( 'key' => 'post_type_book', 'title' => 'Book', @@ -123,7 +123,7 @@ public function validPostTypesProvider() { ), 'Post type with custom supports should be valid', ), - 'rewrite false' => array( + 'rewrite false' => array( array( 'key' => 'post_type_book', 'title' => 'Book', @@ -132,7 +132,7 @@ public function validPostTypesProvider() { ), 'Post type with rewrite as false should validate', ), - 'rewrite object' => array( + 'rewrite object' => array( array( 'key' => 'post_type_book', 'title' => 'Book', @@ -146,7 +146,7 @@ public function validPostTypesProvider() { ), 'Post type with rewrite object should validate', ), - 'with capabilities' => array( + 'with capabilities' => array( array( 'key' => 'post_type_book', 'title' => 'Book', @@ -159,6 +159,60 @@ public function validPostTypesProvider() { ), 'Post type with valid capabilities should validate', ), + 'taxonomies empty array' => array( + array( + 'key' => 'post_type_test', + 'title' => 'Test', + 'post_type' => 'test', + 'taxonomies' => array(), + ), + 'Post type with empty taxonomies array should validate', + ), + 'taxonomies empty string' => array( + array( + 'key' => 'post_type_test', + 'title' => 'Test', + 'post_type' => 'test', + 'taxonomies' => '', + ), + 'Post type with empty taxonomies string should validate', + ), + 'taxonomies array with values' => array( + array( + 'key' => 'post_type_test', + 'title' => 'Test', + 'post_type' => 'test', + 'taxonomies' => array( 'category', 'post_tag' ), + ), + 'Post type with taxonomies array should validate', + ), + 'menu_position null' => array( + array( + 'key' => 'post_type_test', + 'title' => 'Test', + 'post_type' => 'test', + 'menu_position' => null, + ), + 'Post type with null menu_position should validate', + ), + 'menu_position empty string' => array( + array( + 'key' => 'post_type_test', + 'title' => 'Test', + 'post_type' => 'test', + 'menu_position' => '', + ), + 'Post type with empty string menu_position should validate', + ), + 'menu_position integer' => array( + array( + 'key' => 'post_type_test', + 'title' => 'Test', + 'post_type' => 'test', + 'menu_position' => 20, + ), + 'Post type with integer menu_position should validate', + ), ); }