Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ class PostTypesEndpointTest {
val postTypesPost = client.request { requestBuilder ->
requestBuilder.postTypes().retrieveWithEditContext(PostType.Post)
}.assertSuccessAndRetrieveData().data
assert(postTypesPost.supports[PostTypeSupports.Title]!!)
assert(postTypesPost.supports.map[PostTypeSupports.Title]!!)
assertFalse(postTypesPost.capabilities[PostTypeCapabilities.EditPosts]!!.isEmpty())
}

Expand All @@ -35,7 +35,7 @@ class PostTypesEndpointTest {
val postTypesPost = client.request { requestBuilder ->
requestBuilder.postTypes().retrieveWithEditContext(PostType.WpFontFace)
}.assertSuccessAndRetrieveData().data
assertNull(postTypesPost.supports[PostTypeSupports.Author])
assertNull(postTypesPost.supports.map[PostTypeSupports.Author])
}

@Test
Expand Down
2 changes: 1 addition & 1 deletion native/swift/Example/Example/ExampleApp.swift
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ struct ExampleApp: App {
.postTypes
.map(\.value)
.filter { $0.visibility.showInNavMenus }
.filter { $0.supports.keys.contains(allOf: [.title, .author, .customFields]) }
.filter { $0.supports.map.keys.contains(allOf: [.title, .author, .customFields]) }

for type in postTypes {
baseData.append(RootListData(name: type.name, sequence: {
Expand Down
4 changes: 3 additions & 1 deletion scripts/setup-test-site.sh
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,9 @@ wp import /tmp/testdata.xml --authors=create
wp plugin deactivate wordpress-importer
wp plugin delete wordpress-importer

wp plugin install gutenberg --activate
curl -sSL https://downloads.wordpress.org/plugin/gutenberg.21.7.0.zip -o /tmp/gutenberg.zip
unzip -q /tmp/gutenberg.zip -d wp-content/plugins/
wp plugin activate gutenberg

# Install custom must-use plugins for integration tests
mkdir -p wp-content/mu-plugins
Expand Down
12 changes: 11 additions & 1 deletion wp_api/src/post_types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ use serde::{Deserialize, Serialize};
use std::collections::HashMap;
use std::str::FromStr;
use wp_contextual::WpContextual;
use wp_serde_helper::deserialize_empty_array_or_hashmap;

#[derive(
Debug,
Expand Down Expand Up @@ -74,7 +75,7 @@ pub struct SparsePostTypeDetails {
#[WpContext(edit, embed, view)]
pub slug: Option<String>,
#[WpContext(edit)]
pub supports: Option<HashMap<PostTypeSupports, bool>>,
pub supports: Option<PostTypeSupportsMap>,
#[WpContext(edit, view)]
pub has_archive: Option<bool>,
#[WpContext(edit, view)]
Expand All @@ -90,6 +91,15 @@ pub struct SparsePostTypeDetails {
pub icon: Option<String>,
}

#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, uniffi::Record)]
#[serde(transparent)]
pub struct PostTypeSupportsMap {
#[serde(deserialize_with = "deserialize_empty_array_or_hashmap")]
#[serde(flatten)]
#[serde(rename = "supports")]
pub map: HashMap<PostTypeSupports, bool>,
}

#[derive(Default, Debug, Clone, PartialEq, Serialize, Deserialize, uniffi::Record)]
pub struct PostTypeLabels {
pub name: String,
Expand Down
1 change: 1 addition & 0 deletions wp_api/src/templates.rs
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ pub struct SparseTemplate {
#[WpContext(edit, embed, view)]
pub slug: Option<String>,
#[WpContext(edit, embed, view)]
#[WpContextualOption]
pub theme: Option<String>,
#[serde(rename = "type")]
#[WpContext(edit, embed, view)]
Expand Down
2 changes: 1 addition & 1 deletion wp_api_integration_tests/tests/test_post_types_immut.rs
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ async fn retrieve_post_types_with_edit_context(
// post types might not support `Title` in which case it's perfectly fine to completely
// remove this assertion.
assert_eq!(
post_type.supports.get(&PostTypeSupports::Title),
post_type.supports.map.get(&PostTypeSupports::Title),
Some(true).as_ref()
);
// All post types in our current testing sites have `EditPost` capability, so we use this
Expand Down
2 changes: 1 addition & 1 deletion wp_api_integration_tests/tests/test_templates_mut.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ async fn create_template_with_slug_title_and_theme() {
test_create_template(&params, |created_template| {
assert_slug(&created_template);
assert_title(&created_template);
assert_eq!(created_template.theme, theme);
assert_eq!(created_template.theme, Some(theme.to_string()));
})
.await;
}
Expand Down