From 90080accc7cd13900c55469792a0aa2aab08a00c Mon Sep 17 00:00:00 2001 From: Richard Uren Date: Thu, 24 Nov 2016 16:17:51 +1100 Subject: [PATCH] log_unknown now defaults to false & the logging only runs if php-sockets extension installed. tests updated for changes in live data. tests added for iPhone os overlay checks in build-info detection. --- src/HD4.php | 2 +- src/HDBase.php | 15 ++++++----- tests/hd4Test.php | 68 +++++++++++++++++++++++++++++++++++++++-------- 3 files changed, 67 insertions(+), 18 deletions(-) diff --git a/src/HD4.php b/src/HD4.php index 9899c65..b351d67 100644 --- a/src/HD4.php +++ b/src/HD4.php @@ -67,7 +67,7 @@ class HD4 extends HDBase { 'retries' => 3, 'cache_requests' => false, 'geoip' => false, - 'log_unknown' => true + 'log_unknown' => false ); var $tree = array(); diff --git a/src/HDBase.php b/src/HDBase.php index 81623c6..6793bef 100644 --- a/src/HDBase.php +++ b/src/HDBase.php @@ -615,11 +615,14 @@ function getBranch($branch) { * @return void **/ function send_remote_syslog($headers) { - $headers['version'] = phpversion(); - $headers['apikit'] = $this->apikit; - $sock = @socket_create(AF_INET, SOCK_DGRAM, SOL_UDP); - $message = json_encode($headers); - @socket_sendto($sock, '<22> '.$message, strlen($message), 0, $this->loggerHost, $this->loggerPort); - @socket_close($sock); + // Ensure sockets are installed. + if (function_exists('socket_create')) { + $headers['version'] = phpversion(); + $headers['apikit'] = $this->apikit; + $sock = @socket_create(AF_INET, SOCK_DGRAM, SOL_UDP); + $message = json_encode($headers); + @socket_sendto($sock, '<22> '.$message, strlen($message), 0, $this->loggerHost, $this->loggerPort); + @socket_close($sock); + } } } \ No newline at end of file diff --git a/tests/hd4Test.php b/tests/hd4Test.php index 1db0e57..e01b547 100644 --- a/tests/hd4Test.php +++ b/tests/hd4Test.php @@ -635,11 +635,11 @@ function test_deviceDetectWindowsPhone() { //print_r(json_encode($reply)); $this->assertEquals('Nokia', $reply['hd_specs']['general_vendor']); - $this->assertEquals('Lumia 1020', $reply['hd_specs']['general_model']); + $this->assertEquals('RM-875', $reply['hd_specs']['general_model']); $this->assertEquals('Windows Phone', $reply['hd_specs']['general_platform']); $this->assertEquals('8.0', $reply['hd_specs']['general_platform_version']); $this->assertEquals('Mobile', $reply['hd_specs']['general_type']); - $this->assertEquals('332', $reply['hd_specs']['display_ppi']); + $this->assertEquals('326', $reply['hd_specs']['display_ppi']); } /** @@ -661,13 +661,36 @@ function test_deviceDetectWindowsPhoneB() { //print_r(json_encode($reply)); $this->assertEquals('Nokia', $reply['hd_specs']['general_vendor']); - $this->assertEquals('Lumia 1020', $reply['hd_specs']['general_model']); + $this->assertEquals('RM-875', $reply['hd_specs']['general_model']); $this->assertEquals('Windows Phone', $reply['hd_specs']['general_platform']); $this->assertEquals('8.1', $reply['hd_specs']['general_platform_version']); $this->assertEquals('Mobile', $reply['hd_specs']['general_type']); - $this->assertEquals('332', $reply['hd_specs']['display_ppi']); + $this->assertEquals('326', $reply['hd_specs']['display_ppi']); + } + + /** + * Detection test Windows Phone Native Nokia Lumia 1020 + * @depends test_cloudConfigExists + * @group cloud + **/ + function test_deviceDetectBIiPhoneOverlay() { + $buildInfo = array ( + 'utsname.brand' => 'apple', + 'utsname.machine' => 'iPhone7,2', + 'UIDevice.systemVersion' => '9.2', + 'UIDevice.systemName' => 'iPhone OS' + ); + $hd = new HandsetDetection\HD4($this->cloudConfig); + $result = $hd->deviceDetect($buildInfo); + $reply = $hd->getReply(); + + //print_r(json_encode($reply)); + $this->assertEquals('Apple', $reply['hd_specs']['general_vendor']); + $this->assertEquals('iPhone 6', $reply['hd_specs']['general_model']); + $this->assertEquals('iOS', $reply['hd_specs']['general_platform']); + $this->assertEquals('9.2', $reply['hd_specs']['general_platform_version']); + $this->assertEquals('Mobile', $reply['hd_specs']['general_type']); } - // *************************************************************************************************** // ***************************************** Ultimate Tests ****************************************** // *************************************************************************************************** @@ -1210,11 +1233,11 @@ function test_ultimate_deviceDetectWindowsPhone() { $reply = $hd->getReply(); $this->assertEquals('Nokia', $reply['hd_specs']['general_vendor']); - $this->assertEquals('Lumia 1020', $reply['hd_specs']['general_model']); + $this->assertEquals('RM-875', $reply['hd_specs']['general_model']); $this->assertEquals('Windows Phone', $reply['hd_specs']['general_platform']); $this->assertEquals('8.0', $reply['hd_specs']['general_platform_version']); $this->assertEquals('Mobile', $reply['hd_specs']['general_type']); - $this->assertEquals('332', $reply['hd_specs']['display_ppi']); + $this->assertEquals('326', $reply['hd_specs']['display_ppi']); } /** @@ -1235,13 +1258,37 @@ function test_ultimate_deviceDetectWindowsPhoneB() { $reply = $hd->getReply(); $this->assertEquals('Nokia', $reply['hd_specs']['general_vendor']); - $this->assertEquals('Lumia 1020', $reply['hd_specs']['general_model']); + $this->assertEquals('RM-875', $reply['hd_specs']['general_model']); $this->assertEquals('Windows Phone', $reply['hd_specs']['general_platform']); $this->assertEquals('8.1', $reply['hd_specs']['general_platform_version']); $this->assertEquals('Mobile', $reply['hd_specs']['general_type']); - $this->assertEquals('332', $reply['hd_specs']['display_ppi']); + $this->assertEquals('326', $reply['hd_specs']['display_ppi']); } + /** + * Detection test Windows Phone Native Nokia Lumia 1020 + * @depends test_fetchArchive + * @group ultimate + **/ + function test_ultimate_deviceDetectBIiPhoneOverlay() { + $buildInfo = array ( + 'utsname.brand' => 'apple', + 'utsname.machine' => 'iPhone7,2', + 'UIDevice.systemVersion' => '9.2', + 'UIDevice.systemName' => 'iPhone OS' + ); + $hd = new HandsetDetection\HD4($this->cloudConfig); + $result = $hd->deviceDetect($buildInfo); + $reply = $hd->getReply(); + + //print_r(json_encode($reply)); + $this->assertEquals('Apple', $reply['hd_specs']['general_vendor']); + $this->assertEquals('iPhone 6', $reply['hd_specs']['general_model']); + $this->assertEquals('iOS', $reply['hd_specs']['general_platform']); + $this->assertEquals('9.2', $reply['hd_specs']['general_platform_version']); + $this->assertEquals('Mobile', $reply['hd_specs']['general_type']); + } + // *************************************************************************************************** // *********************************** Ultimate Community Tests ************************************** // *************************************************************************************************** @@ -1307,7 +1354,6 @@ function test_ultimate_community_deviceDetectHTTPDesktopJunk() { $headers = array( 'User-Agent' => 'aksjakdjkjdaiwdidjkjdkawjdijwidawjdiajwdkawdjiwjdiawjdwidjwakdjajdkad' ); - $result = $hd->deviceDetect($headers); $reply = $hd->getReply(); //print_r($reply); @@ -1627,7 +1673,7 @@ function test_ultimate_community_deviceDetectWindowsPhone() { $reply = $hd->getReply(); $this->assertEquals('Nokia', $reply['hd_specs']['general_vendor']); - $this->assertEquals('Lumia 1020', $reply['hd_specs']['general_model']); + $this->assertEquals('RM-875', $reply['hd_specs']['general_model']); $this->assertEquals('Windows Phone', $reply['hd_specs']['general_platform']); $this->assertEquals('', $reply['hd_specs']['general_type']); $this->assertEquals(0, $reply['hd_specs']['display_ppi']);