| 1185 | * Test that hooks are fired for sticking and unsticking a post. |
| 1186 | * |
| 1187 | * @ticket 35600 |
| 1188 | */ |
| 1189 | function test_post_stick_and_unstick_fire_actions() { |
| 1190 | // Create a dummy post. |
| 1191 | $sticky_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( $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( $sticky_test_post->ID ); |
| 1203 | |
| 1204 | $this->assertTrue( is_sticky( $sticky_test_post->ID ) ); |
| 1205 | |
| 1206 | unstick_post( $sticky_test_post->ID ); |
| 1207 | |
| 1208 | $this->assertFalse( is_sticky( $sticky_test_post->ID ) ); |
| 1209 | |
| 1210 | // Verify the hooks ran when sticking and unsticking the post. |
| 1211 | $this->assertEquals( 'yes', get_option( '_test_sticked_post_' . $sticky_test_post->ID, false ) ); |
| 1212 | $this->assertEquals( 'yes', get_option( '_test_unsticked_post_' . $sticky_test_post->ID, false ) ); |
| 1213 | } |
| 1214 | |
| 1215 | /** |
| 1216 | * Helper for `test_post_stick_and_unstick_fire_actions`. |
| 1217 | */ |
| 1218 | function stuck_callback( $post_id ) { |
| 1219 | update_option( '_test_sticked_post_' . $post_id, 'yes' ); |
| 1220 | } |
| 1221 | |
| 1222 | /** |
| 1223 | * Helper for `test_post_stick_and_unstick_fire_actions`. |
| 1224 | */ |
| 1225 | function unstuck_callback( $post_id ) { |
| 1226 | update_option( '_test_unsticked_post_' . $post_id, 'yes' ); |
| 1227 | } |
| 1228 | |
| 1229 | /** |