| | 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 | $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( $post->ID ) ); |
| | 1197 | |
| | 1198 | // Callback for testing hook. |
| | 1199 | $sticked_cb = function ( $post_id ) use ( $post ) { |
| | 1200 | update_option('_test_sticked_post_' . $post->ID, 'yes'); |
| | 1201 | }; |
| | 1202 | |
| | 1203 | // Callback for testing hook. |
| | 1204 | $unsticked_cb = function ( $post_id ) use ( $post ) { |
| | 1205 | update_option( '_test_unsticked_post_' . $post->ID, 'yes'); |
| | 1206 | }; |
| | 1207 | |
| | 1208 | // Hook callbacks. |
| | 1209 | add_action( 'post_sticked', $sticked_cb ); |
| | 1210 | add_action( 'post_unsticked', $unsticked_cb ); |
| | 1211 | |
| | 1212 | stick_post( $post->ID ); |
| | 1213 | |
| | 1214 | $this->assertTrue( is_sticky( $post->ID ) ); |
| | 1215 | |
| | 1216 | unstick_post( $post->ID ); |
| | 1217 | |
| | 1218 | $this->assertFalse( is_sticky( $post->ID ) ); |
| | 1219 | |
| | 1220 | // Verify the hooks ran when sticking and unsticking the post. |
| | 1221 | $this->assertEquals('yes', get_option( '_test_sticked_post_' . $post->ID, false ) ); |
| | 1222 | $this->assertEquals('yes', get_option( '_test_unsticked_post_' . $post->ID, false ) ); |
| | 1223 | } |
| | 1224 | |
| | 1225 | /** |