| 26 | |
| 27 | public function test_get_current_admin_page_url_returns_false_in_non_admin() { |
| 28 | set_current_screen( 'front' ); |
| 29 | |
| 30 | $this->assertFalse( is_admin() ); |
| 31 | |
| 32 | $this->assertFalse( get_current_admin_page_url() ); |
| 33 | } |
| 34 | |
| 35 | public function test_get_current_admin_page_url_returns_empty_string_for_empty_pagenow_or_SERVER_values() { |
| 36 | global $pagenow; |
| 37 | $pagenow = ''; |
| 38 | $_SERVER['QUERY_STRING'] = ''; |
| 39 | |
| 40 | // any admin screen will do for the purpose of testing |
| 41 | set_current_screen( 'edit.php' ); |
| 42 | |
| 43 | $this->assertTrue( is_admin() ); |
| 44 | |
| 45 | $this->assertEquals( '', get_current_admin_page_url() ); |
| 46 | } |
| 47 | |
| 48 | public function pagenow_and_SERVER_QUERY_STRING() { |
| 49 | return array( |
| 50 | array( 'some-admin-page.php', 'some-admin-page.php', '' ), |
| 51 | array( 'some-admin-page.php?foo=bar', 'some-admin-page.php', 'foo=bar' ), |
| 52 | array( 'some-admin-page.php?foo=bar&baz=bar', 'some-admin-page.php', 'foo=bar&baz=bar' ), |
| 53 | ); |
| 54 | } |
| 55 | |
| 56 | /** |
| 57 | * @dataProvider pagenow_and_SERVER_QUERY_STRING |
| 58 | */ |
| 59 | public function test_get_current_admin_page_url( $expected, $mock_pagenow, $server_query_string ) { |
| 60 | global $pagenow; |
| 61 | $pagenow = $mock_pagenow; |
| 62 | $_SERVER['QUERY_STRING'] = $server_query_string; |
| 63 | |
| 64 | // any admin screen will do for the purpose of testing |
| 65 | set_current_screen( 'edit.php' ); |
| 66 | |
| 67 | $this->assertTrue( is_admin() ); |
| 68 | |
| 69 | $this->assertEquals( $expected, get_current_admin_page_url() ); |
| 70 | } |
| 71 | |
| 72 | public function test_get_current_admin_hook_will_return_false_in_not_admin() { |
| 73 | set_current_screen( 'front' ); |
| 74 | |
| 75 | $this->assertFalse( get_current_admin_hook() ); |
| 76 | } |
| 77 | |
| 78 | public function current_filters() { |
| 79 | return array( |
| 80 | array( '', array( '' ) ), |
| 81 | array( 'some_hook', array( 'some_hook' ) ), |
| 82 | array( 'another_hook', array( 'some_hook', 'another_hook' ) ), |
| 83 | ); |
| 84 | } |
| 85 | |
| 86 | /** |
| 87 | * @dataProvider current_filters |
| 88 | */ |
| 89 | public function test_get_current_admin_hook( $expected, $mock_current_filter ) { |
| 90 | // any admin screen will do for the purpose of testing |
| 91 | set_current_screen( 'edit.php' ); |
| 92 | |
| 93 | global $wp_current_filter; |
| 94 | $wp_current_filter = $mock_current_filter; |
| 95 | |
| 96 | $this->assertEquals( $expected, get_current_admin_hook() ); |
| 97 | } |