[BUGFIX] Detect Android systems properly
authorFrancois Suter <francois@typo3.org>
Tue, 10 May 2011 15:38:04 +0000 (17:38 +0200)
committerSteffen Gebert <steffen.gebert@typo3.org>
Sun, 5 Jun 2011 15:16:42 +0000 (17:16 +0200)
Android system is not properly detected by
t3lib_utility_Client::getBrowserInfo() because it currently detects
Android devices as variants of a Linux system. However some browsers
don't send "Linux" in the User-Agent, so Android does not get detected
at all. This patch moves Android detection outside of the Linux
detection block. It also comes before Linux detection, so that
Android devices don't get rolled up into Linux computers.

Change-Id: I5e724802f1d8e5bf3b8a824a4fef7755eca779db
Resolves: #26734
Releases: 4.6, 4.5
Reviewed-on: http://review.typo3.org/1999
Reviewed-by: Steffen Gebert
Tested-by: Steffen Gebert
t3lib/utility/class.t3lib_utility_client.php
tests/t3lib/utility/t3lib_utility_clientTest.php

index 7a8d0ac..89023cc 100644 (file)
@@ -148,15 +148,13 @@ final class t3lib_utility_Client {
                                $browserInfo['all_systems'][] = 'mac';
                        }
                                // unixes
+               } elseif (strstr($userAgent, 'Android')) {
+                       $browserInfo['system'] = 'linux'; // backwards compatible
+                       $browserInfo['all_systems'][] = 'android';
+                       $browserInfo['all_systems'][] = 'linux';
                } elseif (strstr($userAgent, 'Linux')) {
-                       if (strstr($userAgent, 'Android')) {
-                               $browserInfo['system'] = 'linux'; // backwards compatible
-                               $browserInfo['all_systems'][] = 'android';
-                               $browserInfo['all_systems'][] = 'linux';
-                       } else {
-                               $browserInfo['system'] = 'linux';
-                               $browserInfo['all_systems'][] = 'linux';
-                       }
+                       $browserInfo['system'] = 'linux';
+                       $browserInfo['all_systems'][] = 'linux';
                } elseif (strstr($userAgent, 'BSD')) {
                        $browserInfo['system'] = 'unix_bsd';
                        $browserInfo['all_systems'][] = 'unix_bsd';
index 30a2767..062d827 100644 (file)
@@ -412,10 +412,28 @@ class t3lib_utility_clientTest extends tx_phpunit_testcase {
        }
 
        /**
+        * Provide various user agent strings for android devices
+        *
+        * @static
+        * @return array List of user agents
+        */
+       public static function androidUserAgentsProvider() {
+               $agents = array(
+                       'defaultBrowser' => array(
+                               'agent' => 'Mozilla/5.0 (Linux; U; Android 2.3; en-US; sdk Build/GRH55) AppleWebKit/533.1 (KHTML, like Gecko) Version/4.0 Mobile Safari/533.1',
+                       ),
+                       'operaMini' => array(
+                               'agent' => 'Opera/9.80 (Android; Opera Mini/6.0.24556/24.816; U; en) Presto/2.5.25 Version/10.54'
+                       )
+               );
+               return $agents;
+       }
+
+       /**
         * @test
+        * @dataProvider androidUserAgentsProvider
         */
-       public function getBrowserInfoReturnsCorrectSystemValueForUserAgentStringOfAndroid() {
-               $userAgentString = 'Mozilla/5.0 (Linux; U; Android 2.3; en-US; sdk Build/GRH55) AppleWebKit/533.1 (KHTML, like Gecko) Version/4.0 Mobile Safari/533.1';
+       public function getBrowserInfoReturnsCorrectSystemValueForUserAgentStringOfAndroid($userAgentString) {
                $infoArray = t3lib_utility_Client::getBrowserInfo($userAgentString);
 
                $this->assertContains(
@@ -480,7 +498,7 @@ class t3lib_utility_clientTest extends tx_phpunit_testcase {
                        $infoArray['all_systems']
                );
        }
-       
+
        /**
         * @test
         */
@@ -519,7 +537,7 @@ class t3lib_utility_clientTest extends tx_phpunit_testcase {
                        $infoArray['browser']
                );
        }
-       
+
        /**
         * @test
         */