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 #48 from elricho/master
Browse files Browse the repository at this point in the history
BugFix Ticket 13641
  • Loading branch information
elricho authored Oct 11, 2016
2 parents 70ec620 + d03d433 commit 52237d5
Show file tree
Hide file tree
Showing 3 changed files with 240 additions and 12 deletions.
12 changes: 8 additions & 4 deletions src/HDBase.php
Original file line number Diff line number Diff line change
Expand Up @@ -66,14 +66,18 @@ class HDBase {
),
'platform-bi-order' => array(
'android' => array(
array('ro.build.id', 'ro.build.version.release'),
array('ro-build-id', 'ro-build-version-release'),
array('hd-platform', 'ro.build.version.release'),
array('hd-platform', 'ro-build-version-release'),
array('hd-platform', 'ro.build.id'),
array('hd-platform', 'ro-build-id')
),
'ios' => array(
array('uidevice.systemname','uidevice.systemversion')
array('uidevice.systemname','uidevice.systemversion'),
array('hd-platform','uidevice.systemversion')
),
'windows phone' => array(
array('osname','osversion')
array('osname','osversion'),
array('hd-platform','osversion')
)
),
'browser-bi-order' => array(),
Expand Down
11 changes: 8 additions & 3 deletions src/HDDevice.php
Original file line number Diff line number Diff line change
Expand Up @@ -287,9 +287,12 @@ function findRating($deviceId, $props) {
function specsOverlay($specsField, &$device, $specs) {
switch ($specsField) {
case 'platform' : {
if (! empty($specs['hd_specs']['general_platform'])) {
if (! empty($specs['hd_specs']['general_platform']) && ! empty($specs['hd_specs']['general_platform_version'])) {
$device['Device']['hd_specs']['general_platform'] = $specs['hd_specs']['general_platform'];
$device['Device']['hd_specs']['general_platform_version'] = $specs['hd_specs']['general_platform_version'];
} elseif (! empty($specs['hd_specs']['general_platform']) && $specs['hd_specs']['general_platform'] != $device['Device']['hd_specs']['general_platform']) {
$device['Device']['hd_specs']['general_platform'] = $specs['hd_specs']['general_platform'];
$device['Device']['hd_specs']['general_platform_version'] = '';
}
} break;

Expand Down Expand Up @@ -521,11 +524,13 @@ function v4MatchBIHelper($buildInfo, $category='device') {

$hints = array();
foreach($confBIKeys as $platform => $set) {
$value = '';
foreach($set as $tuple) {
$checking = true;
$value = '';
foreach($tuple as $item) {
if (! isset($buildInfo[$item])) {
if ($item == 'hd-platform') {
$value .= '|'.$platform;
} elseif (! isset($buildInfo[$item])) {
$checking = false;
break;
} else {
Expand Down
229 changes: 224 additions & 5 deletions tests/hd4Test.php
Original file line number Diff line number Diff line change
Expand Up @@ -415,6 +415,27 @@ function test_deviceDetectHTTPFBiOS() {
$this->assertArrayHasKey('benchmark_max', $reply['hd_specs']);
}

/**
* Android version is not supplied in UA & device base profile has more info than detected platform result
* @depends test_cloudConfigExists
* @group cloud
**/
function test_deviceDetectNoPlatformOverlay() {
$hd = new HandsetDetection\HD4($this->cloudConfig);
$headers = array(
'user-agent' => 'Mozilla/5.0 (Linux; U; Android; en-ca; GT-I9500 Build) AppleWebKit/533.1 (KHTML, like Gecko) Version/4.0 Mobile Safari/533.1'
);
$result = $hd->deviceDetect($headers);
$reply = $hd->getReply();
//print_r($reply);
$this->assertTrue($result);
$this->assertEquals('Samsung', $reply['hd_specs']['general_vendor']);
$this->assertEquals('GT-I9500', $reply['hd_specs']['general_model']);
$this->assertEquals('Android', $reply['hd_specs']['general_platform']);
$this->assertEquals('4.2.2', $reply['hd_specs']['general_platform_version']);
$this->assertEquals('Mobile', $reply['hd_specs']['general_type']);
}

/**
* Detection test Samsung GT-I9500 Native - Note : Device shipped with Android 4.2.2, so this device has been updated.
* @depends test_cloudConfigExists
Expand Down Expand Up @@ -465,7 +486,56 @@ function test_deviceDetectBIAndroid() {
$this->assertEquals('Samsung', $reply['hd_specs']['general_vendor']);
$this->assertEquals('GT-I9500', $reply['hd_specs']['general_model']);
$this->assertEquals('Android', $reply['hd_specs']['general_platform']);
//$this->assertEquals('4.4.2', $reply['hd_specs']['general_platform_version']);
$this->assertEquals('4.4.2', $reply['hd_specs']['general_platform_version']);
$this->assertEquals('Samsung Galaxy S4', $reply['hd_specs']['general_aliases'][0]);
$this->assertEquals('Mobile', $reply['hd_specs']['general_type']);
}

/**
* Detection test Samsung GT-I9500 Native - Note : Device shipped with Android 4.2.2, so this device has been updated.
* @depends test_cloudConfigExists
* @group cloud
**/
function test_deviceDetectBIAndroidUpdatedOs() {
$buildInfo = array (
'ro.build.id' => 'KOT49H',
'ro.build.version.release' => '5.2',
'ro.build.version.sdk' => '19',
'ro.product.brand' => 'samsung',
'ro.product.model' => 'GT-I9500',
);

$hd = new HandsetDetection\HD4($this->cloudConfig);
$result = $hd->deviceDetect($buildInfo);
$reply = $hd->getReply();

$this->assertEquals('Samsung', $reply['hd_specs']['general_vendor']);
$this->assertEquals('GT-I9500', $reply['hd_specs']['general_model']);
$this->assertEquals('Android', $reply['hd_specs']['general_platform']);
$this->assertEquals('5.2', $reply['hd_specs']['general_platform_version']);
$this->assertEquals('Samsung Galaxy S4', $reply['hd_specs']['general_aliases'][0]);
$this->assertEquals('Mobile', $reply['hd_specs']['general_type']);
}

/**
* Detection test Samsung GT-I9500 Native - Note : Device shipped with Android 4.2.2, so this device has been updated.
* @depends test_cloudConfigExists
* @group cloud
**/
function test_deviceDetectBIAndroidDefaultOs() {
$buildInfo = array (
'ro.product.brand' => 'samsung',
'ro.product.model' => 'GT-I9500',
);

$hd = new HandsetDetection\HD4($this->cloudConfig);
$result = $hd->deviceDetect($buildInfo);
$reply = $hd->getReply();

$this->assertEquals('Samsung', $reply['hd_specs']['general_vendor']);
$this->assertEquals('GT-I9500', $reply['hd_specs']['general_model']);
$this->assertEquals('Android', $reply['hd_specs']['general_platform']);
$this->assertEquals('4.2.2', $reply['hd_specs']['general_platform_version']);
$this->assertEquals('Samsung Galaxy S4', $reply['hd_specs']['general_aliases'][0]);
$this->assertEquals('Mobile', $reply['hd_specs']['general_type']);
}
Expand All @@ -486,15 +556,42 @@ function test_deviceDetectBIiOS() {
$reply = $hd->getReply();

//print_r(json_encode($reply));

$this->assertEquals('Apple', $reply['hd_specs']['general_vendor']);
$this->assertEquals('iPhone 4S', $reply['hd_specs']['general_model']);
$this->assertEquals('iOS', $reply['hd_specs']['general_platform']);
// Note : Default shipped version in the absence of any version information
$this->assertEquals('5.0', $reply['hd_specs']['general_platform_version']);
$this->assertEquals('Mobile', $reply['hd_specs']['general_type']);
}


/**
* Detection test iPhone 4S Native
* @depends test_cloudConfigExists
* @group cloud
**/
function test_deviceDetectBIiOSUpdatedOs() {
$buildInfo = array (
'utsname.machine' => 'iphone4,1',
'utsname.brand' => 'Apple',
'uidevice.systemVersion' => '5.1',
'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 4S', $reply['hd_specs']['general_model']);
$this->assertEquals('iOS', $reply['hd_specs']['general_platform']);
// Note : Default shipped version is 5.0
$this->assertEquals('5.1', $reply['hd_specs']['general_platform_version']);
$this->assertEquals('Mobile', $reply['hd_specs']['general_type']);
}

/**
* Detection test iPhone 4S Native
* @depends test_cloudConfigExists
Expand Down Expand Up @@ -540,10 +637,37 @@ function test_deviceDetectWindowsPhone() {
$this->assertEquals('Nokia', $reply['hd_specs']['general_vendor']);
$this->assertEquals('Lumia 1020', $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']);
}

/**
* Detection test Windows Phone Native Nokia Lumia 1020
* @depends test_cloudConfigExists
* @group cloud
**/
function test_deviceDetectWindowsPhoneB() {
$buildInfo = array (
'devicemanufacturer' => 'nokia',
'devicename' => 'RM-875',
'osname' => 'windows phone',
'osversion' => '8.1'
);
$hd = new HandsetDetection\HD4($this->cloudConfig);
$result = $hd->deviceDetect($buildInfo);
$reply = $hd->getReply();

//print_r(json_encode($reply));

$this->assertEquals('Nokia', $reply['hd_specs']['general_vendor']);
$this->assertEquals('Lumia 1020', $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']);
}

// ***************************************************************************************************
// ***************************************** Ultimate Tests ******************************************
// ***************************************************************************************************
Expand Down Expand Up @@ -902,6 +1026,27 @@ function test_ultimate_deviceDetectHTTPFBiOS() {
$this->assertArrayHasKey('benchmark_max', $reply['hd_specs']);
}

/**
* Android version is not supplied in UA & device base profile has more info than detected platform result
* @depends test_fetchArchive
* @group ultimate
**/
function test_ultimate_deviceDetectNoPlatformOverlay() {
$hd = new HandsetDetection\HD4($this->ultimateConfig);
$headers = array(
'user-agent' => 'Mozilla/5.0 (Linux; U; Android; en-ca; GT-I9500 Build) AppleWebKit/533.1 (KHTML, like Gecko) Version/4.0 Mobile Safari/533.1'
);
$result = $hd->deviceDetect($headers);
$reply = $hd->getReply();
//print_r($reply);
$this->assertTrue($result);
$this->assertEquals('Samsung', $reply['hd_specs']['general_vendor']);
$this->assertEquals('GT-I9500', $reply['hd_specs']['general_model']);
$this->assertEquals('Android', $reply['hd_specs']['general_platform']);
$this->assertEquals('4.2.2', $reply['hd_specs']['general_platform_version']);
$this->assertEquals('Mobile', $reply['hd_specs']['general_type']);
}

/**
* Samsung GT-I9500 Native - Note : Device shipped with Android 4.2.2, so this device has been updated.
* @depends test_fetchArchive
Expand Down Expand Up @@ -948,12 +1093,60 @@ function test_ultimate_deviceDetectBIAndroid() {
$this->assertEquals('Samsung', $reply['hd_specs']['general_vendor']);
$this->assertEquals('GT-I9500', $reply['hd_specs']['general_model']);
$this->assertEquals('Android', $reply['hd_specs']['general_platform']);
//$this->assertEquals('4.4.2', $reply['hd_specs']['general_platform_version']);
$this->assertEquals('4.4.2', $reply['hd_specs']['general_platform_version']);
$this->assertEquals('Samsung Galaxy S4', $reply['hd_specs']['general_aliases'][0]);
$this->assertEquals('Mobile', $reply['hd_specs']['general_type']);
}

//
/**
* Detection test Samsung GT-I9500 Native - Note : Device shipped with Android 4.2.2, so this device has been updated.
* @depends test_fetchArchive
* @group ultimate
**/
function test_ultimate_deviceDetectBIAndroidUpdatedOs() {
$buildInfo = array (
'ro.build.id' => 'KOT49H',
'ro.build.version.release' => '5.2',
'ro.build.version.sdk' => '19',
'ro.product.brand' => 'samsung',
'ro.product.model' => 'GT-I9500',
);

$hd = new HandsetDetection\HD4($this->ultimateConfig);
$result = $hd->deviceDetect($buildInfo);
$reply = $hd->getReply();

$this->assertEquals('Samsung', $reply['hd_specs']['general_vendor']);
$this->assertEquals('GT-I9500', $reply['hd_specs']['general_model']);
$this->assertEquals('Android', $reply['hd_specs']['general_platform']);
$this->assertEquals('5.2', $reply['hd_specs']['general_platform_version']);
$this->assertEquals('Samsung Galaxy S4', $reply['hd_specs']['general_aliases'][0]);
$this->assertEquals('Mobile', $reply['hd_specs']['general_type']);
}

/**
* Detection test Samsung GT-I9500 Native - Note : Device shipped with Android 4.2.2
* @depends test_fetchArchive
* @group ultimate
**/
function test_ultimate_deviceDetectBIAndroidDefaultOs() {
$buildInfo = array (
'ro.product.brand' => 'samsung',
'ro.product.model' => 'GT-I9500',
);

$hd = new HandsetDetection\HD4($this->ultimateConfig);
$result = $hd->deviceDetect($buildInfo);
$reply = $hd->getReply();

$this->assertEquals('Samsung', $reply['hd_specs']['general_vendor']);
$this->assertEquals('GT-I9500', $reply['hd_specs']['general_model']);
$this->assertEquals('Android', $reply['hd_specs']['general_platform']);
$this->assertEquals('4.2.2', $reply['hd_specs']['general_platform_version']);
$this->assertEquals('Samsung Galaxy S4', $reply['hd_specs']['general_aliases'][0]);
$this->assertEquals('Mobile', $reply['hd_specs']['general_type']);
}

/**
* iPhone 4S Native
* @depends test_fetchArchive
Expand Down Expand Up @@ -1019,6 +1212,32 @@ function test_ultimate_deviceDetectWindowsPhone() {
$this->assertEquals('Nokia', $reply['hd_specs']['general_vendor']);
$this->assertEquals('Lumia 1020', $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']);
}

/**
* Windows Phone Native Nokia Lumia 1020
* @depends test_fetchArchive
* @group ultimate
**/
function test_ultimate_deviceDetectWindowsPhoneB() {
$buildInfo = array (
'devicemanufacturer' => 'nokia',
'devicename' => 'RM-875',
'osname' => 'windows phone',
'osversion' => '8.1'
);

$hd = new HandsetDetection\HD4($this->ultimateConfig);
$result = $hd->deviceDetect($buildInfo);
$reply = $hd->getReply();

$this->assertEquals('Nokia', $reply['hd_specs']['general_vendor']);
$this->assertEquals('Lumia 1020', $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']);
}
Expand Down

0 comments on commit 52237d5

Please sign in to comment.