diff --git a/lib/phpUserAgentStringParser.php b/lib/phpUserAgentStringParser.php index e33548e..c1aa4b5 100644 --- a/lib/phpUserAgentStringParser.php +++ b/lib/phpUserAgentStringParser.php @@ -39,7 +39,7 @@ public function parse($userAgentString = null) /** * Detect quickly informations from the user agent string - * + * * @param string $userAgentString user agent string * @return array user agent informations array */ @@ -83,7 +83,7 @@ protected function doParse($userAgentString) // Find operating system $pattern = '#'.join('|', $this->getKnownOperatingSystems()).'#'; - + if (preg_match($pattern, $userAgent['string'], $match)) { if (isset($match[0])) @@ -94,7 +94,7 @@ protected function doParse($userAgentString) // Find engine $pattern = '#'.join('|', $this->getKnownEngines()).'#'; - + if (preg_match($pattern, $userAgent['string'], $match)) { if (isset($match[0])) @@ -148,7 +148,7 @@ public function getFilters() /** * Add a filter to be called when parsing a user agent - * + * * @param string $filter name of the filter method */ public function addFilter($filter) @@ -209,7 +209,8 @@ protected function getKnownOperatingSystems() 'linux', 'freebsd', 'unix', - 'iphone' + 'iphone', + 'ipad' ); } diff --git a/test/StringParserTest.php b/test/StringParserTest.php index 5906682..b1e2e7f 100644 --- a/test/StringParserTest.php +++ b/test/StringParserTest.php @@ -80,29 +80,32 @@ 'Mozilla/5.0 (iPhone; U; CPU iPhone OS 3_1_2 like Mac OS X; de-de) AppleWebKit/528.18 (KHTML, like Gecko) Mobile/7D11' => array('applewebkit', '528.18', 'iphone', 'webkit'), - // Motorola Xoom - 'Mozilla/5.0 (Linux; U; Android 3.0; en-us; Xoom Build/HRI39) AppleWebKit/534.13 (KHTML, like Gecko) Version/4.0 Safari/534.13' => - array('android', '3.0', 'android', 'webkit'), + // Motorola Xoom + 'Mozilla/5.0 (Linux; U; Android 3.0; en-us; Xoom Build/HRI39) AppleWebKit/534.13 (KHTML, like Gecko) Version/4.0 Safari/534.13' + => array('android', '3.0', 'android', 'webkit'), - // Samsung Galaxy Tab - 'Mozilla/5.0 (Linux U Android 2.2 es-es GT-P1000 Build/FROYO) AppleWebKit/533.1 (KHTML, like Gecko) Version/4.0 Mobile Safari/533.1' => - array('android', '2.2', 'android', 'webkit'), + // Samsung Galaxy Tab + 'Mozilla/5.0 (Linux U Android 2.2 es-es GT-P1000 Build/FROYO) AppleWebKit/533.1 (KHTML, like Gecko) Version/4.0 Mobile Safari/533.1' + => array('android', '2.2', 'android', 'webkit'), - // Google Nexus - 'Mozilla/5.0 (Linux; U; Android 2.2; en-us; Nexus One Build/FRF91) AppleWebKit/533.1 (KHTML, like Gecko) Version/4.0 Mobile Safari/533.1' => - array('android', '2.2', 'android', 'webkit'), + // Google Nexus + 'Mozilla/5.0 (Linux; U; Android 2.2; en-us; Nexus One Build/FRF91) AppleWebKit/533.1 (KHTML, like Gecko) Version/4.0 Mobile Safari/533.1' + => array('android', '2.2', 'android', 'webkit'), - // HTC Desire + // HTC Desire + 'Mozilla/5.0 (Linux; U; Android 2.1-update1; de-de; HTC Desire 1.19.161.5 Build/ERE27) AppleWebKit/530.17 (KHTML, like Gecko) Version/4.0 Mobile Safari/530.17' + => array('android', '2.1', 'android', 'webkit'), - 'Mozilla/5.0 (Linux; U; Android 2.1-update1; de-de; HTC Desire 1.19.161.5 Build/ERE27) AppleWebKit/530.17 (KHTML, like Gecko) Version/4.0 Mobile Safari/530.17' => - array('android', '2.1', 'android', 'webkit'), + 'Mozilla/5.0 (Linux; U; Android 2.3.6; ru-ru; GT-B5512 Build/GINGERBREAD) AppleWebKit/533.1 (KHTML, like Gecko) Version/4.0 Mobile Safari/533.1' + => array('android', '2.3.6', 'android', 'webkit'), - 'Mozilla/5.0 (Linux; U; Android 2.3.6; ru-ru; GT-B5512 Build/GINGERBREAD) AppleWebKit/533.1 (KHTML, like Gecko) Version/4.0 Mobile Safari/533.1' => - array('android', '2.3.6', 'android', 'webkit'), + // Nexus 7 + 'Mozilla/5.0 (Linux; Android 4.1.1; Nexus 7 Build/JRO03D) AppleWebKit/535.19 (KHTML, like Gecko) Chrome/18.0.1025.166 Safari/535.19' + => array('android', '4.1.1', 'android', 'webkit'), - // Nexus 7 - 'Mozilla/5.0 (Linux; Android 4.1.1; Nexus 7 Build/JRO03D) AppleWebKit/535.19 (KHTML, like Gecko) Chrome/18.0.1025.166 Safari/535.19' => - array('android', '4.1.1', 'android', 'webkit'), + // Ipad + 'Mozilla/5.0 (iPad; CPU OS 6_1_3 like Mac OS X) AppleWebKit/536.26 (KHTML, like Gecko) Version/6.0 Mobile/10B329 Safari/8536.25' + => array('safari', '6.0', 'ipad', 'webkit'), ); $t = new lime_test(count($tests)); @@ -120,6 +123,6 @@ ); $result = $parser->parse($userAgentString); - + $t->is_deeply($result, $expected, $userAgentString.' -> '.implode(', ', $result)); }