Skip to content

Commit

Permalink
Added "vendorCheck" in UA tests which will optionally check the "vendor"
Browse files Browse the repository at this point in the history
  • Loading branch information
serbanghita committed Dec 5, 2024
1 parent 7355b68 commit d871711
Show file tree
Hide file tree
Showing 5 changed files with 4,963 additions and 4,908 deletions.
9 changes: 6 additions & 3 deletions MobileDetect.json
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,8 @@
"Amoi": "Amoi",
"INQ": "INQ",
"OnePlus": "ONEPLUS",
"GenericPhone": "Tapatalk|PDA;|SAGEM|\\bmmp\\b|pocket|\\bpsp\\b|symbian|Smartphone|smartfon|treo|up.browser|up.link|vodafone|\\bwap\\b|nokia|Series40|Series60|S60|SonyEricsson|N900|MAUI.*WAP.*Browser"
"GenericPhone": "Tapatalk|PDA;|SAGEM|\\bmmp\\b|pocket|\\bpsp\\b|symbian|Smartphone|smartfon|treo|up.browser|up.link|vodafone|\\bwap\\b|nokia|Series40|Series60|S60|SonyEricsson|N900|MAUI.*WAP.*Browser",
"Huawei": "HMSCore"
},
"tablets": {
"iPad": "iPad|iPad.*Mobile",
Expand Down Expand Up @@ -404,7 +405,8 @@
"ObigoBrowser": "Obigo",
"NetFront": "NF-Browser",
"GenericBrowser": "NokiaBrowser|OviBrowser|OneBrowser|TwonkyBeamBrowser|SEMC.*Browser|FlyFlow|Minimo|NetFront|Novarra-Vision|MQQBrowser|MicroMessenger",
"PaleMoon": "Android.*PaleMoon|Mobile.*PaleMoon"
"PaleMoon": "Android.*PaleMoon|Mobile.*PaleMoon",
"HuaweiBrowser": "HuaweiBrowser"
},
"os": {
"AndroidOS": "Android",
Expand All @@ -421,7 +423,8 @@
"JavaOS": "J2ME\/|\\bMIDP\\b|\\bCLDC\\b",
"webOS": "webOS|hpwOS",
"badaOS": "\\bBada\\b",
"BREWOS": "BREW"
"BREWOS": "BREW",
"HarmonyOS": "HarmonyOS"
}
}
}
4 changes: 2 additions & 2 deletions src/MobileDetect.php
Original file line number Diff line number Diff line change
Expand Up @@ -473,7 +473,7 @@ class MobileDetect
'OnePlus' => 'ONEPLUS',
// @Tapatalk is a mobile app; http://support.tapatalk.com/threads/smf-2-0-2-os-and-browser-detection-plugin-and-tapatalk.15565/#post-79039
'GenericPhone' => 'Tapatalk|PDA;|SAGEM|\bmmp\b|pocket|\bpsp\b|symbian|Smartphone|smartfon|treo|up.browser|up.link|vodafone|\bwap\b|nokia|Series40|Series60|S60|SonyEricsson|N900|MAUI.*WAP.*Browser',
'Huawei' => 'HMSCore',
'Huawei' => 'HMSCore|Huawei',
];

/**
Expand Down Expand Up @@ -615,7 +615,7 @@ class MobileDetect
'bqTablet' => 'Android.*(bq)?.*\b(Elcano|Curie|Edison|Maxwell|Kepler|Pascal|Tesla|Hypatia|Platon|Newton|Livingstone|Cervantes|Avant|Aquaris ([E|M]10|M8))\b|Maxwell.*Lite|Maxwell.*Plus',
// http://www.huaweidevice.com/worldwide/productFamily.do?method=index&directoryId=5011&treeId=3290
// http://www.huaweidevice.com/worldwide/downloadCenter.do?method=index&directoryId=3372&treeId=0&tb=1&type=software (including legacy tablets)
'HuaweiTablet' => 'MediaPad|MediaPad 7 Youth|IDEOS S7|S7-201c|S7-202u|S7-101|S7-103|S7-104|S7-105|S7-106|S7-201|S7-Slim|M2-A01L|BAH-L09|BAH-W09|AGS-L09|CMR-AL19|KOB2-L09|BG2-U01|BG2-W09|BG2-U03',
'HuaweiTablet' => 'MediaPad|MediaPad 7 Youth|IDEOS S7|S7-201c|S7-202u|S7-101|S7-103|S7-104|S7-105|S7-106|S7-201|S7-Slim|M2-A01L|BAH-L09|BAH-W09|AGS-L09|CMR-AL19|KOB2-L09|BG2-U01|BG2-W09|BG2-U03|AGS-W09',
// Nec or Medias Tab
'NecTablet' => '\bN-06D|\bN-08D',
// Pantech Tablets: http://www.pantechusa.com/phones/
Expand Down
19 changes: 14 additions & 5 deletions tests/UserAgentTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,12 @@ public static function generateJson()
'user_agent' => $userAgent
);

// Get all dynamic functions to allow test checking.
// e.g. "isHuawei"
// $tmpDynamicFunctions = array_filter($props, function($value) {
// return !in_array($value, ['isMobile', 'isTablet', 'version', 'model']);
// });

if (isset($props['isMobile'])) {
$tmp['mobile'] = $props['isMobile'];
}
Expand All @@ -92,6 +98,10 @@ public static function generateJson()
$tmp['model'] = $props['model'];
}

if (isset($props['vendorCheck'])) {
$tmp['vendorCheck'] = $props['vendorCheck'];
}

$json[] = $tmp;
}
}
Expand Down Expand Up @@ -132,6 +142,7 @@ public static function setUpBeforeClass(): void
$tmp[] = $userAgent['version'] ?? null;
$tmp[] = $userAgent['model'] ?? null;
$tmp[] = $userAgent['vendor'] ?? null;
$tmp[] = $userAgent['vendorCheck'] ?? null;

self::$userAgentList[] = $tmp;
}
Expand All @@ -151,7 +162,7 @@ public function userAgentData(): array
* @dataProvider userAgentData
* @throws MobileDetectException
*/
public function testUserAgents($userAgent, $isMobile, $isTablet, $version, $model, $vendor)
public function testUserAgents($userAgent, $isMobile, $isTablet, $version, $model, $vendor, $vendorCheck = false)
{
//make sure we're passed valid data
if (!is_string($userAgent) || !is_bool($isMobile) || !is_bool($isTablet)) {
Expand Down Expand Up @@ -181,12 +192,10 @@ public function testUserAgents($userAgent, $isMobile, $isTablet, $version, $mode
}
}

//@todo: model test, not sure how exactly yet
//@todo: vendor test. The below is theoretical, but fails 50% of the tests...
/*if (isset($vendor)) {
if (isset($vendorCheck) && $vendorCheck === true) {
$method = "is$vendor";
$this->assertTrue($this->detect->{$method}(), "Expected Mobile_Detect::{$method}() to be true.");
}*/
}
}

/**
Expand Down
47 changes: 25 additions & 22 deletions tests/providers/vendors/Huawei.php
Original file line number Diff line number Diff line change
@@ -1,34 +1,37 @@
<?php

return [
'Huwaei' => [
'Huawei' => [
'Mozilla/5.0 (Linux; U; Android 2.1-update1; bg-bg; Ideos S7 Build/ERE27) AppleWebKit/525.10+ (KHTML, like Gecko) Version/3.0.4 Mobile Safari/523.12.2' => ['isMobile' => true, 'isTablet' => true],
'Mozilla/5.0 (Linux; U; Android 2.1; en-us; Ideos S7 Build/ERE27) AppleWebKit/525.10+ (KHTML, like Gecko) Version/3.0.4 Mobile Safari/523.12.2' => ['isMobile' => true, 'isTablet' => true],
'Mozilla/5.0 (Linux; U; Android 2.3.6; lt-lt; U8660 Build/HuaweiU8660) AppleWebKit/533.1 (KHTML, like Gecko) Version/4.0 Mobile Safari/533.1' => ['isMobile' => true, 'isTablet' => false],
'Mozilla/5.0 (Linux; U; Android 2.3.7; ru-ru; HUAWEI-U8850 Build/HuaweiU8850) AppleWebKit/533.1 (KHTML, like Gecko) Version/4.0 Mobile Safari/533.1' => ['isMobile' => true, 'isTablet' => false],
'Mozilla/5.0 (Linux; U; Android 3.2; pl-pl; MediaPad Build/HuaweiMediaPad) AppleWebKit/534.13 (KHTML, like Gecko) Version/4.0 Safari/534.13' => ['isMobile' => true, 'isTablet' => true],
'Mozilla/5.0 (Linux; U; Android 3.2; nl-nl; HUAWEI MediaPad Build/HuaweiMediaPad) AppleWebKit/534.13 (KHTML, like Gecko) Version/4.0 Safari/534.13' => ['isMobile' => true, 'isTablet' => true],
'HUAWEI_T8951_TD/1.0 Android/4.0.4 (Linux; U; Android 4.0.4; zh-cn) Release/05.31.2012 Browser/WAP2.0 (AppleWebKit/534.30) Mobile Safari/534.30' => ['isMobile' => true, 'isTablet' => false],
'Mozilla/5.0 (Linux; U; Android 4.1.2; ar-eg; MediaPad 7 Youth Build/HuaweiMediaPad) AppleWebKit/534.30 (KHTML, like Gecko) Version/4.0 Safari/534.30' => ['isMobile' => true, 'isTablet' => true],
'Mozilla/5.0 (Linux; U; Android 4.1.2; zh-cn; HW-HUAWEI_C8815/C8815V100R001C541B135; 540*960; CTC/2.0) AppleWebKit/534.30 (KHTML, like Gecko) Mobile Safari/534.30' => ['isMobile' => true, 'isTablet' => false],
'Mozilla/5.0 (Linux; U; Android 4.1.1; zh-cn; HW-HUAWEI_C8813D/C8813DV100R001C92B172; 480*854; CTC/2.0) AppleWebKit/534.30 (KHTML, like Gecko) Mobile Safari/534.30' => ['isMobile' => true, 'isTablet' => false],
'Mozilla/5.0 (Linux; U; Android 4.1.1; zh-cn; HW-HUAWEI_Y300C/Y300CV100R001C92B168; 480*800; CTC/2.0) AppleWebKit/534.30 (KHTML, like Gecko) Mobile Safari/534.30' => ['isMobile' => true, 'isTablet' => false],
'Mozilla/5.0 (Linux; U; Android 4.2.2; id-id; HUAWEI Y330-U11 Build/HuaweiY330-U11) AppleWebKit/537.16 (KHTML, like Gecko) Version/4.0 Mobile Safari/537.16 Chrome/33.0.0.0' => ['isMobile' => true, 'isTablet' => false],
'Mozilla/5.0 (Linux; Android 5.1.1; HUAWEI M2-A01L Build/HUAWEIM2-A01L) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/59.0.3071.125 Safari/537.36' => ['isMobile' => true, 'isTablet' => true],
'Mozilla/5.0 (Linux; Android 6.0; HUAWEI GRA-L09 Build/HUAWEIGRA-L09) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/63.0.3239.111 Mobile Safari/537.36' => ['isMobile' => true, 'isTablet' => false],
'Mozilla/5.0 (Linux; Android 7.0; FRD-L09 Build/HUAWEIFRD-L09) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/63.0.3239.111 Mobile Safari/537.36' => ['isMobile' => true, 'isTablet' => false],
'Mozilla/5.0 (Linux; Android 8.0; DUK-AL20 Build/HUAWEIDUK-AL20; wv) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/57.0.2987.132 MQQBrowser/6.2 TBS/044054 Mobile Safari/537.36 V1_AND_SQ_7.5.8_818_YYB_D QQ/7.5.8.3490 NetType/WIFI WebP/0.3.0 Pixe' => ['isMobile' => true, 'isTablet' => false],
'Mozilla/5.0 (Linux; Android 7.0; BAH-L09 Build/HUAWEIBAH-L09) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/66.0.3359.126 Safari/537.36' => ['isMobile' => true, 'isTablet' => true],
'Mozilla/5.0 (Linux; Android 7.0; BAH-W09 Build/HUAWEIBAH-W09) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/62.0.3202.84 Safari/537.36' => ['isMobile' => true, 'isTablet' => true],
'Mozilla/5.0 (Linux; Android 7.0; WAS-LX3 Build/HUAWEIWAS-LX3; wv) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/63.0.3239.111 Mobile Safari/537.36 [FB_IAB/Orca-Android;FBAV/162.0.0.19.90;]' => ['isMobile' => true, 'isTablet' => false],
'Mozilla/5.0 (Linux; U; Android 2.3.6; lt-lt; U8660 Build/HuaweiU8660) AppleWebKit/533.1 (KHTML, like Gecko) Version/4.0 Mobile Safari/533.1' => ['isMobile' => true, 'isTablet' => false, 'vendorCheck' => true],
'Mozilla/5.0 (Linux; U; Android 2.3.7; ru-ru; HUAWEI-U8850 Build/HuaweiU8850) AppleWebKit/533.1 (KHTML, like Gecko) Version/4.0 Mobile Safari/533.1' => ['isMobile' => true, 'isTablet' => false, 'vendorCheck' => true],
'Mozilla/5.0 (Linux; U; Android 3.2; pl-pl; MediaPad Build/HuaweiMediaPad) AppleWebKit/534.13 (KHTML, like Gecko) Version/4.0 Safari/534.13' => ['isMobile' => true, 'isTablet' => true, 'vendorCheck' => true],
'Mozilla/5.0 (Linux; U; Android 3.2; nl-nl; HUAWEI MediaPad Build/HuaweiMediaPad) AppleWebKit/534.13 (KHTML, like Gecko) Version/4.0 Safari/534.13' => ['isMobile' => true, 'isTablet' => true, 'vendorCheck' => true],
'HUAWEI_T8951_TD/1.0 Android/4.0.4 (Linux; U; Android 4.0.4; zh-cn) Release/05.31.2012 Browser/WAP2.0 (AppleWebKit/534.30) Mobile Safari/534.30' => ['isMobile' => true, 'isTablet' => false, 'vendorCheck' => true],
'Mozilla/5.0 (Linux; U; Android 4.1.2; ar-eg; MediaPad 7 Youth Build/HuaweiMediaPad) AppleWebKit/534.30 (KHTML, like Gecko) Version/4.0 Safari/534.30' => ['isMobile' => true, 'isTablet' => true, 'vendorCheck' => true],
'Mozilla/5.0 (Linux; U; Android 4.1.2; zh-cn; HW-HUAWEI_C8815/C8815V100R001C541B135; 540*960; CTC/2.0) AppleWebKit/534.30 (KHTML, like Gecko) Mobile Safari/534.30' => ['isMobile' => true, 'isTablet' => false, 'vendorCheck' => true],
'Mozilla/5.0 (Linux; U; Android 4.1.1; zh-cn; HW-HUAWEI_C8813D/C8813DV100R001C92B172; 480*854; CTC/2.0) AppleWebKit/534.30 (KHTML, like Gecko) Mobile Safari/534.30' => ['isMobile' => true, 'isTablet' => false, 'vendorCheck' => true],
'Mozilla/5.0 (Linux; U; Android 4.1.1; zh-cn; HW-HUAWEI_Y300C/Y300CV100R001C92B168; 480*800; CTC/2.0) AppleWebKit/534.30 (KHTML, like Gecko) Mobile Safari/534.30' => ['isMobile' => true, 'isTablet' => false, 'vendorCheck' => true],
'Mozilla/5.0 (Linux; U; Android 4.2.2; id-id; HUAWEI Y330-U11 Build/HuaweiY330-U11) AppleWebKit/537.16 (KHTML, like Gecko) Version/4.0 Mobile Safari/537.16 Chrome/33.0.0.0' => ['isMobile' => true, 'isTablet' => false, 'vendorCheck' => true],
'Mozilla/5.0 (Linux; Android 5.1.1; HUAWEI M2-A01L Build/HUAWEIM2-A01L) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/59.0.3071.125 Safari/537.36' => ['isMobile' => true, 'isTablet' => true, 'vendorCheck' => true],
'Mozilla/5.0 (Linux; Android 6.0; HUAWEI GRA-L09 Build/HUAWEIGRA-L09) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/63.0.3239.111 Mobile Safari/537.36' => ['isMobile' => true, 'isTablet' => false, 'vendorCheck' => true],
'Mozilla/5.0 (Linux; Android 7.0; FRD-L09 Build/HUAWEIFRD-L09) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/63.0.3239.111 Mobile Safari/537.36' => ['isMobile' => true, 'isTablet' => false, 'vendorCheck' => true],
'Mozilla/5.0 (Linux; Android 8.0; DUK-AL20 Build/HUAWEIDUK-AL20; wv) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/57.0.2987.132 MQQBrowser/6.2 TBS/044054 Mobile Safari/537.36 V1_AND_SQ_7.5.8_818_YYB_D QQ/7.5.8.3490 NetType/WIFI WebP/0.3.0 Pixe' => ['isMobile' => true, 'isTablet' => false, 'vendorCheck' => true],
'Mozilla/5.0 (Linux; Android 7.0; BAH-L09 Build/HUAWEIBAH-L09) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/66.0.3359.126 Safari/537.36' => ['isMobile' => true, 'isTablet' => true, 'vendorCheck' => true],
'Mozilla/5.0 (Linux; Android 7.0; BAH-W09 Build/HUAWEIBAH-W09) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/62.0.3202.84 Safari/537.36' => ['isMobile' => true, 'isTablet' => true, 'vendorCheck' => true],
'Mozilla/5.0 (Linux; Android 7.0; WAS-LX3 Build/HUAWEIWAS-LX3; wv) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/63.0.3239.111 Mobile Safari/537.36 [FB_IAB/Orca-Android;FBAV/162.0.0.19.90;]' => ['isMobile' => true, 'isTablet' => false, 'vendorCheck' => true],
'Mozilla/5.0 (Linux; Android 8.1.0; Nexus 6P Build/OPM3.171019.014) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/64.0.3282.137 Mobile Safari/537.36' => ['isMobile' => true, 'isTablet' => false],
'Mozilla/5.0 (Linux; Android 8.0.0; CMR-AL19 Build/HUAWEICMR-AL19) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/68.0.3440.70 Safari/537.36' => ['isMobile' => true, 'isTablet' => true],
'Mozilla/5.0 (Linux; Android 7.0; AGS-L09 Build/HUAWEIAGS-L09; xx-xx) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/59.0.3071.125 Safari/537.36' => ['isMobile' => true, 'isTablet' => true],
'Mozilla/5.0 (Linux; Android 8.0.0; CMR-AL19 Build/HUAWEICMR-AL19) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/68.0.3440.70 Safari/537.36' => ['isMobile' => true, 'isTablet' => true, 'vendorCheck' => true],
'Mozilla/5.0 (Linux; Android 7.0; AGS-L09 Build/HUAWEIAGS-L09; xx-xx) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/59.0.3071.125 Safari/537.36' => ['isMobile' => true, 'isTablet' => true, 'vendorCheck' => true],
'Mozilla/5.0 (Linux; Android 8.0.0; EDI-AL10 Build/HUAWEIEDISON-AL10; wv) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/72.0.3626.121 Mobile Safari/537.36' => ['isMobile' => true, 'isTablet' => false],
'Mozilla/5.0 (Linux; U; Android 4.1.1; cs-cz; HUAWEI G510-0200 Build/HuaweiG510-0200) AppleWebKit/534.30 (KHTML, like Gecko) Version/4.0 Mobile Safari/534.30' => ['isMobile' => true, 'isTablet' => false],
'Mozilla/5.0 (Linux; U; Android 4.1.1; cs-cz; HUAWEI G510-0200 Build/HuaweiG510-0200) AppleWebKit/534.30 (KHTML, like Gecko) Version/4.0 Mobile Safari/534.30' => ['isMobile' => true, 'isTablet' => false, 'vendorCheck' => true],
'Mozilla/5.0 (Linux; Android 10; KOB2-L09) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/92.0.4515.166 Safari/537.36 OPR/65.1.3381.61266' => ['isMobile' => true, 'isTablet' => true],
'Mozilla/5.0 (Linux; Android 7.0; BG2-U03) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.101 Mobile Safari/537.36' => ['isMobile' => true, 'isTablet' => true],
'Mozilla/5.0 (Linux; Android 6.0; BG2-W09 Build/HuaweiBAGGIO2; wv) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/55.0.2883.91 Mobile Safari/537.36' => ['isMobile' => true, 'isTablet' => true],
'Mozilla/5.0 (Linux; Android 6.0; BG2-W09 Build/HuaweiBAGGIO2; wv) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/55.0.2883.91 Mobile Safari/537.36' => ['isMobile' => true, 'isTablet' => true, 'vendorCheck' => true],
'Mozilla/5.0 (Linux; Android 10; MAR-LX1B; HMSCore 6.13.0.322; GMSCore 24.15.15) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/99.0.4844.88 HuaweiBrowser/14.0.5.302 Mobile Safari/537.36' => ['isMobile' => true, 'isTablet' => false, 'vendorCheck' => true],
'Mozilla/5.0 (Linux; Android 10; SPN-AL00 Build/HUAWEISPN-AL00; wv) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/116.0.0.0 Mobile Safari/537.36 XWEB/1160055 MMWEBSDK/20231201 MMWEBID/4954 MicroMessenger/8.0.45.2521(0x28002DCE) WeChat/arm64 Weixin NetType/WIFI Language/zh_CN ABI/arm64' => ['isMobile' => true, 'isTablet' => false, 'vendorCheck' => true],
'Mozilla/5.0 (Linux; Android 8.0.0; AGS-W09) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/92.0.4515.159 Safari/537.36' => ['isMobile' => true, 'isTablet' => true],
],

];
Loading

0 comments on commit d871711

Please sign in to comment.