|
| 1 | +<?php |
| 2 | + |
| 3 | +/** |
| 4 | + * @group admin |
| 5 | + * |
| 6 | + * @covers ::wp_heartbeat_set_suspension |
| 7 | + */ |
| 8 | +class Tests_Admin_Includes_Misc_WpHeartbeatSetSuspension_Test extends WP_UnitTestCase { |
| 9 | + |
| 10 | + /** |
| 11 | + * Original value of $pagenow. |
| 12 | + * |
| 13 | + * @var string |
| 14 | + */ |
| 15 | + private $orig_pagenow; |
| 16 | + |
| 17 | + public function set_up() { |
| 18 | + global $pagenow; |
| 19 | + |
| 20 | + parent::set_up(); |
| 21 | + |
| 22 | + $this->orig_pagenow = $pagenow; |
| 23 | + } |
| 24 | + |
| 25 | + public function tear_down() { |
| 26 | + global $pagenow; |
| 27 | + |
| 28 | + $pagenow = $this->orig_pagenow; |
| 29 | + |
| 30 | + parent::tear_down(); |
| 31 | + } |
| 32 | + |
| 33 | + /** |
| 34 | + * Tests that wp_heartbeat_set_suspension() disables suspension on post screens. |
| 35 | + * |
| 36 | + * @dataProvider data_wp_heartbeat_set_suspension |
| 37 | + * |
| 38 | + * @ticket 65200 |
| 39 | + * |
| 40 | + * @param string $pagenow_value The value for the $pagenow global. |
| 41 | + * @param string $expected The expected value of 'suspension' in settings. |
| 42 | + */ |
| 43 | + public function test_wp_heartbeat_set_suspension( $pagenow_value, $expected ) { |
| 44 | + global $pagenow; |
| 45 | + |
| 46 | + $pagenow = $pagenow_value; |
| 47 | + |
| 48 | + $settings = array( 'suspension' => 'initial' ); |
| 49 | + $result = wp_heartbeat_set_suspension( $settings ); |
| 50 | + |
| 51 | + $this->assertSame( $expected, $result['suspension'], "Suspension should be '{$expected}' when \$pagenow is {$pagenow_value}." ); |
| 52 | + } |
| 53 | + |
| 54 | + /** |
| 55 | + * Data provider for test_wp_heartbeat_set_suspension(). |
| 56 | + * |
| 57 | + * @return array<string, array{ |
| 58 | + * pagenow_value: string, |
| 59 | + * expected: string, |
| 60 | + * }> |
| 61 | + */ |
| 62 | + public function data_wp_heartbeat_set_suspension(): array { |
| 63 | + return array( |
| 64 | + 'post.php' => array( |
| 65 | + 'pagenow_value' => 'post.php', |
| 66 | + 'expected' => 'disable', |
| 67 | + ), |
| 68 | + 'post-new.php' => array( |
| 69 | + 'pagenow_value' => 'post-new.php', |
| 70 | + 'expected' => 'disable', |
| 71 | + ), |
| 72 | + 'index.php' => array( |
| 73 | + 'pagenow_value' => 'index.php', |
| 74 | + 'expected' => 'initial', |
| 75 | + ), |
| 76 | + 'edit.php' => array( |
| 77 | + 'pagenow_value' => 'edit.php', |
| 78 | + 'expected' => 'initial', |
| 79 | + ), |
| 80 | + ); |
| 81 | + } |
| 82 | +} |
0 commit comments