| | 1 | <?php |
| | 2 | |
| | 3 | include dirname( __FILE__ ) . '/../../../parse.php'; |
| | 4 | |
| | 5 | /** |
| | 6 | * |
| | 7 | * @group browse-happy |
| | 8 | */ |
| | 9 | class Tests_Browse_Happy extends PHPUnit_Framework_TestCase { |
| | 10 | |
| | 11 | /** |
| | 12 | * @dataProvider data_browse_happy |
| | 13 | * |
| | 14 | * @type string $header 'User-Agent' header value. |
| | 15 | * @type string $expected Expected browser name and version. |
| | 16 | */ |
| | 17 | function test_browsehappy_parse_user_agent( $header, $expected ) { |
| | 18 | $parsed = browsehappy_parse_user_agent( $header ); |
| | 19 | $result = $parsed['platform'] . ' ' . $parsed['name'] . ' ' . $parsed['version']; |
| | 20 | |
| | 21 | $this->assertEquals( $expected, $result ); |
| | 22 | } |
| | 23 | |
| | 24 | /** |
| | 25 | * @dataProvider data_browse_happy |
| | 26 | * |
| | 27 | * @type string $header 'User-Agent' header value. |
| | 28 | */ |
| | 29 | function test_insecure_browsers( $header ) { |
| | 30 | $parsed = browsehappy_parse_user_agent( $header ); |
| | 31 | |
| | 32 | if ( 'Internet Explorer' === $parsed['name'] && version_compare( $parsed['version'], '11', '<' ) ) { |
| | 33 | $this->assertTrue( $parsed['insecure'] ); |
| | 34 | } |
| | 35 | } |
| | 36 | |
| | 37 | /** |
| | 38 | * Data provider for test_browsehappy_parse_user_agent(). |
| | 39 | * |
| | 40 | * @return array { |
| | 41 | * @type array { |
| | 42 | * @type string $header 'User-Agent' header value. |
| | 43 | * @type string $expected Expected browser name and version. |
| | 44 | * } |
| | 45 | * } |
| | 46 | */ |
| | 47 | function data_browse_happy() { |
| | 48 | return [ |
| | 49 | [ |
| | 50 | 'Mozilla/4.0 (Windows; MSIE 6.0; Windows NT 5.1; SV1; .NET CLR 2.0.50727)', |
| | 51 | 'Windows Internet Explorer 6.0', |
| | 52 | ], |
| | 53 | [ |
| | 54 | 'Mozilla/4.0 (MSIE 6.0; Windows NT 5.1)', |
| | 55 | 'Windows Internet Explorer 6.0', |
| | 56 | ], |
| | 57 | [ |
| | 58 | 'Mozilla/4.0 (MSIE 6.0; Windows NT 5.0)', |
| | 59 | 'Windows Internet Explorer 6.0', |
| | 60 | ], |
| | 61 | [ |
| | 62 | 'Mozilla/4.0 (compatible;MSIE 6.0;Windows 98;Q312461)', |
| | 63 | 'Windows Internet Explorer 6.0', |
| | 64 | ], |
| | 65 | [ |
| | 66 | 'Mozilla/4.0 (Compatible; Windows NT 5.1; MSIE 6.0) (compatible; MSIE 6.0; Windows NT 5.1; .NET CLR 1.1.4322; .NET CLR 2.0.50727)', |
| | 67 | 'Windows Internet Explorer 6.0', |
| | 68 | ], |
| | 69 | [ |
| | 70 | 'Mozilla/4.0 (compatible; U; MSIE 6.0; Windows NT 5.1)', |
| | 71 | 'Windows Internet Explorer 6.0', |
| | 72 | ], |
| | 73 | [ |
| | 74 | 'Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1) ; .NET CLR 1.1.4322; .NET CLR 2.0.50727; .NET CLR 3.0.4506.2152; .NET CLR 3.5.30729; .NET4.0C; .NET4.0E)', |
| | 75 | 'Windows Internet Explorer 7.0', |
| | 76 | ], |
| | 77 | [ |
| | 78 | 'Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.1; Trident/4.0; SLCC2; .NET CLR 2.0.50727; .NET CLR 3.5.30729; .NET CLR 3.0.30729; Media Center PC 6.0; .NET4.0C; .NET4.0E; Tablet PC 2.0)', |
| | 79 | 'Windows Internet Explorer 8.0', |
| | 80 | ], |
| | 81 | [ |
| | 82 | 'Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.1; Trident/4.0; Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1) ; SLCC2; .NET CLR 2.0.50727; .NET CLR 3.5.30729; .NET CLR 3.0.30729; Media Center PC 6.0; .NET4.0C; InfoPath.3; Tablet PC 2.0)', |
| | 83 | 'Windows Internet Explorer 8.0', |
| | 84 | ], |
| | 85 | [ |
| | 86 | 'Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; Trident/5.0)', |
| | 87 | 'Windows Internet Explorer 9.0', |
| | 88 | ], |
| | 89 | // #2587 |
| | 90 | [ |
| | 91 | 'Mozilla/5.0 (compatible; MSIE 10.0; Windows NT 6.2; Trident/6.0)', |
| | 92 | 'Windows Internet Explorer 10.0', |
| | 93 | ], |
| | 94 | // #2587 |
| | 95 | [ |
| | 96 | 'Mozilla/5.0 (Windows NT 6.3; Trident/7.0; rv:11.0) like Gecko', |
| | 97 | 'Windows Internet Explorer 11', |
| | 98 | ], |
| | 99 | [ |
| | 100 | 'Mozilla/5.0 (Windows; U; Windows NT 5.1; en-GB; rv:1.9.1.5) Gecko/20091102 Firefox/3.5.5 (.NET CLR 3.5.21022)', |
| | 101 | 'Windows Firefox 3.5.5', |
| | 102 | ], |
| | 103 | [ |
| | 104 | 'Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US; rv:1.9.2.15) Gecko/20110303 Firefox/3.6.15 FirePHP/0.5', |
| | 105 | 'Windows Firefox 3.6.15', |
| | 106 | ], |
| | 107 | [ |
| | 108 | 'Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US) AppleWebKit/534.13 (KHTML, like Gecko) Chrome/9.0.597.98 Safari/534.13', |
| | 109 | 'Windows Chrome 9.0.597.98', |
| | 110 | ], |
| | 111 | [ |
| | 112 | 'Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US) AppleWebKit/534.16 (KHTML, like Gecko) Chrome/10.0.648.114 Safari/534.16', |
| | 113 | 'Windows Chrome 10.0.648.114', |
| | 114 | ], |
| | 115 | [ |
| | 116 | 'Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US) AppleWebKit/534.7 (KHTML, like Gecko) Chrome/7.0.517.41 Safari/534.7', |
| | 117 | 'Windows Chrome 7.0.517.41', |
| | 118 | ], |
| | 119 | [ |
| | 120 | 'Opera/9.80 (Windows NT 6.0; U; en) Presto/2.8.99 Version/11.10', |
| | 121 | 'Windows Opera 11.10', |
| | 122 | ], |
| | 123 | [ |
| | 124 | 'Opera/9.80 (Windows NT 5.1; U; cs) Presto/2.7.62 Version/11.01', |
| | 125 | 'Windows Opera 11.01', |
| | 126 | ], |
| | 127 | [ |
| | 128 | 'Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US; rv:1.9.2.13) Gecko/20101213 Opera/9.80 (Windows NT 6.1; U; zh-tw) Presto/2.7.62 Version/11.01', |
| | 129 | 'Windows Opera 11.01', |
| | 130 | ], |
| | 131 | [ |
| | 132 | 'Mozilla/5.0 (Windows NT 6.1; U; nl; rv:1.9.1.6) Gecko/20091201 Firefox/3.5.6 Opera 11.01', |
| | 133 | 'Windows Opera 11.01', |
| | 134 | ], |
| | 135 | [ |
| | 136 | 'Mozilla/5.0 (Windows NT 6.1; U; de; rv:1.9.1.6) Gecko/20091201 Firefox/3.5.6 Opera 11.01', |
| | 137 | 'Windows Opera 11.01', |
| | 138 | ], |
| | 139 | [ |
| | 140 | 'Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.1; de) Opera 11.01', |
| | 141 | 'Windows Opera 11.01', |
| | 142 | ], |
| | 143 | [ |
| | 144 | 'Mozilla/5.0 (Windows; U; Windows NT 6.1; tr-TR) AppleWebKit/533.20.25 (KHTML, like Gecko) Version/5.0.4 Safari/533.20.27', |
| | 145 | 'Windows Safari 5.0.4', |
| | 146 | ], |
| | 147 | [ |
| | 148 | 'Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10.6; en-US; rv:1.9.2.3) Gecko/20100401 Firefox/3.6.3', |
| | 149 | 'Macintosh Firefox 3.6.3', |
| | 150 | ], |
| | 151 | [ |
| | 152 | 'Mozilla/5.0 (Macintosh; U; PPC Mac OS X 10_4_11; en) AppleWebKit/531.22.7 (KHTML, like Gecko) Version/4.0.5 Safari/531.22.7', |
| | 153 | 'Macintosh Safari 4.0.5', |
| | 154 | ], |
| | 155 | [ |
| | 156 | 'Mozilla/5.0 (Macintosh; U; PPC Mac OS X 10_4_11; en) AppleWebKit/533.18.1 (KHTML, like Gecko) Version/4.1.2 Safari/533.18.5', |
| | 157 | 'Macintosh Safari 4.1.2', |
| | 158 | ], |
| | 159 | [ |
| | 160 | 'Mozilla/5.0 (Macintosh; U; PPC Mac OS X; en) AppleWebKit/312.9 (KHTML, like Gecko) Safari/312.6', |
| | 161 | 'Macintosh Safari 312.6', |
| | 162 | ], |
| | 163 | [ |
| | 164 | 'Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10_6_3; en-us) AppleWebKit/533.16 (KHTML, like Gecko) Version/5.0 Safari/533.16', |
| | 165 | 'Macintosh Safari 5.0', |
| | 166 | ], |
| | 167 | [ |
| | 168 | 'Mozilla/5.0 (Macintosh; U; PPC Mac OS X 10.5; it; rv:1.9.0.19) Gecko/2010111021 Camino/2.0.6 (MultiLang) (like Firefox/3.0.19)', |
| | 169 | 'Macintosh Camino 2.0.6', |
| | 170 | ], |
| | 171 | [ |
| | 172 | 'Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10.6; en; rv:1.9.0.18) Gecko/2010021619 Camino/2.0.2 (like Firefox/3.0.18)', |
| | 173 | 'Macintosh Camino 2.0.2', |
| | 174 | ], |
| | 175 | [ |
| | 176 | 'Mozilla/5.0 (Macintosh; U; PPC Mac OS X Mach-O; it; rv:1.8.1.21) Gecko/20090327 Camino/1.6.7 (MultiLang) (like Firefox/2.0.0.21pre)', |
| | 177 | 'Macintosh Camino 1.6.7', |
| | 178 | ], |
| | 179 | [ |
| | 180 | 'Mozilla/5.0 (Macintosh; U; Intel Mac OS X; en; rv:1.8.1.11) Gecko/20071128 Camino/1.5.4', |
| | 181 | 'Macintosh Camino 1.5.4', |
| | 182 | ], |
| | 183 | [ |
| | 184 | 'Mozilla/5.0 (Linux; U; Android 2.2; en-us; SGH-T959 Build/FROYO) AppleWebKit/533.1 (KHTML, like Gecko) Version/4.0 Mobile Safari/533.1', |
| | 185 | 'Linux Mobile Safari 4.0', |
| | 186 | ], |
| | 187 | [ |
| | 188 | 'Mozilla/5.0 (iPad; U; CPU iPhone OS 3_2 like Mac OS X; en-us) AppleWebKit/531.21.10 (KHTML, like Gecko) Version/4.0.4 Mobile/7B314 Safari/531.21.10', |
| | 189 | 'iPad Safari 4.0.4', |
| | 190 | ], |
| | 191 | [ |
| | 192 | 'Mozilla/5.0 (iPad; U; CPU OS 3_2 like Mac OS X; en-us) AppleWebKit/531.21.10 (KHTML, like Gecko) Version/4.0.4 Mobile/7B334b Safari/531.21.10', |
| | 193 | 'iPad Safari 4.0.4', |
| | 194 | ], |
| | 195 | [ |
| | 196 | 'Mozilla/5.0 (iPhone; U; CPU iPhone OS 4_2_6 like Mac OS X; en-us) AppleWebKit/533.17.9 (KHTML, like Gecko) Version/5.0.2 Mobile/8E200 Safari/6533.18.5', |
| | 197 | 'iPhone Safari 5.0.2', |
| | 198 | ], |
| | 199 | [ |
| | 200 | 'Mozilla/5.0 (iPhone; U; CPU like Mac OS X; en) AppleWebKit/420+ (KHTML, like Gecko) Version/3.0 Mobile/1C25 Safari/419.3', |
| | 201 | 'iPhone Safari 3.0', |
| | 202 | ], |
| | 203 | [ |
| | 204 | 'Mozilla/4.0 (compatible; MSIE 7.0; Windows Phone OS 7.0; Trident/3.1; IEMobile/7.0) Asus;Galaxy6', |
| | 205 | 'Windows Phone OS Internet Explorer Mobile 7.0', |
| | 206 | ], |
| | 207 | [ |
| | 208 | 'Mozilla/4.0 (compatible; MSIE 7.0; Windows Phone OS 7.0; Trident/3.1; IEMobile/7.0; LG; GW910)', |
| | 209 | 'Windows Phone OS Internet Explorer Mobile 7.0', |
| | 210 | ], |
| | 211 | [ |
| | 212 | 'Mozilla/4.0 (compatible; MSIE 7.0; Windows Phone OS 7.0; Trident/3.1; IEMobile/7.0) LG;LG-E900h)', |
| | 213 | 'Windows Phone OS Internet Explorer Mobile 7.0', |
| | 214 | ], |
| | 215 | [ |
| | 216 | 'Mozilla/4.0 (compatible; Linux 2.6.10) NetFront/3.3 Kindle/1.0 (screen 600x800)', |
| | 217 | 'Kindle Kindle 1.0', |
| | 218 | ], |
| | 219 | [ |
| | 220 | 'Mozilla/5.0 (Linux; U; en-US) AppleWebKit/528.5+ (KHTML, like Gecko, Safari/528.5+) Version/4.0 Kindle/3.0 (screen 600x800; rotate)', |
| | 221 | 'Kindle Kindle 4.0', |
| | 222 | ], |
| | 223 | [ |
| | 224 | 'Mozilla/5.0 (Linux; U; en-US) AppleWebKit/528.5+ (KHTML, like Gecko, Safari/538.5+) Version/4.0 Kindle/3.0 (screen 600x800; rotate)', |
| | 225 | 'Kindle Kindle 4.0', |
| | 226 | ], |
| | 227 | [ |
| | 228 | 'Mozilla/5.0 (PlayBook; U; RIM Tablet OS 1.0.0; en-US) AppleWebKit/534.8 (KHTML, like Gecko) Version/0.0.1 Safari/534.8', |
| | 229 | 'PlayBook PlayBook 0.0.1', |
| | 230 | ], |
| | 231 | [ |
| | 232 | 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_6_7) AppleWebKit/534.24 (KHTML, like Gecko) RockMelt/0.9.58.494 Chrome/11.0.696.71 Safari/534.24', |
| | 233 | 'Macintosh RockMelt 0.9.58.494', |
| | 234 | ], |
| | 235 | [ |
| | 236 | 'Mozilla/5.0 (Linux; U; Android 3.1; en-us; GT-P7510 Build/HMJ37) AppleWebKit/534.13 (KHTML, like Gecko) Version/4.0 Safari/534.13', |
| | 237 | 'Android Safari 4.0', |
| | 238 | ], |
| | 239 | ]; |
| | 240 | } |
| | 241 | } |