Skip to content
Browse files

Adding the JWebClient class and some minor modifications to JWeb.

  • Loading branch information...
1 parent 906a159 commit 4bbf72ae00dbb9d93e4e4673d257b2bec1dc966e @LouisLandry committed Sep 18, 2011
View
63 libraries/joomla/application/web.php
@@ -402,20 +402,17 @@ protected function render()
*/
protected function compress()
{
- // Get the output data.
- $data = $this->getBody();
-
- // Detect the client supported encoding.
- $encoding = $this->detectClientAcceptedEncoding();
+ // Supported compression encodings.
+ $supported = array(
+ 'x-gzip' => 'gz',
+ 'gzip' => 'gz'
+ );
- // If no supported encoding is detected just return the data.
- if (!$encoding)
- {
- return;
- }
+ // Get the client supported encoding.
+ $encodings = $this->client->encodings;
- // Verify that the server supports gzip compression before we attempt to gzip encode the data.
- if (!extension_loaded('zlib') || ini_get('zlib.output_compression'))
+ // If no supported encoding is detected do nothing and return.
+ if (empty($encodings) || !empty(array_intersect($encodings, array_keys($supported))))
{
return;
}
@@ -426,24 +423,38 @@ protected function compress()
return;
}
- // Ideal level.
- $level = 4;
+ // Iterate through the encodings and attempt to compress the data using any found supported encodings.
+ foreach ($encodings as $encoding)
+ {
+ if (($supported[$encoding] == 'gz') || ($supported[$encoding] == 'deflate'))
+ {
+ // Verify that the server supports gzip compression before we attempt to gzip encode the data.
+ if (!extension_loaded('zlib') || ini_get('zlib.output_compression'))
+ {
+ continue;
+ }
- // Attemp to gzip encode the data.
- $gzdata = gzencode($data, $level);
+ // Attemp to gzip encode the data with an optimal level 4.
+ $data = $this->getBody();
+ $gzdata = gzencode($data, 4, ($supported[$encoding] == 'gz') ? FORCE_GZIP : FORCE_DEFLATE);
- // If there was a problem encoding the data just return the unencoded data.
- if ($gzdata === false)
- {
- return;
- }
+ // If there was a problem encoding the data just return the unencoded data.
+ if ($gzdata === false)
+ {
+ continue;
+ }
+
+ // Set the encoding headers.
+ $this->setHeader('Content-Encoding', $encoding);
+ $this->setHeader('X-Content-Encoded-By', 'Joomla');
- // Set the encoding headers.
- $this->setHeader('Content-Encoding', $encoding);
- $this->setHeader('X-Content-Encoded-By', 'Joomla');
+ // Replace the output with the encoded data.
+ $this->setBody($gzdata);
- // Replace the output with the encoded data.
- $this->setBody($gzdata);
+ // Compression complete, let's return.
+ return;
+ }
+ }
}
/**
View
446 libraries/joomla/application/web/webclient.php
@@ -0,0 +1,446 @@
+<?php
+/**
+ * @package Joomla.Platform
+ * @subpackage Application
+ *
+ * @copyright Copyright (C) 2005 - 2011 Open Source Matters, Inc. All rights reserved.
+ * @license GNU General Public License version 2 or later; see LICENSE
+ */
+
+defined('JPATH_PLATFORM') or die();
+
+/**
+ * Class to model a Web Client.
+ *
+ * @package Joomla.Platform
+ * @subpackage Application
+ * @since 11.3
+ */
+class JWebClient
+{
+ const WINDOWS = 1;
+ const WINDOWS_PHONE = 2;
+ const WINDOWS_CE = 3;
+ const IPHONE = 4;
+ const IPAD = 5;
+ const IPOD = 6;
+ const MAC = 7;
+ const BLACKBERRY = 8;
+ const ANDROID = 9;
+ const LINUX = 10;
+ const TRIDENT = 11;
+ const WEBKIT = 12;
+ const GECKO = 13;
+ const PRESTO = 14;
+ const KHTML = 15;
+ const AMAYA = 16;
+ const IE = 17;
+ const FIREFOX = 18;
+ const CHROME = 19;
+ const SAFARI = 20;
+ const OPERA = 21;
+
+ /**
+ * @var integer The detected platform on which the web client runs.
+ * @since 11.3
+ */
+ protected $platform;
+
+ /**
+ * @var boolean True if the web client is a mobile device.
+ * @since 11.3
+ */
+ protected $mobile = false;
+
+ /**
+ * @var integer The detected rendering engine used by the web client.
+ * @since 11.3
+ */
+ protected $engine;
+
+ /**
+ * @var integer The detected browser used by the web client.
+ * @since 11.3
+ */
+ protected $browser;
+
+ /**
+ * @var string The detected browser version used by the web client.
+ * @since 11.3
+ */
+ protected $browserVersion;
+
+ /**
+ * @var array The priority order detected accepted languages for the client.
+ * @since 11.3
+ */
+ protected $languages = array();
+
+ /**
+ * @var array The priority order detected accepted encodings for the client.
+ * @since 11.3
+ */
+ protected $encodings = array();
+
+ /**
+ * @var string The web client's user agent string.
+ * @since 11.3
+ */
+ protected $userAgent;
+
+ /**
+ * @var string The web client's accepted encoding string.
+ * @since 11.3
+ */
+ protected $acceptEncoding;
+
+ /**
+ * @var string The web client's accepted languages string.
+ * @since 11.3
+ */
+ protected $acceptLanguage;
+
+ /**
+ * @var array An array of flags determining whether or not a detection routine has been run.
+ * @since 11.3
+ */
+ protected $detection = array();
+
+ /**
+ * Class constructor.
+ *
+ * @param mixed $userAgent The optional user-agent string to parse.
+ * @param mixed $acceptEncoding The optional client accept encoding string to parse.
+ * @param mixed $acceptLanguage The optional client accept language string to parse.
+ *
+ * @return void
+ *
+ * @since 11.3
+ */
+ public function __construct($userAgent = null, $acceptEncoding = null, $acceptLanguage = null)
+ {
+ // If no explicit user agent string was given attempt to use the implicit one from server environment.
+ if (empty($userAgent) && isset($_SERVER['HTTP_USER_AGENT']))
+ {
+ $this->userAgent = $_SERVER['HTTP_USER_AGENT'];
+ }
+ else
+ {
+ $this->acceptEncoding = $acceptEncoding;
+ }
+
+ // If no explicit acceptable encoding string was given attempt to use the implicit one from server environment.
+ if (empty($acceptEncoding) && isset($_SERVER['HTTP_ACCEPT_ENCODING']))
+ {
+ $this->acceptEncoding = $_SERVER['HTTP_ACCEPT_ENCODING'];
+ }
+ else
+ {
+ $this->acceptEncoding = $acceptEncoding;
+ }
+
+ // If no explicit acceptable languages string was given attempt to use the implicit one from server environment.
+ if (empty($acceptLanguage) && isset($_SERVER['HTTP_ACCEPT_LANGUAGE']))
+ {
+ $this->acceptLanguage = $_SERVER['HTTP_ACCEPT_LANGUAGE'];
+ }
+ else
+ {
+ $this->acceptLanguage = $acceptLanguage;
+ }
+
+ // Attempt to detect the platform.
+ $this->detectPlatform($this->userAgent);
+
+ // Attempt to detect the engine.
+ $this->detectEngine($this->userAgent);
+
+ // Attempt to detect the browser.
+ $this->detectBrowser($this->userAgent);
+ }
+
+ /**
+ * Magic method to get an object property's value by name.
+ *
+ * @param string $name Name of the property for which to return a value.
+ *
+ * @return mixed The requested value if it exists.
+ *
+ * @since 11.3
+ */
+ public function __get($name)
+ {
+ switch ($name)
+ {
+ case 'mobile':
+ case 'platform':
+ if (empty($this->detection['platform']))
+ {
+ $this->detectPlatform($this->userAgent);
+ }
+ break;
+
+ case 'engine':
+ if (empty($this->detection['engine']))
+ {
+ $this->detectEngine($this->userAgent);
+ }
+ break;
+
+ case 'browser':
+ case 'browserVersion':
+ if (empty($this->detection['browser']))
+ {
+ $this->detectBrowser($this->userAgent);
+ }
+ break;
+
+ case 'languages':
+ if (empty($this->detection['acceptLanguage']))
+ {
+ $this->detectLanguage($this->acceptLanguage);
+ }
+ break;
+
+ case 'encodings':
+ if (empty($this->detection['acceptEncoding']))
+ {
+ $this->detectEncoding($this->acceptEncoding);
+ }
+ break;
+ }
+
+ // Return the property if it exists.
+ if (isset($this->$name))
+ {
+ return $this->$name;
+ }
+ }
+
+ /**
+ * Detects the client browser and version in a user agent string.
+ *
+ * @param string $userAgent The user-agent string to parse.
+ *
+ * @return void
+ *
+ * @since 11.3
+ */
+ protected function detectBrowser($userAgent)
+ {
+ // Attempt to detect the browser type. Obviously we are only worried about major browsers.
+ if ((stripos($userAgent, 'MSIE') !== false) && (stripos($userAgent, 'Opera') === false))
+ {
+ $this->browser = self::IE;
+ $patternBrowser = 'MSIE';
+ }
+ elseif ((stripos($userAgent, 'Firefox') !== false) && (stripos($userAgent, 'like Firefox') === false))
+ {
+ $this->browser = self::FIREFOX;
+ $patternBrowser = 'Firefox';
+ }
+ elseif (stripos($userAgent, 'Chrome') !== false)
+ {
+ $this->browser = self::CHROME;
+ $patternBrowser = 'Chrome';
+ }
+ elseif (stripos($userAgent, 'Safari') !== false)
+ {
+ $this->browser = self::SAFARI;
+ $patternBrowser = 'Safari';
+ }
+ elseif (stripos($userAgent, 'Opera') !== false)
+ {
+ $this->browser = self::OPERA;
+ $patternBrowser = 'Opera';
+ }
+
+ // If we detected a known browser let's attempt to determine the version.
+ if ($this->browser)
+ {
+ // Build the REGEX pattern to match the browser version string within the user agent string.
+ $pattern = '#(?<browser>Version|'.$patternBrowser.')[/ ]+(?<version>[0-9.|a-zA-Z.]*)#';
+
+ // Attempt to find version strings in the user agent string.
+ $matches = array();
+ if (preg_match_all($pattern, $userAgent, $matches))
+ {
+ // Do we have both a Version and browser match?
+ if (count($matches['browser']) > 1)
+ {
+ // See whether Version or browser came first, and use the number accordingly.
+ if (strripos($userAgent, 'Version') < strripos($userAgent, $patternBrowser))
+ {
+ $this->browserVersion = $matches['version'][0];
+ }
+ else
+ {
+ $this->browserVersion = $matches['version'][1];
+ }
+ }
+ // We only have a Version or a browser so use what we have.
+ else
+ {
+ $this->browserVersion = $matches['version'][0];
+ }
+ }
+ }
+
+ // Mark this dectection routine as run.
+ $this->detection['browser'] = true;;
+ }
+
+ /**
+ * Method to detect the accepted response encoding by the client. We only support gzip encoding
+ * at this time so that is the only type of response encoding that can be returned besides false
+ * if no supported encoding can be accepted by the client.
+ *
+ * @param string $acceptEncoding The client accept encoding string to parse.
+ *
+ * @return void
+ *
+ * @since 11.3
+ */
+ protected function detectEncoding($acceptEncoding)
+ {
+ // Parse the accepted encodings.
+ $this->encodings = array_map('trim', (array) explode(',', $acceptEncoding));
+
+ // Mark this dectection routine as run.
+ $this->detection['acceptEncoding'] = true;;
+ }
+
+ /**
+ * Detects the client rendering engine in a user agent string.
+ *
+ * @param string $userAgent The user-agent string to parse.
+ *
+ * @return void
+ *
+ * @since 11.3
+ */
+ protected function detectEngine($userAgent)
+ {
+ // Attempt to detect the client engine -- starting with the most popular ... for now.
+ if (stripos($userAgent, 'MSIE') !== false || stripos($userAgent, 'Trident') !== false)
+ {
+ $this->engine = self::TRIDENT;
+ }
+ // Evidently blackberry uses WebKit and doesn't necessarily report it. Bad RIM.
+ elseif (stripos($userAgent, 'AppleWebKit') !== false || stripos($userAgent, 'blackberry') !== false)
+ {
+ $this->engine = self::WEBKIT;
+ }
+ // We have to check for like Gecko because some other browsers spoof Gecko.
+ elseif (stripos($userAgent, 'Gecko') !== false && stripos($userAgent, 'like Gecko') === false)
+ {
+ $this->engine = self::GECKO;
+ }
+ // Sometims Opera browsers don't say Presto.
+ elseif (stripos($userAgent, 'Opera') !== false || stripos($userAgent, 'Presto') !== false)
+ {
+ $this->engine = self::PRESTO;
+ }
+ // *sigh*
+ elseif (stripos($userAgent, 'KHTML') !== false)
+ {
+ $this->engine = self::KHTML;
+ }
+ // Lesser known engine but it finishes off the major list from Wikipedia :-)
+ elseif (stripos($userAgent, 'Amaya') !== false)
+ {
+ $this->engine = self::AMAYA;
+ }
+
+ // Mark this dectection routine as run.
+ $this->detection['engine'] = true;;
+ }
+
+ /**
+ * Method to detect the accepted response encoding by the client. We only support gzip encoding
@elinw
elinw added a note Sep 19, 2011

I think you mean language here.

@LouisLandry
Owner
LouisLandry added a note Sep 19, 2011

sigh ... yes I do. Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
+ * at this time so that is the only type of response encoding that can be returned besides false
+ * if no supported encoding can be accepted by the client.
+ *
+ * @param mixed $acceptLanguage The optional client accept language string to parse.
+ *
+ * @return void
+ *
+ * @since 11.3
+ */
+ protected function detectLanguage($acceptLanguage)
+ {
+ // Parse the accepted encodings.
+ $this->languages = array_map('trim', (array) explode(',', $acceptLanguage));
+
+ // Mark this dectection routine as run.
+ $this->detection['acceptLanguage'] = true;;
+ }
+
+ /**
+ * Detects the client platform in a user agent string.
+ *
+ * @param string $userAgent The user-agent string to parse.
+ *
+ * @return void
+ *
+ * @since 11.3
+ */
+ protected function detectPlatform($userAgent)
+ {
+ // Attempt to detect the client platform.
+ if (stripos($userAgent, 'Windows') !== false)
+ {
+ $this->platform = self::WINDOWS;
+
+ // Let's look at the specific mobile options in the windows space.
+ if (stripos($userAgent, 'Windows Phone') !== false)
+ {
+ $this->mobile = true;
+ $this->platform = self::WINDOWS_PHONE;
+ }
+ elseif (stripos($userAgent, 'Windows CE') !== false)
+ {
+ $this->mobile = true;
+ $this->platform = self::WINDOWS_CE;
+ }
+ }
+ // Interestingly 'iPhone' is present in all iOS devices so far including iPad and iPods.
+ elseif (stripos($userAgent, 'iPhone') !== false)
+ {
+ $this->mobile = true;
+ $this->platform = self::IPHONE;
+
+ // Let's look at the specific mobile options in the windows space.
+ if (stripos($userAgent, 'iPad') !== false)
+ {
+ $this->platform = self::IPAD;
+ }
+ elseif (stripos($userAgent, 'iPod') !== false)
+ {
+ $this->platform = self::IPOD;
+ }
+ }
+ // This has to come after the iPhone check because mac strings are also present in iOS devices.
+ elseif (preg_match('/macintosh|mac os x/i', $userAgent))
+ {
+ $this->platform = self::MAC;
+ }
+ elseif (stripos($userAgent, 'Blackberry') !== false)
+ {
+ $this->mobile = true;
+ $this->platform = self::BLACKBERRY;
+ }
+ elseif (stripos($userAgent, 'Android') !== false)
+ {
+ $this->mobile = true;
+ $this->platform = self::ANDROID;
+ }
+ elseif (stripos($userAgent, 'Linux') !== false)
+ {
+ $this->platform = self::LINUX;
+ }
+
+ // Mark this dectection routine as run.
+ $this->detection['platform'] = true;;
+ }
+}
View
110 tests/suite/joomla/application/web/JWebClientTest.php
@@ -0,0 +1,110 @@
+<?php
+/**
+ * @package Joomla.UnitTest
+ * @subpackage Application
+ *
+ * @copyright Copyright (C) 2005 - 2011 Open Source Matters, Inc. All rights reserved.
+ * @license GNU General Public License version 2 or later; see LICENSE
+ */
+
+require_once JPATH_PLATFORM.'/joomla/application/web/webclient.php';
+
+/**
+ * Test class for JWebClient.
+ */
+class JWebClientTest extends PHPUnit_Framework_TestCase
+{
+ /**
+ * Setup for testing.
+ *
+ * @return void
+ */
+ public function setUp()
+ {
+ // Include the inspector.
+ include_once JPATH_TESTS.'/suite/joomla/application/web/TestStubs/JWebClient_Inspector.php';
+
+ // Setup the system logger to echo all.
+ JLog::addLogger(array('logger' => 'echo'), JLog::ALL);
+
+ $_SERVER['HTTP_HOST'] = 'mydomain.com';
+ $_SERVER['HTTP_USER_AGENT'] = 'Mozilla/5.0';
+
+ // Get a new JWebInspector instance.
+ $this->inspector = new JWebClientInspector();
+
+ parent::setUp();
+ }
+
+ public static function userAgentProvider()
+ {
+ // Platform, Mobile, Engine, Browser, Version, User Agent
+ return array(
+ array('windows', false, 'trident', 'Internet_Explorer', '10', 'Mozilla/5.0 (compatible; MSIE 10.0; Windows NT 6.1; WOW64; Trident/6.0)'),
+ array('windows', false, 'trident', 'Internet_Explorer', '9', 'Mozilla/5.0 (Windows; U; MSIE 9.0; WIndows NT 9.0; en-US))'),
+ array('windows', false, 'trident', 'Internet_Explorer', '8', 'Mozilla/5.0 (compatible; MSIE 8.0; Windows NT 6.0; Trident/4.0; WOW64; Trident/4.0; SLCC2; .NET CLR 2.0.50727; .NET CLR 3.5.30729; .NET CLR 3.0.30729; .NET CLR 1.0.3705; .NET CLR 1.1.4322)'),
+ array('windows', false, 'trident', 'Internet_Explorer', '7.0b', 'Mozilla/4.0(compatible; MSIE 7.0b; Windows NT 6.0)'),
+ array('windows', false, 'trident', 'Internet_Explorer', '7.0b', 'Mozilla/4.0 (compatible; MSIE 7.0b; Windows NT 5.1; Media Center PC 3.0; .NET CLR 1.0.3705; .NET CLR 1.1.4322; .NET CLR 2.0.50727; InfoPath.1)'),
+ array('windows', false, 'trident', 'Internet_Explorer', '7', 'Mozilla/5.0 (Windows; U; MSIE 7.0; Windows NT 5.2)'),
+ array('windows', false, 'trident', 'Internet_Explorer', '6.1', 'Mozilla/4.0 (compatible; MSIE 6.1; Windows XP)'),
+ array('windows', false, 'trident', 'Internet_Explorer', '6', 'Mozilla/4.0 (compatible;MSIE 6.0;Windows 98;Q312461)'),
+ array('windows', false, 'trident', 'Internet_Explorer', '7', 'Mozilla/4.0 (compatible; MSIE 7.0; AOL 9.6; AOLBuild 4340.128; Windows NT 5.1; Trident/4.0; .NET CLR 1.1.4322; .NET CLR 2.0.50727; .NET CLR 3.0.04506.648; .NET CLR 3.5.21022)'),
+ array('windows', false, 'trident', 'Internet_Explorer', '8', 'Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.1; Trident/4.0; SLCC2; .NET CLR 2.0.50727; .NET CLR 3.5.30729; .NET CLR 3.0.30729; .NET4.0C; Maxthon 2.0)'),
+ array('windows', false, 'trident', 'Internet_Explorer', '7', 'Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; Trident/4.0; .NET CLR 2.0.50727; SlimBrowser)'),
+ array('mac', false, 'webkit', 'Chrome', '13.0.782.32', 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_6_3) AppleWebKit/535.1 (KHTML, like Gecko) Chrome/13.0.782.32 Safari/535.1'),
+ array('windows', false, 'webkit', 'Chrome', '12.0.742.113', 'Mozilla/5.0 (Windows NT 6.1) AppleWebKit/534.30 (KHTML, like Gecko) Chrome/12.0.742.113 Safari/534.30'),
+ array('linux', false, 'webkit', 'Chrome', '12.0.742.112', 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/534.30 (KHTML, like Gecko) Ubuntu/10.04 Chromium/12.0.742.112 Chrome/12.0.742.112 Safari/534.30'),
+ array('windows', false, 'webkit', 'Chrome', '15.0.864.0', 'Mozilla/5.0 (Windows NT 5.1) AppleWebKit/535.2 (KHTML, like Gecko) Chrome/15.0.864.0 Safari/535.2'),
+ array('blackberry', true, 'webkit', 'Safari', '6.0.0.546', 'Mozilla/5.0 (BlackBerry; U; BlackBerry 9700; pt) AppleWebKit/534.8+ (KHTML, like Gecko) Version/6.0.0.546 Mobile Safari/534.8+'),
+ array('blackberry', true, 'webkit', '', '', 'BlackBerry9700/5.0.0.862 Profile/MIDP-2.1 Configuration/CLDC-1.1 VendorID/120'),
+ array('android', true, 'webkit', 'Safari', '999.9', 'Mozilla/5.0 (Linux; U; Android 2.3; en-us) AppleWebKit/999+ (KHTML, like Gecko) Safari/999.9'),
+ array('android', true, 'webkit', 'Safari', '4', 'Mozilla/5.0 (Linux; U; Android 2.2.1; en-ca; LG-P505R Build/FRG83) AppleWebKit/533.1 (KHTML, like Gecko) Version/4.0 Mobile Safari/533.1'),
+ array('ipad', true, 'webkit', 'Safari', '4.0.4', 'Mozilla/5.0(iPad; U; CPU iPhone OS 3_2 like Mac OS X; en-us) AppleWebKit/531.21.10 (KHTML, like Gecko) Version/4.0.4 Mobile/7B314 Safari/531.21.10gin_lib.cc'),
+ array('iphone', true, 'webkit', 'Safari', '4.0.5', 'Mozilla/5.0 (iPhone; U; CPU iPhone OS 4_1 like Mac OS X; en-us) AppleWebKit/532.9 (KHTML, like Gecko) Version/4.0.5 Mobile/8B5097d Safari/6531.22.7'),
+ array('windows', false, 'webkit', 'Safari', '5.0.4', 'Mozilla/5.0 (Windows; U; Windows NT 6.0; en-US) AppleWebKit/533.20.25 (KHTML, like Gecko) Version/5.0.4 Safari/533.20.27'),
+ array('mac', false, 'webkit', 'Safari', '5.0.3', 'Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10_6_5; ar) AppleWebKit/533.19.4 (KHTML, like Gecko) Version/5.0.3 Safari/533.19.4'),
+ array('windows', false, 'gecko', 'Firefox', '3.6.9', 'Mozilla/5.0 (Windows; U; Windows NT 6.0; en-GB; rv:1.9.2.9) Gecko/20100824 Firefox/3.6.9 ( .NET CLR 3.5.30729; .NET CLR 4.0.20506)'),
+ array('windows', false, 'gecko', 'Firefox', '4.0b8pre', 'Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:2.0b8pre) Gecko/20101213 Firefox/4.0b8pre'),
+ array('windows', false, 'gecko', 'Firefox', '5', 'Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:5.0) Gecko/20100101 Firefox/5.0'),
+ array('windows', false, 'gecko', 'Firefox', '6', 'Mozilla/5.0 (Windows NT 5.0; WOW64; rv:6.0) Gecko/20100101 Firefox/6.0'),
+ array('mac', false, 'gecko', '', '', 'Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10.6; en; rv:1.9.2.14pre) Gecko/20101212 Camino/2.1a1pre (like Firefox/3.6.14pre)'),
+ array('linux', false, 'khtml', '', '', 'Mozilla/5.0 (compatible; Konqueror/4.4; Linux 2.6.32-22-generic; X11; en_US) KHTML/4.4.3 (like Gecko) Kubuntu'),
+ array('', false, 'amaya', '', '', 'amaya/11.3.1 libwww/5.4.1')
+ );
+ }
+
+ /**
+ * @dataProvider userAgentProvider
+ */
+ public function testDetectClientBrowser($p, $m, $e, $b, $v, $ua)
+ {
+ $data = $this->inspector->detectClientBrowser($ua);
+
+ // Test the assertions.
+ $this->assertEquals($data['browser'], $b);
+ $this->assertEquals($data['version'], $v);
+ }
+
+ /**
+ * @dataProvider userAgentProvider
+ */
+ public function testDetectClientPlatform($p, $m, $e, $b, $v, $ua)
+ {
+ $data = $this->inspector->detectClientPlatform($ua);
+
+ // Test the assertions.
+ $this->assertEquals($data['mobile'], $m);
+ $this->assertEquals($data['platform'], $p);
+ }
+
+ /**
+ * @dataProvider userAgentProvider
+ */
+ public function testDetectClientEngine($p, $m, $e, $b, $v, $ua)
+ {
+ $data = $this->inspector->detectClientEngine($ua);
+
+ // Test the assertion.
+ $this->assertEquals($data, $e);
+ }
+}
View
68 tests/suite/joomla/application/web/TestStubs/JWebClient_Inspector.php
@@ -0,0 +1,68 @@
+<?php
+/**
+ * @package Joomla.UnitTest
+ * @subpackage Application
+ *
+ * @copyright Copyright (C) 2005 - 2011 Open Source Matters, Inc. All rights reserved.
+ * @license GNU General Public License version 2 or later; see LICENSE
+ */
+
+/**
+ * Inspector classes for the JWebClient library.
+ */
+
+/**
+ * @package Joomla.UnitTest
+ * @subpackage Application
+ */
+class JWebClientInspector extends JWebClient
+{
+ public function __construct()
+ {
+ return parent::__construct();
+ }
+
+ public function detectRequestURI()
+ {
+ return parent::detectRequestURI();
+ }
+
+ public function detectClientPlatform($userAgent)
+ {
+ return parent::detectClientPlatform($userAgent);
+ }
+
+ public function detectClientEngine($userAgent)
+ {
+ return parent::detectClientEngine($userAgent);
+ }
+
+ public function detectClientBrowser($userAgent)
+ {
+ return parent::detectClientBrowser($userAgent);
+ }
+
+ public function loadClientInformation($userAgent = null)
+ {
+ return parent::loadClientInformation($userAgent);
+ }
+
+ public function fetchConfigurationData()
+ {
+ return parent::fetchConfigurationData();
+ }
+
+ public function loadSystemURIs()
+ {
+ return parent::loadSystemURIs();
+ }
+
+ public function testHelperClient($ua)
+ {
+ $_SERVER['HTTP_USER_AGENT'] = $ua;
+
+ $this->detectClientInformation();
+
+ return $this->config->get('client');
+ }
+}

0 comments on commit 4bbf72a

Please sign in to comment.
Something went wrong with that request. Please try again.