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 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']); $HTTP_USER_AGENT = strtolower($_SERVER['HTTP_USER_AGENT']);
$this->ver = 0; // Operating system detection
$this->win = strpos($HTTP_USER_AGENT, 'win') != false; $this->win = strpos($HTTP_USER_AGENT, 'win') != false;
$this->mac = strpos($HTTP_USER_AGENT, 'mac') != false; $this->mac = strpos($HTTP_USER_AGENT, 'mac') != false;
$this->linux = strpos($HTTP_USER_AGENT, 'linux') != false; $this->linux = strpos($HTTP_USER_AGENT, 'linux') != false;
$this->unix = strpos($HTTP_USER_AGENT, 'unix') != false; $this->unix = strpos($HTTP_USER_AGENT, 'unix') != false;
// Engine detection
$this->webkit = strpos($HTTP_USER_AGENT, 'applewebkit') !== false; $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->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->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->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->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 ($this->opera) {
if (preg_match('/(opera|opr)\/([0-9.]+)/', $HTTP_USER_AGENT, $regs)) { if (preg_match('/(opera|opr)\/([0-9.]+)/', $HTTP_USER_AGENT, $regs)) {
$this->ver = (float) $regs[2]; $this->ver = (float) $regs[2];
@ -55,16 +96,9 @@ class rcube_browser
$this->ver = (float) $regs[1]; $this->ver = (float) $regs[1];
} }
// Language code
if (preg_match('/ ([a-z]{2})-([a-z]{2})/', $HTTP_USER_AGENT, $regs)) { if (preg_match('/ ([a-z]{2})-([a-z]{2})/', $HTTP_USER_AGENT, $regs)) {
$this->lang = $regs[1]; $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) function test_browser($useragent, $opera, $chrome, $ie, $ns, $safari, $mz)
{ {
$object = $this->getBrowser($useragent); $object = $this->getBrowser($useragent);
$this->assertEquals($opera, $object->opera, 'Check for Opera failed'); $this->assertEquals($opera, $object->opera, 'Check for Opera failed');
$this->assertEquals($chrome, $object->chrome, 'Check for Chrome failed'); $this->assertEquals($chrome, $object->chrome, 'Check for Chrome failed');
$this->assertEquals($ie, $object->ie, 'Check for IE 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($safari, $object->safari, 'Check for Safari failed');
$this->assertEquals($mz, $object->mz, 'Check for MZ 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); $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() function versions()
{ {
return $this->extractDataSet(array('version')); return $this->extractDataSet(array('version'));
} }
function pngalpha()
{
return $this->extractDataSet(array('canPNGALPHA'));
}
function imgdata()
{
return $this->extractDataSet(array('canIMGDATA'));
}
private function extractDataSet($keys) private function extractDataSet($keys)
{ {
$keys = array_merge(array('useragent'), $keys); $keys = array_merge(array('useragent'), $keys);
@ -123,11 +83,6 @@ class Framework_Browser extends PHPUnit_Framework_TestCase
return $this->extractDataSet(array('lang')); return $this->extractDataSet(array('lang'));
} }
function dom()
{
return $this->extractDataSet(array('hasDOM'));
}
function browsers() function browsers()
{ {
return $this->extractDataSet(array('isOpera','isChrome','isIE','isNS','isSafari','isMZ')); return $this->extractDataSet(array('isOpera','isChrome','isIE','isNS','isSafari','isMZ'));
@ -138,103 +93,84 @@ class Framework_Browser extends PHPUnit_Framework_TestCase
return array( return array(
'WIN: Mozilla Firefox ' => 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', '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 'version' => '1.8',
'isWin' => true, //isWindows 'isWin' => true,
'isLinux' => false, 'isLinux' => false,
'isMac' => false, //isMac 'isMac' => false,
'isUnix' => false, //isUnix 'isUnix' => false,
'isOpera' => false, //isOpera 'isOpera' => false,
'isChrome' => false, //isChrome 'isChrome' => false,
'isIE' => false, //isIE 'isIE' => false,
'isNS' => false, //isNS 'isSafari' => false,
'isSafari' => false, //isSafari 'isMZ' => true,
'isMZ' => true, //isMZ 'lang' => 'en-US',
'lang' => 'en-US', //lang
'hasDOM' => true, //hasDOM
'canPNGALPHA' => true, //canPNGALPHA
'canIMGDATA' => true, //canIMGDATA
), ),
'LINUX: Bon Echo ' => array( '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', '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 'version' => '1.8',
'isWin' => false, //isWindows 'isWin' => false,
'isLinux' => true, 'isLinux' => true,
'isMac' => false, //isMac 'isMac' => false,
'isUnix' => false, //isUnix 'isUnix' => false,
'isOpera' => false, //isOpera 'isOpera' => false,
'isChrome' => false, //isChrome 'isChrome' => false,
'isIE' => false, //isIE 'isIE' => false,
'isNS' => false, //isNS 'isSafari' => false,
'isSafari' => false, //isSafari 'isMZ' => true,
'isMZ' => true, //isMZ 'lang' => 'en-US',
'lang' => 'en-US', //lang
'hasDOM' => true, //hasDOM
'canPNGALPHA' => true, //canPNGALPHA
'canIMGDATA' => true, //canIMGDATA
), ),
'Chrome Mac' => array( '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', '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 'version' => '6',
'isWin' => false, //isWindows 'isWin' => false,
'isLinux' => false, 'isLinux' => false,
'isMac' => true, //isMac 'isMac' => true,
'isUnix' => false, //isUnix 'isUnix' => false,
'isOpera' => false, //isOpera 'isOpera' => false,
'isChrome' => true, //isChrome 'isChrome' => true,
'isIE' => false, //isIE 'isIE' => false,
'isNS' => false, //isNS 'isSafari' => false,
'isSafari' => false, //isSafari 'isMZ' => false,
'isMZ' => false, //isMZ 'lang' => 'en-US',
'lang' => 'en-US', //lang
'hasDOM' => false, //hasDOM
'canPNGALPHA' => false, //canPNGALPHA
'canIMGDATA' => true, //canIMGDATA
), ),
'IE 11' => array( 'IE 11' => array(
'useragent' => 'Mozilla/5.0 (Windows NT 6.3; Trident/7.0; .NET4.0E; .NET4.0C; rv:11.0) like Gecko', 'useragent' => 'Mozilla/5.0 (Windows NT 6.3; Trident/7.0; .NET4.0E; .NET4.0C; rv:11.0) like Gecko',
'version' => '11.0', //Version 'version' => '11.0',
'isWin' => true, //isWindows 'isWin' => true,
'isLinux' => false, 'isLinux' => false,
'isMac' => false, //isMac 'isMac' => false,
'isUnix' => false, //isUnix 'isUnix' => false,
'isOpera' => false, //isOpera 'isOpera' => false,
'isChrome' => false, //isChrome 'isChrome' => false,
'isIE' => true, //isIE 'isIE' => true,
'isNS' => false, //isNS 'isSafari' => false,
'isSafari' => false, //isSafari 'isMZ' => false,
'isMZ' => false, //isMZ 'lang' => '',
'lang' => '', //lang
'hasDOM' => true, //hasDOM
'canPNGALPHA' => true, //canPNGALPHA
'canIMGDATA' => false, //canIMGDATA
), ),
'Opera 15' => array( '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', '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 'version' => '15.0',
'isWin' => true, //isWindows 'isWin' => true,
'isLinux' => false, 'isLinux' => false,
'isMac' => false, //isMac 'isMac' => false,
'isUnix' => false, //isUnix 'isUnix' => false,
'isOpera' => true, //isOpera 'isOpera' => true,
'isChrome' => false, //isChrome 'isChrome' => false,
'isIE' => false, //isIE 'isIE' => false,
'isNS' => false, //isNS 'isSafari' => false,
'isSafari' => false, //isSafari 'isMZ' => false,
'isMZ' => false, //isMZ 'lang' => '',
'lang' => '', //lang
'hasDOM' => true, //hasDOM
'canPNGALPHA' => true, //canPNGALPHA
'canIMGDATA' => true, //canIMGDATA
), ),
); );
} }
function os() function os()
{ {
return $this->extractDataSet(array('isWin','isLinux','isUnix','isMac')); return $this->extractDataSet(array('isWin', 'isLinux', 'isUnix', 'isMac'));
} }
/** /**

Loading…
Cancel
Save