Skip to content

Commit

Permalink
Merge pull request #85 from cbschuld/ucbrowser
Browse files Browse the repository at this point in the history
added UCBrowser
  • Loading branch information
cbschuld authored Jul 9, 2019
2 parents 100b312 + bec87c4 commit 1870c94
Show file tree
Hide file tree
Showing 3 changed files with 566 additions and 1 deletion.
25 changes: 24 additions & 1 deletion lib/Browser.php
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ class Browser
const BROWSER_GOOGLEBOT = 'GoogleBot'; // http://en.wikipedia.org/wiki/Googlebot
const BROWSER_CURL = 'cURL'; // https://en.wikipedia.org/wiki/CURL
const BROWSER_WGET = 'Wget'; // https://en.wikipedia.org/wiki/Wget
const BROWSER_UCBROWSER = 'UCBrowser'; // https://www.ucweb.com/


const BROWSER_YANDEXBOT = 'YandexBot'; // http://yandex.com/bots
Expand Down Expand Up @@ -425,6 +426,7 @@ protected function checkBrowsers()
// before Firefox and Chrome
$this->checkBrowserWebTv() ||
$this->checkBrowserBrave() ||
$this->checkBrowserUCBrowser() ||
$this->checkBrowserEdge() ||
$this->checkBrowserInternetExplorer() ||
$this->checkBrowserOpera() ||
Expand Down Expand Up @@ -1304,7 +1306,28 @@ protected function checkBrowserPalemoon()
}

/**
* Determine if the browser is Firefox or not (last updated 1.7)
* Determine if the browser is UCBrowser or not
* @return boolean True if the browser is UCBrowser otherwise false
*/
protected function checkBrowserUCBrowser()
{
if (preg_match('/UC ?Browser\/?([\d\.]+)/', $this->_agent, $matches )) {
if(isset($matches[1])) {
$this->setVersion($matches[1]);
}
if (stripos($this->_agent, 'Mobile') !== false) {
$this->setMobile(true);
} else {
$this->setTablet(true);
}
$this->setBrowser(self::BROWSER_UCBROWSER);
return true;
}
return false;
}

/**
* Determine if the browser is Firefox or not
* @return boolean True if the browser is Firefox otherwise false
*/
protected function checkBrowserFirefox()
Expand Down
33 changes: 33 additions & 0 deletions tests/UCBrowserTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<?php
declare(strict_types=1);

use PHPUnit\Framework\TestCase;

require_once dirname(__FILE__)."/TabDelimitedFileIterator.php";

final class UCBrowserTest extends TestCase
{
/**
* @dataProvider userAgentUCBrowserProvider
* @param $userAgent string Browser's User Agent
* @param $type string Type of the Browser
* @param $browser string Name of the Browser
* @param $version string Version of the Browser
* @param $osType string Type of operating system associated with the Browser
* @param $osName string Name of the operating system associated with the Browser, typically has the version number
* @param $osVersionName string Version of the Operating System (name)
* @param $osVersionNumber string Version of the Operating System (number)
*/
public function testUCBrowserUserAgent($userAgent,$type,$browser,$version,$osType,$osName,$osVersionName,$osVersionNumber)
{
$b = new Browser($userAgent);

$this->assertSame($browser, $b->getBrowser());
$this->assertSame($version, $b->getVersion());
}

public function userAgentUCBrowserProvider()
{
return new TabDelimitedFileIterator(dirname(__FILE__).'/lists/ucbrowser.txt');
}
}
Loading

0 comments on commit 1870c94

Please sign in to comment.