| | 1185 | * Test that hooks are fired when post is stuck and unstuck. |
| | 1186 | * |
| | 1187 | * @ticket 35600 |
| | 1188 | */ |
| | 1189 | function test_hooks_fire_when_post_is_stuck_and_unstuck() { |
| | 1190 | // Create a dummy post. |
| | 1191 | $test_post = self::factory()->post->create_and_get( array( |
| | 1192 | 'post_title' => 'Dummy post title', |
| | 1193 | 'post_content' => 'Dummy post content', |
| | 1194 | ) ); |
| | 1195 | |
| | 1196 | $this->assertFalse( is_sticky( $test_post->ID ) ); |
| | 1197 | |
| | 1198 | // Hook callbacks. |
| | 1199 | add_action( 'post_stuck', array( $this, 'stuck_callback' ) ); |
| | 1200 | add_action( 'post_unstuck', array( $this, 'unstuck_callback' ) ); |
| | 1201 | |
| | 1202 | stick_post( $test_post->ID ); |
| | 1203 | |
| | 1204 | $this->assertTrue( is_sticky( $test_post->ID ) ); |
| | 1205 | |
| | 1206 | unstick_post( $test_post->ID ); |
| | 1207 | |
| | 1208 | $this->assertFalse( is_sticky( $test_post->ID ) ); |
| | 1209 | |
| | 1210 | // Verify the hooks ran when post was stuck and unstuck. |
| | 1211 | $this->assertEquals( 'yes', get_option( '_test_stuck_post_' . $test_post->ID, false ) ); |
| | 1212 | $this->assertEquals( 'yes', get_option( '_test_unstuck_post_' . $test_post->ID, false ) ); |
| | 1213 | } |
| | 1214 | |
| | 1215 | /** |
| | 1216 | * Helper for `test_hooks_fire_when_post_is_stuck_and_unstuck`. |
| | 1217 | */ |
| | 1218 | function stuck_callback( $post_id ) { |
| | 1219 | update_option( '_test_stuck_post_' . $post_id, 'yes' ); |
| | 1220 | } |
| | 1221 | |
| | 1222 | /** |
| | 1223 | * Helper for `test_hooks_fire_when_post_is_stuck_and_unstuck`. |
| | 1224 | */ |
| | 1225 | function unstuck_callback( $post_id ) { |
| | 1226 | update_option( '_test_unstuck_post_' . $post_id, 'yes' ); |
| | 1227 | } |
| | 1228 | |
| | 1229 | /** |