| 7 | | function test_shorten_url() { |
| 8 | | $tests = array( |
| 9 | | 'wordpress\.org/about/philosophy' |
| 10 | | => 'wordpress\.org/about/philosophy', // no longer strips slashes |
| 11 | | 'wordpress.org/about/philosophy' |
| 12 | | => 'wordpress.org/about/philosophy', |
| 13 | | 'http://wordpress.org/about/philosophy/' |
| 14 | | => 'wordpress.org/about/philosophy', // remove http, trailing slash |
| 15 | | 'http://www.wordpress.org/about/philosophy/' |
| 16 | | => 'wordpress.org/about/philosophy', // remove http, www |
| 17 | | 'http://wordpress.org/about/philosophy/#box' |
| 18 | | => 'wordpress.org/about/philosophy/#box', // don't shorten 35 characters |
| 19 | | 'http://wordpress.org/about/philosophy/#decisions' |
| 20 | | => 'wordpress.org/about/philosophy/#…', // shorten to 32 if > 35 after cleaning |
| | 7 | public function shorten_url_urls() { |
| | 8 | return array( |
| | 9 | // no longer strips slashes |
| | 10 | array( 'wordpress\.org/about/philosophy', 'wordpress\.org/about/philosophy' ), |
| | 11 | array( 'wordpress.org/about/philosophy', 'wordpress.org/about/philosophy' ), |
| | 12 | // remove http, trailing slash |
| | 13 | array( 'http://wordpress.org/about/philosophy/', 'wordpress.org/about/philosophy' ), |
| | 14 | // remove http, www |
| | 15 | array( 'http://www.wordpress.org/about/philosophy/', 'wordpress.org/about/philosophy' ), |
| | 16 | // don't shorten 35 characters |
| | 17 | array( 'http://wordpress.org/about/philosophy/#box', 'wordpress.org/about/philosophy/#box' ), |
| | 18 | // shorten to 32 if > 35 after cleaning |
| | 19 | array( 'http://wordpress.org/about/philosophy/#decisions', 'wordpress.org/about/philosophy/#…' ), |
| | 22 | |
| | 23 | /** |
| | 24 | * @dataProvider shorten_url_urls |
| | 25 | */ |
| | 26 | function test_shorten_url( $input, $expected ) { |
| | 27 | $this->assertEquals( $expected, url_shorten( $input ) ); |
| | 28 | } |
| | 29 | |
| | 30 | public function test_get_current_admin_page_url_returns_false_in_non_admin() { |
| | 31 | set_current_screen( 'front' ); |
| | 32 | |
| | 33 | $this->assertFalse( is_admin() ); |
| | 34 | |
| | 35 | $this->assertFalse( get_current_admin_page_url() ); |
| | 36 | } |
| | 37 | |
| | 38 | public function test_get_current_admin_page_url_returns_empty_string_for_empty_pagenow_or_SERVER_values() { |
| | 39 | global $pagenow; |
| | 40 | $pagenow = ''; |
| | 41 | $_SERVER['QUERY_STRING'] = ''; |
| | 42 | |
| | 43 | // any admin screen will do for the purpose of testing |
| | 44 | set_current_screen( 'edit.php' ); |
| | 45 | |
| | 46 | $this->assertTrue( is_admin() ); |
| | 47 | |
| | 48 | $this->assertEquals( '', get_current_admin_page_url() ); |
| | 49 | } |
| | 50 | |
| | 51 | public function pagenow_and_SERVER_QUERY_STRING() { |
| | 52 | return array( |
| | 53 | array( 'some-admin-page.php', 'some-admin-page.php', '' ), |
| | 54 | array( 'some-admin-page.php?foo=bar', 'some-admin-page.php', 'foo=bar' ), |
| | 55 | array( 'some-admin-page.php?foo=bar&baz=bar', 'some-admin-page.php', 'foo=bar&baz=bar' ), |
| | 56 | ); |
| | 57 | } |
| | 58 | |
| | 59 | /** |
| | 60 | * @dataProvider pagenow_and_SERVER_QUERY_STRING |
| | 61 | */ |
| | 62 | public function test_get_current_admin_page_url( $expected, $mock_pagenow, $server_query_string ) { |
| | 63 | global $pagenow; |
| | 64 | $pagenow = $mock_pagenow; |
| | 65 | $_SERVER['QUERY_STRING'] = $server_query_string; |
| | 66 | |
| | 67 | // any admin screen will do for the purpose of testing |
| | 68 | set_current_screen( 'edit.php' ); |
| | 69 | |
| | 70 | $this->assertTrue( is_admin() ); |
| | 71 | |
| | 72 | $this->assertEquals( $expected, get_current_admin_page_url() ); |
| | 73 | } |
| | 74 | |
| | 75 | public function test_get_current_admin_hook_will_return_false_in_not_admin() { |
| | 76 | set_current_screen( 'front' ); |
| | 77 | |
| | 78 | $this->assertFalse( get_current_admin_hook() ); |
| | 79 | } |
| | 80 | |
| | 81 | public function current_filters() { |
| | 82 | return array( |
| | 83 | array( '', array( '' ) ), |
| | 84 | array( 'some_hook', array( 'some_hook' ) ), |
| | 85 | array( 'another_hook', array( 'some_hook', 'another_hook' ) ), |
| | 86 | ); |
| | 87 | } |
| | 88 | |
| | 89 | /** |
| | 90 | * @dataProvider current_filters |
| | 91 | */ |
| | 92 | public function test_get_current_admin_hook( $expected, $mock_current_filter ) { |
| | 93 | // any admin screen will do for the purpose of testing |
| | 94 | set_current_screen( 'edit.php' ); |
| | 95 | |
| | 96 | global $wp_current_filter; |
| | 97 | $wp_current_filter = $mock_current_filter; |
| | 98 | |
| | 99 | $this->assertEquals( $expected, get_current_admin_hook() ); |
| | 100 | } |