Skip to content

Commit 8f087fe

Browse files
authored
Pin Gutenberg plugin version and address test issues (#955)
* Address parsing issues for post_types & templates * Update Kotlin integration tests for PostTypeSupports changes * Update Swift example app for PostTypeSupports changes * Pin Gutenberg plugin version for test server to 21.7.0
1 parent f01f566 commit 8f087fe

File tree

7 files changed

+20
-7
lines changed

7 files changed

+20
-7
lines changed

native/kotlin/api/kotlin/src/integrationTest/kotlin/PostTypesEndpointTest.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ class PostTypesEndpointTest {
2626
val postTypesPost = client.request { requestBuilder ->
2727
requestBuilder.postTypes().retrieveWithEditContext(PostType.Post)
2828
}.assertSuccessAndRetrieveData().data
29-
assert(postTypesPost.supports[PostTypeSupports.Title]!!)
29+
assert(postTypesPost.supports.map[PostTypeSupports.Title]!!)
3030
assertFalse(postTypesPost.capabilities[PostTypeCapabilities.EditPosts]!!.isEmpty())
3131
}
3232

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

4141
@Test

native/swift/Example/Example/ExampleApp.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ struct ExampleApp: App {
128128
.postTypes
129129
.map(\.value)
130130
.filter { $0.visibility.showInNavMenus }
131-
.filter { $0.supports.keys.contains(allOf: [.title, .author, .customFields]) }
131+
.filter { $0.supports.map.keys.contains(allOf: [.title, .author, .customFields]) }
132132

133133
for type in postTypes {
134134
baseData.append(RootListData(name: type.name, sequence: {

scripts/setup-test-site.sh

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,9 @@ wp import /tmp/testdata.xml --authors=create
7171
wp plugin deactivate wordpress-importer
7272
wp plugin delete wordpress-importer
7373

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

7678
# Install custom must-use plugins for integration tests
7779
mkdir -p wp-content/mu-plugins

wp_api/src/post_types.rs

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ use serde::{Deserialize, Serialize};
33
use std::collections::HashMap;
44
use std::str::FromStr;
55
use wp_contextual::WpContextual;
6+
use wp_serde_helper::deserialize_empty_array_or_hashmap;
67

78
#[derive(
89
Debug,
@@ -74,7 +75,7 @@ pub struct SparsePostTypeDetails {
7475
#[WpContext(edit, embed, view)]
7576
pub slug: Option<String>,
7677
#[WpContext(edit)]
77-
pub supports: Option<HashMap<PostTypeSupports, bool>>,
78+
pub supports: Option<PostTypeSupportsMap>,
7879
#[WpContext(edit, view)]
7980
pub has_archive: Option<bool>,
8081
#[WpContext(edit, view)]
@@ -90,6 +91,15 @@ pub struct SparsePostTypeDetails {
9091
pub icon: Option<String>,
9192
}
9293

94+
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, uniffi::Record)]
95+
#[serde(transparent)]
96+
pub struct PostTypeSupportsMap {
97+
#[serde(deserialize_with = "deserialize_empty_array_or_hashmap")]
98+
#[serde(flatten)]
99+
#[serde(rename = "supports")]
100+
pub map: HashMap<PostTypeSupports, bool>,
101+
}
102+
93103
#[derive(Default, Debug, Clone, PartialEq, Serialize, Deserialize, uniffi::Record)]
94104
pub struct PostTypeLabels {
95105
pub name: String,

wp_api/src/templates.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,7 @@ pub struct SparseTemplate {
9494
#[WpContext(edit, embed, view)]
9595
pub slug: Option<String>,
9696
#[WpContext(edit, embed, view)]
97+
#[WpContextualOption]
9798
pub theme: Option<String>,
9899
#[serde(rename = "type")]
99100
#[WpContext(edit, embed, view)]

wp_api_integration_tests/tests/test_post_types_immut.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ async fn retrieve_post_types_with_edit_context(
9393
// post types might not support `Title` in which case it's perfectly fine to completely
9494
// remove this assertion.
9595
assert_eq!(
96-
post_type.supports.get(&PostTypeSupports::Title),
96+
post_type.supports.map.get(&PostTypeSupports::Title),
9797
Some(true).as_ref()
9898
);
9999
// All post types in our current testing sites have `EditPost` capability, so we use this

wp_api_integration_tests/tests/test_templates_mut.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ async fn create_template_with_slug_title_and_theme() {
5252
test_create_template(&params, |created_template| {
5353
assert_slug(&created_template);
5454
assert_title(&created_template);
55-
assert_eq!(created_template.theme, theme);
55+
assert_eq!(created_template.theme, Some(theme.to_string()));
5656
})
5757
.await;
5858
}

0 commit comments

Comments
 (0)