Skip to content

Commit 5f00726

Browse files
authored
Merge pull request #84 from cbschuld/firefox_mobile
better checks and tests for mobile firefox
2 parents d40cb3b + 4a5feb7 commit 5f00726

File tree

2 files changed

+75
-14
lines changed

2 files changed

+75
-14
lines changed

lib/Browser.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1314,8 +1314,8 @@ protected function checkBrowserFirefox()
13141314
$this->setVersion($matches[1]);
13151315
$this->setBrowser(self::BROWSER_FIREFOX);
13161316
//Firefox on Android
1317-
if (stripos($this->_agent, 'Android') !== false) {
1318-
if (stripos($this->_agent, 'Mobile') !== false) {
1317+
if (stripos($this->_agent, 'Android') !== false || stripos($this->_agent, 'iPhone') !== false) {
1318+
if (stripos($this->_agent, 'Mobile') !== false || stripos($this->_agent, 'Tablet') !== false) {
13191319
$this->setMobile(true);
13201320
} else {
13211321
$this->setTablet(true);
@@ -1335,8 +1335,8 @@ protected function checkBrowserFirefox()
13351335
$this->setVersion($matches[1]);
13361336
$this->setBrowser(self::BROWSER_FIREFOX);
13371337
//Firefox on Android
1338-
if (stripos($this->_agent, 'Android') !== false) {
1339-
if (stripos($this->_agent, 'Mobile') !== false) {
1338+
if (stripos($this->_agent, 'Android') !== false || stripos($this->_agent, 'iPhone') !== false) {
1339+
if (stripos($this->_agent, 'Mobile') !== false || stripos($this->_agent, 'Tablet') !== false) {
13401340
$this->setMobile(true);
13411341
} else {
13421342
$this->setTablet(true);

tests/StaticTest.php

Lines changed: 71 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,19 +7,80 @@
77

88
final class StaticTest extends TestCase
99
{
10-
public function testStaticUserAgent()
10+
public function userAgentStaticProvider()
1111
{
12-
$userAgents = [
13-
'Mozilla/5.0 (Windows NT 10.0; WOW64; Trident/7.0; rv:11.0) like Gecko' => [
12+
return [
13+
[
14+
'useragent' => 'Mozilla/5.0 (Windows NT 10.0; WOW64; Trident/7.0; rv:11.0) like Gecko',
1415
'browser' => Browser::BROWSER_IE,
15-
'version' => '11.0'
16-
]
16+
'version' => '11.0',
17+
'platform' => Browser::PLATFORM_WINDOWS,
18+
'mobile' => false,
19+
],
20+
[
21+
'useragent' => 'Mozilla/5.0 (Android 4.4; Mobile; rv:41.0) Gecko/41.0 Firefox/41.0',
22+
'browser' => Browser::BROWSER_FIREFOX,
23+
'version' => '41.0',
24+
'platform' => Browser::PLATFORM_ANDROID,
25+
'mobile' => true,
26+
],
27+
[
28+
'useragent' => 'Mozilla/5.0 (Android 4.4; Tablet; rv:41.0) Gecko/41.0 Firefox/41.0',
29+
'browser' => Browser::BROWSER_FIREFOX,
30+
'version' => '41.0',
31+
'platform' => Browser::PLATFORM_ANDROID,
32+
'mobile' => true,
33+
],
34+
[
35+
'useragent' => 'Mozilla/5.0 (iPhone; CPU iPhone OS 6_1_4 like Mac OS X) AppleWebKit/536.26 (KHTML, like Gecko) CriOS/28.0.1500.16 Mobile/10B350 Safari/8536.25',
36+
'browser' => Browser::BROWSER_CHROME,
37+
'version' => '28.0.1500.16',
38+
'platform' => Browser::PLATFORM_IPHONE,
39+
'mobile' => true,
40+
],
41+
[
42+
'useragent' => 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/536.11 (KHTML, like Gecko) DumpRenderTree/0.0.0.0 Safari/536.11',
43+
'browser' => Browser::BROWSER_SAFARI,
44+
'version' => 'unknown', // all we really know here is that it's based on webkit; we do not really have a version number to deal with
45+
'platform' => Browser::PLATFORM_LINUX,
46+
'mobile' => false,
47+
],
48+
[
49+
'useragent' => 'Mozilla/5.0 (iPhone; CPU iPhone OS 6_1 like Mac OS X) AppleWebKit/536.26 (KHTML, like Gecko) CriOS/28.0.1500.16 Mobile/10B142 Safari/8536.25',
50+
'browser' => Browser::BROWSER_CHROME,
51+
'version' => '28.0.1500.16',
52+
'platform' => Browser::PLATFORM_IPHONE,
53+
'mobile' => true,
54+
],
55+
[
56+
'useragent' => 'Mozilla/5.0 (compatible; MSIE 9.0; Windows Phone OS 7.5; Trident/5.0; IEMobile/9.0; HTC; Radar; Orange)',
57+
'browser' => Browser::BROWSER_POCKET_IE,
58+
'version' => '9.0',
59+
'platform' => Browser::PLATFORM_WINDOWS,
60+
'mobile' => true,
61+
],
1762
];
18-
foreach($userAgents as $userAgent => $info) {
19-
$b = new Browser($userAgent);
20-
$this->assertSame($info['browser'], $b->getBrowser());
21-
$this->assertSame($info['version'], $b->getVersion());
22-
}
2363

2464
}
65+
66+
/**
67+
* @dataProvider userAgentStaticProvider
68+
* @param $userAgent string Browser's User Agent
69+
* @param $type string Type of the Browser
70+
* @param $browser string Name of the Browser
71+
* @param $version string Version of the Browser
72+
* @param $osType string Type of operating system associated with the Browser
73+
* @param $osName string Name of the operating system associated with the Browser, typically has the version number
74+
* @param $osVersionName string Version of the Operating System (name)
75+
* @param $osVersionNumber string Version of the Operating System (number)
76+
*/
77+
public function testStaticUserAgent($userAgent,$browser,$version,$platform,$mobile)
78+
{
79+
$b = new Browser($userAgent);
80+
81+
$this->assertSame((string)$browser, $b->getBrowser());
82+
$this->assertSame((string)$version, $b->getVersion());
83+
$this->assertSame((string)$platform, $b->getPlatform());
84+
$this->assertSame((boolean)$mobile, $b->isMobile());
85+
}
2586
}

0 commit comments

Comments
 (0)