Ticket #44786: 44786.withtests.patch
File 44786.withtests.patch, 3.8 KB (added by , 7 years ago) |
---|
-
src/wp-includes/revision.php
109 109 * @return int|WP_Error|void Void or 0 if error, new revision ID, if success. 110 110 */ 111 111 function wp_save_post_revision( $post_id ) { 112 if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) { 112 $autosave = defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE; 113 /** 114 * Filters whether saving of revisions is allowed during autosaves. 115 * Normally, it is disallowed whenever the `DOING_AUTOSAVE` constant is truthy. 116 * 117 * @since 4.9.9 118 * 119 * @param bool $block Is saving of revisions blocked for autosaves. Default is the value of `DOING_AUTOSAVE` 120 */ 121 if ( apply_filters( 'wp_save_post_block_revision_for_autosave', $autosave, $post_id ) ) { 113 122 return; 114 123 } 115 124 -
tests/phpunit/tests/post/revisions.php
119 119 ); //content unchanged, shouldn't save 120 120 $this->assertCount( 3, wp_get_post_revisions( $post_id ) ); //should still be 3 revision 121 121 122 //next try to save another update, same content, but new t tile, should save revision122 //next try to save another update, same content, but new title, should save revision 123 123 wp_update_post( 124 124 array( 125 125 'post_title' => 'some-post-changed', … … 190 190 ); //content unchanged, shouldn't save 191 191 $this->assertCount( 4, wp_get_post_revisions( $post_id ) ); 192 192 193 //next try to save another update, same content, but new t tile, should save revision193 //next try to save another update, same content, but new title, should save revision 194 194 wp_update_post( 195 195 array( 196 196 'post_title' => 'some-post-changed', … … 214 214 } 215 215 216 216 /** 217 * @ticket 44786 218 */ 219 function test_revision_block_revision_for_autosave() { 220 add_filter( 'wp_save_post_block_revision_for_autosave', '__return_false' ); 221 $post = get_default_post_to_edit( 'post', true ); 222 remove_filter( 'wp_save_post_block_revision_for_autosave', '__return_false' ); 223 224 $post_id = $post->ID; 225 226 $this->assertCount( 0, wp_get_post_revisions( $post_id ), 'There should be no revisions on auto-draft creation.' ); 227 228 $filter_false_and_check_post_id = function( $autosave, $_post_id ) use ( $post_id ) { 229 $this->assertSame( $post_id, $_post_id, 'post_id in the filtering function does not match.' ); 230 return false; 231 }; 232 233 add_filter( 'wp_save_post_block_revision_for_autosave', $filter_false_and_check_post_id, 10, 2 ); 234 235 wp_update_post( 236 array( 237 'post_status' => 'draft', 238 'post_title' => 'some-post', 239 'post_type' => 'post', 240 'post_content' => 'some_content', 241 'ID' => $post_id, 242 ) 243 ); 244 245 $this->assertCount( 1, wp_get_post_revisions( $post_id ), 'Revision count should be 1 after an update.' ); 246 247 wp_update_post( 248 array( 249 'post_content' => 'some updated content', 250 'ID' => $post_id, 251 ) 252 ); 253 $this->assertCount( 2, wp_get_post_revisions( $post_id ), 'Revision count should be 2 after another update.' ); 254 255 remove_filter( 'wp_save_post_block_revision_for_autosave', $filter_false_and_check_post_id ); 256 257 add_filter( 'wp_save_post_block_revision_for_autosave', '__return_true' ); 258 wp_update_post( 259 array( 260 'post_content' => 'new update for some updated content', 261 'ID' => $post_id, 262 ) 263 ); 264 remove_filter( 'wp_save_post_block_revision_for_autosave', '__return_true' ); 265 266 $this->assertCount( 2, wp_get_post_revisions( $post_id ), 'Revision count should still be 2 after another update with blocking re-enabled.' ); 267 } 268 269 /** 217 270 * Tests the Caps used in the action=view case of wp-admin/revision.php 218 271 * 219 272 * @ticket 16847