Remove useless properties from rcube_browser

pull/6911/head
Aleksander Machniak 5 years ago
parent 0786ab8187
commit f5d6a242a8

@ -25,24 +25,65 @@
*/
class rcube_browser
{
function __construct()
/** @var float $ver Browser version */
public $ver = 0;
/** @var bool $win Browser OS is Windows */
public $win = false;
/** @var bool $mac Browser OS is Mac */
public $mac = false;
/** @var bool $linux Browser OS is Linux */
public $linux = false;
/** @var bool $unix Browser OS is Unix */
public $unix = false;
/** @var bool $webkit Browser uses WebKit engine */
public $webkit = false;
/** @var bool $opera Browser is Opera */
public $opera = false;
/** @var bool $chrome Browser is Chrome */
public $chrome = false;
/** @var bool $ie Browser is Internet Explorer */
public $ie = false;
/** @var bool $safari Browser is Safari */
public $safari = false;
/** @var bool $mz Browser is Mozilla Firefox */
public $mz = false;
/** @var string $lang Language code */
public $lang = 'en';
/**
* Object construstor
*/
public function __construct()
{
$HTTP_USER_AGENT = strtolower($_SERVER['HTTP_USER_AGENT']);
$this->ver = 0;
// Operating system detection
$this->win = strpos($HTTP_USER_AGENT, 'win') != false;
$this->mac = strpos($HTTP_USER_AGENT, 'mac') != false;
$this->linux = strpos($HTTP_USER_AGENT, 'linux') != false;
$this->unix = strpos($HTTP_USER_AGENT, 'unix') != false;
// Engine detection
$this->webkit = strpos($HTTP_USER_AGENT, 'applewebkit') !== false;
$this->opera = strpos($HTTP_USER_AGENT, 'opera') !== false || ($this->webkit && strpos($HTTP_USER_AGENT, 'opr/') !== false);
$this->ns = strpos($HTTP_USER_AGENT, 'netscape') !== false;
$this->chrome = !$this->opera && strpos($HTTP_USER_AGENT, 'chrome') !== false;
$this->ie = !$this->opera && (strpos($HTTP_USER_AGENT, 'compatible; msie') !== false || strpos($HTTP_USER_AGENT, 'trident/') !== false);
$this->safari = !$this->opera && !$this->chrome && ($this->webkit || strpos($HTTP_USER_AGENT, 'safari') !== false);
$this->mz = !$this->ie && !$this->safari && !$this->chrome && !$this->ns && !$this->opera && strpos($HTTP_USER_AGENT, 'mozilla') !== false;
$this->mz = !$this->ie && !$this->safari && !$this->chrome && !$this->opera && strpos($HTTP_USER_AGENT, 'mozilla') !== false;
// Version detection
if ($this->opera) {
if (preg_match('/(opera|opr)\/([0-9.]+)/', $HTTP_USER_AGENT, $regs)) {
$this->ver = (float) $regs[2];
@ -55,16 +96,9 @@ class rcube_browser
$this->ver = (float) $regs[1];
}
// Language code
if (preg_match('/ ([a-z]{2})-([a-z]{2})/', $HTTP_USER_AGENT, $regs)) {
$this->lang = $regs[1];
}
else {
$this->lang = 'en';
}
$this->dom = $this->mz || $this->safari || ($this->ie && $this->ver>=5) || ($this->opera && $this->ver>=7);
$this->pngalpha = $this->mz || $this->safari || ($this->ie && $this->ver>=5.5) ||
($this->ie && $this->ver>=5 && $this->mac) || ($this->opera && $this->ver>=7);
$this->imgdata = !$this->ie;
}
}

@ -23,13 +23,11 @@ class Framework_Browser extends PHPUnit_Framework_TestCase
*/
function test_browser($useragent, $opera, $chrome, $ie, $ns, $safari, $mz)
{
$object = $this->getBrowser($useragent);
$this->assertEquals($opera, $object->opera, 'Check for Opera failed');
$this->assertEquals($chrome, $object->chrome, 'Check for Chrome failed');
$this->assertEquals($ie, $object->ie, 'Check for IE failed');
$this->assertEquals($ns, $object->ns, 'Check for NS failed');
$this->assertEquals($safari, $object->safari, 'Check for Safari failed');
$this->assertEquals($mz, $object->mz, 'Check for MZ failed');
}
@ -57,49 +55,11 @@ class Framework_Browser extends PHPUnit_Framework_TestCase
$this->assertEquals($version, $object->ver);
}
/**
* @dataProvider dom
*/
function test_dom($useragent, $dom)
{
$object = $this->getBrowser($useragent);
$this->assertEquals($dom, $object->dom);
}
/**
* @dataProvider pngalpha
*/
function test_pngalpha($useragent, $pngalpha)
{
$object = $this->getBrowser($useragent);
$this->assertEquals($pngalpha, $object->pngalpha);
}
/**
* @dataProvider imgdata
*/
function test_imgdata($useragent, $imgdata)
{
$object = $this->getBrowser($useragent);
$this->assertEquals($imgdata, $object->imgdata);
}
function versions()
{
return $this->extractDataSet(array('version'));
}
function pngalpha()
{
return $this->extractDataSet(array('canPNGALPHA'));
}
function imgdata()
{
return $this->extractDataSet(array('canIMGDATA'));
}
private function extractDataSet($keys)
{
$keys = array_merge(array('useragent'), $keys);
@ -123,11 +83,6 @@ class Framework_Browser extends PHPUnit_Framework_TestCase
return $this->extractDataSet(array('lang'));
}
function dom()
{
return $this->extractDataSet(array('hasDOM'));
}
function browsers()
{
return $this->extractDataSet(array('isOpera','isChrome','isIE','isNS','isSafari','isMZ'));
@ -138,103 +93,84 @@ class Framework_Browser extends PHPUnit_Framework_TestCase
return array(
'WIN: Mozilla Firefox ' => array(
'useragent' => 'Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.0.1) Gecko/20060111 Firefox/1.5.0.1',
'version' => '1.8', //Version
'isWin' => true, //isWindows
'version' => '1.8',
'isWin' => true,
'isLinux' => false,
'isMac' => false, //isMac
'isUnix' => false, //isUnix
'isOpera' => false, //isOpera
'isChrome' => false, //isChrome
'isIE' => false, //isIE
'isNS' => false, //isNS
'isSafari' => false, //isSafari
'isMZ' => true, //isMZ
'lang' => 'en-US', //lang
'hasDOM' => true, //hasDOM
'canPNGALPHA' => true, //canPNGALPHA
'canIMGDATA' => true, //canIMGDATA
'isMac' => false,
'isUnix' => false,
'isOpera' => false,
'isChrome' => false,
'isIE' => false,
'isSafari' => false,
'isMZ' => true,
'lang' => 'en-US',
),
'LINUX: Bon Echo ' => array(
'useragent' => 'Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.8.1.1) Gecko/20070222 BonEcho/2.0.0.1',
'version' => '1.8', //Version
'isWin' => false, //isWindows
'version' => '1.8',
'isWin' => false,
'isLinux' => true,
'isMac' => false, //isMac
'isUnix' => false, //isUnix
'isOpera' => false, //isOpera
'isChrome' => false, //isChrome
'isIE' => false, //isIE
'isNS' => false, //isNS
'isSafari' => false, //isSafari
'isMZ' => true, //isMZ
'lang' => 'en-US', //lang
'hasDOM' => true, //hasDOM
'canPNGALPHA' => true, //canPNGALPHA
'canIMGDATA' => true, //canIMGDATA
'isMac' => false,
'isUnix' => false,
'isOpera' => false,
'isChrome' => false,
'isIE' => false,
'isSafari' => false,
'isMZ' => true,
'lang' => 'en-US',
),
'Chrome Mac' => array(
'useragent' => 'Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10_6_4; en-US) AppleWebKit/534.3 (KHTML, like Gecko) Chrome/6.0.461.0 Safari/534.3',
'version' => '6', //Version
'isWin' => false, //isWindows
'version' => '6',
'isWin' => false,
'isLinux' => false,
'isMac' => true, //isMac
'isUnix' => false, //isUnix
'isOpera' => false, //isOpera
'isChrome' => true, //isChrome
'isIE' => false, //isIE
'isNS' => false, //isNS
'isSafari' => false, //isSafari
'isMZ' => false, //isMZ
'lang' => 'en-US', //lang
'hasDOM' => false, //hasDOM
'canPNGALPHA' => false, //canPNGALPHA
'canIMGDATA' => true, //canIMGDATA
'isMac' => true,
'isUnix' => false,
'isOpera' => false,
'isChrome' => true,
'isIE' => false,
'isSafari' => false,
'isMZ' => false,
'lang' => 'en-US',
),
'IE 11' => array(
'useragent' => 'Mozilla/5.0 (Windows NT 6.3; Trident/7.0; .NET4.0E; .NET4.0C; rv:11.0) like Gecko',
'version' => '11.0', //Version
'isWin' => true, //isWindows
'version' => '11.0',
'isWin' => true,
'isLinux' => false,
'isMac' => false, //isMac
'isUnix' => false, //isUnix
'isOpera' => false, //isOpera
'isChrome' => false, //isChrome
'isIE' => true, //isIE
'isNS' => false, //isNS
'isSafari' => false, //isSafari
'isMZ' => false, //isMZ
'lang' => '', //lang
'hasDOM' => true, //hasDOM
'canPNGALPHA' => true, //canPNGALPHA
'canIMGDATA' => false, //canIMGDATA
'isMac' => false,
'isUnix' => false,
'isOpera' => false,
'isChrome' => false,
'isIE' => true,
'isSafari' => false,
'isMZ' => false,
'lang' => '',
),
'Opera 15' => array(
'useragent' => 'Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/28.0.1500.29 Safari/537.36 OPR/15.0.1147.24',
'version' => '15.0', //Version
'isWin' => true, //isWindows
'version' => '15.0',
'isWin' => true,
'isLinux' => false,
'isMac' => false, //isMac
'isUnix' => false, //isUnix
'isOpera' => true, //isOpera
'isChrome' => false, //isChrome
'isIE' => false, //isIE
'isNS' => false, //isNS
'isSafari' => false, //isSafari
'isMZ' => false, //isMZ
'lang' => '', //lang
'hasDOM' => true, //hasDOM
'canPNGALPHA' => true, //canPNGALPHA
'canIMGDATA' => true, //canIMGDATA
'isMac' => false,
'isUnix' => false,
'isOpera' => true,
'isChrome' => false,
'isIE' => false,
'isSafari' => false,
'isMZ' => false,
'lang' => '',
),
);
}
function os()
{
return $this->extractDataSet(array('isWin','isLinux','isUnix','isMac'));
return $this->extractDataSet(array('isWin', 'isLinux', 'isUnix', 'isMac'));
}
/**

Loading…
Cancel
Save