Skip to content
This repository has been archived by the owner on Nov 15, 2020. It is now read-only.

Commit

Permalink
Merge pull request #49 from elricho/master
Browse files Browse the repository at this point in the history
logging tweaked, tests added & updated.
  • Loading branch information
elricho authored Nov 24, 2016
2 parents 52237d5 + 90080ac commit 28a22d6
Show file tree
Hide file tree
Showing 3 changed files with 67 additions and 18 deletions.
2 changes: 1 addition & 1 deletion src/HD4.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ class HD4 extends HDBase {
'retries' => 3,
'cache_requests' => false,
'geoip' => false,
'log_unknown' => true
'log_unknown' => false
);

var $tree = array();
Expand Down
15 changes: 9 additions & 6 deletions src/HDBase.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
}
68 changes: 57 additions & 11 deletions tests/hd4Test.php
Original file line number Diff line number Diff line change
Expand Up @@ -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']);
}

/**
Expand All @@ -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 ******************************************
// ***************************************************************************************************
Expand Down Expand Up @@ -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']);
}

/**
Expand All @@ -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 **************************************
// ***************************************************************************************************
Expand Down Expand Up @@ -1307,7 +1354,6 @@ function test_ultimate_community_deviceDetectHTTPDesktopJunk() {
$headers = array(
'User-Agent' => 'aksjakdjkjdaiwdidjkjdkawjdijwidawjdiajwdkawdjiwjdiawjdwidjwakdjajdkad'
);

$result = $hd->deviceDetect($headers);
$reply = $hd->getReply();
//print_r($reply);
Expand Down Expand Up @@ -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']);
Expand Down

0 comments on commit 28a22d6

Please sign in to comment.