| | 1 | <?php |
| | 2 | |
| | 3 | // test behaviour of wp-includes/vars.php |
| | 4 | /** |
| | 5 | * @group vars |
| | 6 | */ |
| | 7 | class Tests_Vars extends WP_UnitTestCase { |
| | 8 | |
| | 9 | /** |
| | 10 | * @ticket 20014 |
| | 11 | * @ticket 33193 |
| | 12 | * @dataProvider userAgentData |
| | 13 | */ |
| | 14 | public function testUserAgentDetection( $name, $user_agent, array $expected ) { |
| | 15 | |
| | 16 | $_SERVER['HTTP_USER_AGENT'] = $user_agent; |
| | 17 | |
| | 18 | require ABSPATH . '/wp-includes/vars.php'; |
| | 19 | |
| | 20 | $conditionals = array( |
| | 21 | 'is_lynx', |
| | 22 | 'is_gecko', |
| | 23 | 'is_winIE', |
| | 24 | 'is_macIE', |
| | 25 | 'is_opera', |
| | 26 | 'is_NS4', |
| | 27 | 'is_safari', |
| | 28 | 'is_chrome', |
| | 29 | 'is_iphone', |
| | 30 | 'is_IE', |
| | 31 | 'is_edge', |
| | 32 | ); |
| | 33 | |
| | 34 | foreach ( $conditionals as $cond ) { |
| | 35 | if ( in_array( $cond, $expected ) ) { |
| | 36 | $this->assertTrue( $$cond, sprintf( '%s() should be true for %s', $cond, $name ) ); |
| | 37 | } else { |
| | 38 | $this->assertFalse( $$cond, sprintf( '%s() should be false for %s', $cond, $name ) ); |
| | 39 | } |
| | 40 | } |
| | 41 | |
| | 42 | } |
| | 43 | |
| | 44 | public function userAgentData() { |
| | 45 | return array( |
| | 46 | array( |
| | 47 | // https://udger.com/resources/ua-list/browser-detail?browser=Microsoft%20Edge |
| | 48 | 'Edge - Windows', |
| | 49 | 'Mozilla/5.0 (Windows NT 10.0) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/42.0.2311.135 Safari/537.36 Edge/12.10136', |
| | 50 | array( 'is_edge' ), |
| | 51 | ), |
| | 52 | array( |
| | 53 | 'IE11 - Windows', |
| | 54 | 'Mozilla/5.0 (Windows NT 6.3; Trident/7.0; rv:11.0) like Gecko', |
| | 55 | array( 'is_IE', 'is_winIE' ), |
| | 56 | ), |
| | 57 | array( |
| | 58 | // https://github.com/gorhill/uMatrix/wiki/Latest-user-agent-strings |
| | 59 | 'Firefox - Windows', |
| | 60 | 'Mozilla/5.0 (Windows NT 5.1; rv:39.0) Gecko/20100101 Firefox/39.0', |
| | 61 | array( 'is_gecko' ), |
| | 62 | ), |
| | 63 | array( |
| | 64 | // https://github.com/gorhill/uMatrix/wiki/Latest-user-agent-strings |
| | 65 | 'Firefox - Linux', |
| | 66 | 'Mozilla/5.0 (X11; Linux x86_64; rv:39.0) Gecko/20100101 Firefox/39.0', |
| | 67 | array( 'is_gecko' ), |
| | 68 | ), |
| | 69 | array( |
| | 70 | // https://github.com/gorhill/uMatrix/wiki/Latest-user-agent-strings |
| | 71 | 'Firefox - OS X', |
| | 72 | 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10.6; rv:39.0) Gecko/20100101 Firefox/39.0', |
| | 73 | array( 'is_gecko' ), |
| | 74 | ), |
| | 75 | array( |
| | 76 | // https://developer.mozilla.org/en-US/docs/Web/HTTP/Gecko_user_agent_string_reference |
| | 77 | 'Firefox - Android phone', |
| | 78 | 'Mozilla/5.0 (Android 4.4; Mobile; rv:41.0) Gecko/41.0 Firefox/41.0', |
| | 79 | array( 'is_gecko' ), |
| | 80 | ), |
| | 81 | array( |
| | 82 | // https://developer.mozilla.org/en-US/docs/Web/HTTP/Gecko_user_agent_string_reference |
| | 83 | 'Firefox - Android tablet', |
| | 84 | 'Mozilla/5.0 (Android 4.4; Tablet; rv:41.0) Gecko/41.0 Firefox/41.0', |
| | 85 | array( 'is_gecko' ), |
| | 86 | ), |
| | 87 | array( |
| | 88 | // https://developer.mozilla.org/en-US/docs/Web/HTTP/Gecko_user_agent_string_reference |
| | 89 | 'Firefox - Firefox OS phone', |
| | 90 | 'Mozilla/5.0 (Mobile; rv:26.0) Gecko/26.0 Firefox/26.0', |
| | 91 | array( 'is_gecko' ), |
| | 92 | ), |
| | 93 | array( |
| | 94 | // https://developer.mozilla.org/en-US/docs/Web/HTTP/Gecko_user_agent_string_reference |
| | 95 | 'Firefox - Firefox OS tablet', |
| | 96 | 'Mozilla/5.0 (Tablet; rv:26.0) Gecko/26.0 Firefox/26.0', |
| | 97 | array( 'is_gecko' ), |
| | 98 | ), |
| | 99 | array( |
| | 100 | // https://developer.chrome.com/multidevice/user-agent |
| | 101 | 'Chrome - Android phone', |
| | 102 | 'Mozilla/5.0 (Linux; Android 4.0.4; Galaxy Nexus Build/IMM76B) AppleWebKit/535.19 (KHTML, like Gecko) Chrome/18.0.1025.133 Mobile Safari/535.19', |
| | 103 | array( 'is_chrome' ), |
| | 104 | ), |
| | 105 | array( |
| | 106 | // https://developer.chrome.com/multidevice/user-agent |
| | 107 | 'Chrome - Android tablet', |
| | 108 | 'Mozilla/5.0 (Linux; Android 4.0.4; Galaxy Nexus Build/IMM76B) AppleWebKit/535.19 (KHTML, like Gecko) Chrome/18.0.1025.133 Safari/535.19', |
| | 109 | array( 'is_chrome' ), |
| | 110 | ), |
| | 111 | array( |
| | 112 | // https://github.com/gorhill/uMatrix/wiki/Latest-user-agent-strings |
| | 113 | 'Chrome - Windows', |
| | 114 | 'Mozilla/5.0 (Windows NT 6.3; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/44.0.2403.107 Safari/537.36', |
| | 115 | array( 'is_chrome' ), |
| | 116 | ), |
| | 117 | array( |
| | 118 | // https://github.com/gorhill/uMatrix/wiki/Latest-user-agent-strings |
| | 119 | 'Chrome - OS X', |
| | 120 | 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10_4) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/44.0.2403.89 Safari/537.36', |
| | 121 | array( 'is_chrome' ), |
| | 122 | ), |
| | 123 | array( |
| | 124 | // https://github.com/gorhill/uMatrix/wiki/Latest-user-agent-strings |
| | 125 | 'Lynx', |
| | 126 | 'Lynx/2.8.3dev.6 libwww-FM/2.14', |
| | 127 | array( 'is_lynx' ), |
| | 128 | ), |
| | 129 | array( |
| | 130 | // https://udger.com/resources/ua-list/browser-detail?browser=Safari |
| | 131 | 'Safari - OS X', |
| | 132 | 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10_0) AppleWebKit/600.3.10 (KHTML, like Gecko) Version/8.0.3 Safari/600.3.10', |
| | 133 | array( 'is_safari' ), |
| | 134 | ), |
| | 135 | array( |
| | 136 | // http://www.useragentstring.com/pages/Safari/ |
| | 137 | 'Safari - iOS', |
| | 138 | 'Mozilla/5.0 (iPad; CPU OS 6_0 like Mac OS X) AppleWebKit/536.26 (KHTML, like Gecko) Version/6.0 Mobile/10A5355d Safari/8536.25', |
| | 139 | array( 'is_safari', 'is_iphone' ), |
| | 140 | ), |
| | 141 | ); |
| | 142 | } |
| | 143 | |
| | 144 | } |