@@ -85,6 +85,20 @@ wp theme activate twentytwentyfour
85
85
wp comment trash 22
86
86
wp comment spam 23
87
87
88
+ create_post_revision () {
89
+ local revision_number=" $1 "
90
+ local post_id=" $2 "
91
+
92
+ curl --silent --user " $ADMIN_USERNAME " :" $ADMIN_PASSWORD " -H " Content-Type: application/json" -d " {\" content\" :\" content_revision_$revision_number \" , \" author\" : $ADMIN_USER_ID }" " http://localhost/wp-json/wp/v2/posts/$post_id " > /dev/null
93
+ }
94
+
95
+ create_post_autosave () {
96
+ local autosave_number=" $1 "
97
+ local post_id=" $2 "
98
+
99
+ curl --silent --user " $ADMIN_USERNAME " :" $ADMIN_PASSWORD " -H " Content-Type: application/json" -d " {\" content\" :\" content_autosave_$autosave_number \" , \" author\" : $ADMIN_USER_ID }" " http://localhost/wp-json/wp/v2/posts/$post_id /autosaves"
100
+ }
101
+
88
102
create_test_credentials () {
89
103
local SITE_URL
90
104
local ADMIN_USERNAME
@@ -98,6 +112,8 @@ create_test_credentials () {
98
112
local PASSWORD_PROTECTED_COMMENT_ID
99
113
local PASSWORD_PROTECTED_COMMENT_AUTHOR
100
114
local REVISIONED_POST_ID
115
+ local AUTOSAVED_POST_ID
116
+ local AUTOSAVE_ID_FOR_AUTOSAVED_POST_ID
101
117
local FIRST_POST_DATE_GMT
102
118
local WORDPRESS_VERSION
103
119
local INTEGRATION_TEST_CUSTOM_TEMPLATE_ID
@@ -133,13 +149,26 @@ create_test_credentials () {
133
149
134
150
echo " Setting up a post with 10 revisions for integration tests.."
135
151
REVISIONED_POST_ID=" $( wp post create --post_type=post --post_title=Revisioned_POST_FOR_INTEGRATION_TESTS --porcelain) "
152
+ # Create revisions
136
153
for i in {1..10};
137
154
do
138
- curl --silent --user " $ADMIN_USERNAME " : " $ADMIN_PASSWORD " -H " Content-Type: application/json " -d " { \" content \" : \" content_revision_ $i \" , \" author \" : $ADMIN_USER_ID } " " http://localhost/wp-json/wp/v2/posts/ $ REVISIONED_POST_ID" > /dev/null
155
+ create_post_revision " $i " " $ REVISIONED_POST_ID"
139
156
done
140
157
# Generating revisions don't return an id, but since we just created the `REVISIONED_POST_ID`, we can use it to calculate the revision id
141
158
REVISION_ID_FOR_REVISIONED_POST_ID=$(( REVISIONED_POST_ID + 1 ))
142
159
160
+ echo " Setting up a post with autosave for integration tests.."
161
+ # Autosaves require special setup: WordPress only creates separate autosave revisions when
162
+ # the autosave is made by a different user than the post author. If the same user creates
163
+ # an autosave, WordPress just updates the original post instead of creating a revision.
164
+ # See: https://github.com/WordPress/WordPress/blob/c90da2b67323e36b0390a9efa95f2b4bbb3be31b/wp-includes/rest-api/endpoints/class-wp-rest-autosaves-controller.php#L235-L244
165
+ # Create post as author user to enable proper autosave behavior
166
+ AUTHOR_USER_ID=" $( wp user get " $AUTHOR_USERNAME " --field=ID) "
167
+ AUTOSAVED_POST_ID=" $( wp post create --post_type=post --post_title=Autosaved_POST_FOR_INTEGRATION_TESTS --post_author=" $AUTHOR_USER_ID " --porcelain) "
168
+ # Create autosave as admin user (different from post author) and capture its ID
169
+ AUTOSAVE_RESPONSE=" $( create_post_autosave " 1" " $AUTOSAVED_POST_ID " ) "
170
+ AUTOSAVE_ID_FOR_AUTOSAVED_POST_ID=" $( echo " $AUTOSAVE_RESPONSE " | jq -r ' .id' ) "
171
+
143
172
rm -rf /app/test_credentials.json
144
173
jo -p \
145
174
site_url=" $SITE_URL " \
@@ -162,6 +191,8 @@ create_test_credentials () {
162
191
integration_test_custom_template_id=" $INTEGRATION_TEST_CUSTOM_TEMPLATE_ID " \
163
192
revisioned_post_id=" $REVISIONED_POST_ID " \
164
193
revision_id_for_revisioned_post_id=" $REVISION_ID_FOR_REVISIONED_POST_ID " \
194
+ autosaved_post_id=" $AUTOSAVED_POST_ID " \
195
+ autosave_id_for_autosaved_post_id=" $AUTOSAVE_ID_FOR_AUTOSAVED_POST_ID " \
165
196
> /app/test_credentials.json
166
197
}
167
198
create_test_credentials
0 commit comments