Index: trunk/extensions/MobileFrontend/tests/DeviceDetectionTest.php |
— | — | @@ -0,0 +1,36 @@ |
| 2 | +<?php
|
| 3 | +
|
| 4 | +/**
|
| 5 | + * @group MobileFrontend
|
| 6 | + */
|
| 7 | + class DeviceDetectionTest extends MediaWikiTestCase {
|
| 8 | +
|
| 9 | + /**
|
| 10 | + * @dataProvider provideTestFormatName
|
| 11 | + */
|
| 12 | + public function testFormatName( $format, $userAgent ) {
|
| 13 | + $detector = new DeviceDetection();
|
| 14 | + $this->assertEquals( $format, $detector->formatName( $userAgent ) );
|
| 15 | + }
|
| 16 | +
|
| 17 | + public function provideTestFormatName() {
|
| 18 | + return array(
|
| 19 | + array( 'android', 'Mozilla/5.0 (Linux; U; Android 2.1; en-us; Nexus One Build/ERD62) AppleWebKit/530.17 (KHTML, like Gecko) Version/4.0 Mobile Safari/530.17' ),
|
| 20 | + array( 'iphone2', 'Mozilla/5.0 (ipod: U;CPU iPhone OS 2_2 like Mac OS X: es_es) AppleWebKit/525.18.1 (KHTML, like Gecko) Version/3.0 Mobile/3B48b Safari/419.3' ),
|
| 21 | + array( 'iphone', 'Mozilla/5.0 (iPhone; U; CPU like Mac OS X; en) AppleWebKit/420.1 (KHTML, like Gecko) Version/3.0 Mobile/3B48b Safari/419.3' ),
|
| 22 | + array( 'nokia', 'Mozilla/5.0 (SymbianOS/9.1; U; [en]; SymbianOS/91 Series60/3.0) AppleWebKit/413 (KHTML, like Gecko) Safari/413' ),
|
| 23 | + array( 'palm_pre', 'Mozilla/5.0 (webOS/1.0; U; en-US) AppleWebKit/525.27.1 (KHTML, like Gecko) Version/1.0 Safari/525.27.1 Pre/1.0' ),
|
| 24 | + array( 'wii', 'Opera/9.00 (Nintendo Wii; U; ; 1309-9; en)' ),
|
| 25 | + array( 'operamini', 'Opera/9.50 (J2ME/MIDP; Opera Mini/4.0.10031/298; U; en)' ),
|
| 26 | + array( 'iphone', 'Opera/9.51 Beta (Microsoft Windows; PPC; Opera Mobi/1718; U; en)' ),
|
| 27 | + array( 'kindle', 'Mozilla/4.0 (compatible; Linux 2.6.10) NetFront/3.3 Kindle/1.0 (screen 600x800)' ),
|
| 28 | + array( 'kindle2', 'Mozilla/4.0 (compatible; Linux 2.6.22) NetFront/3.4 Kindle/2.0 (screen 824x1200; rotate)' ),
|
| 29 | + array( 'capable', 'Mozilla/5.0 (X11; Linux i686; rv:2.0.1) Gecko/20100101 Firefox/4.0.1' ),
|
| 30 | + array( 'netfront', 'Mozilla/4.08 (Windows; Mobile Content Viewer/1.0) NetFront/3.2' ),
|
| 31 | + array( 'wap2', 'SonyEricssonK608i/R2L/SN356841000828910 Browser/SEMC-Browser/4.2 Profile/MIDP-2.0 Configuration/CLDC-1.1' ),
|
| 32 | + array( 'wap2', 'NokiaN73-2/3.0-630.0.2 Series60/3.0 Profile/MIDP-2.0 Configuration/CLDC-1.1' ),
|
| 33 | + array( 'psp', 'Mozilla/4.0 (PSP (PlayStation Portable); 2.00)' ),
|
| 34 | + array( 'ps3', 'Mozilla/5.0 (PLAYSTATION 3; 1.00)' ),
|
| 35 | + );
|
| 36 | + }
|
| 37 | +} |
\ No newline at end of file |
Index: trunk/extensions/MobileFrontend/tests/MobileFrontendTest.php |
— | — | @@ -1,5 +1,8 @@ |
2 | 2 | <?php |
3 | 3 | |
| 4 | +/** |
| 5 | + * @group MobileFrontend |
| 6 | + */ |
4 | 7 | class ExtMobileFrontendTest extends MediaWikiTestCase { |
5 | 8 | /** |
6 | 9 | * PHP 5.3.2 introduces the ReflectionMethod::setAccessible() method to allow the invocation of |
Index: trunk/extensions/MobileFrontend/DeviceDetection.php |
— | — | @@ -259,42 +259,6 @@ |
260 | 260 | } |
261 | 261 | |
262 | 262 | /** |
263 | | - * @return string |
264 | | - */ |
265 | | - public function testFormatName() { |
266 | | - $testResults = ''; |
267 | | - |
268 | | - $userAgents = array(); |
269 | | - $userAgents['android'] = 'Mozilla/5.0 (Linux; U; Android 2.1; en-us; Nexus One Build/ERD62) AppleWebKit/530.17 (KHTML, like Gecko) Version/4.0 Mobile Safari/530.17'; |
270 | | - $userAgents['iphone2'] = 'Mozilla/5.0 (ipod: U;CPU iPhone OS 2_2 like Mac OS X: es_es) AppleWebKit/525.18.1 (KHTML, like Gecko) Version/3.0 Mobile/3B48b Safari/419.3'; |
271 | | - $userAgents['iphone'] = 'Mozilla/5.0 (iPhone; U; CPU like Mac OS X; en) AppleWebKit/420.1 (KHTML, like Gecko) Version/3.0 Mobile/3B48b Safari/419.3'; |
272 | | - $userAgents['nokia'] = 'Mozilla/5.0 (SymbianOS/9.1; U; [en]; SymbianOS/91 Series60/3.0) AppleWebKit/413 (KHTML, like Gecko) Safari/413'; |
273 | | - $userAgents['palm_pre'] = 'Mozilla/5.0 (webOS/1.0; U; en-US) AppleWebKit/525.27.1 (KHTML, like Gecko) Version/1.0 Safari/525.27.1 Pre/1.0'; |
274 | | - $userAgents['wii'] = 'Opera/9.00 (Nintendo Wii; U; ; 1309-9; en)'; |
275 | | - $userAgents['operamini'] = 'Opera/9.50 (J2ME/MIDP; Opera Mini/4.0.10031/298; U; en)'; |
276 | | - $userAgents['iphone'] = 'Opera/9.51 Beta (Microsoft Windows; PPC; Opera Mobi/1718; U; en)'; |
277 | | - $userAgents['kindle'] = 'Mozilla/4.0 (compatible; Linux 2.6.10) NetFront/3.3 Kindle/1.0 (screen 600x800)'; |
278 | | - $userAgents['kindle2'] = 'Mozilla/4.0 (compatible; Linux 2.6.22) NetFront/3.4 Kindle/2.0 (screen 824x1200; rotate)'; |
279 | | - $userAgents['capable'] = 'Mozilla/5.0 (X11; Linux i686; rv:2.0.1) Gecko/20100101 Firefox/4.0.1'; |
280 | | - $userAgents['netfront'] = 'Mozilla/4.08 (Windows; Mobile Content Viewer/1.0) NetFront/3.2'; |
281 | | - $userAgents['wap2'] = 'SonyEricssonK608i/R2L/SN356841000828910 Browser/SEMC-Browser/4.2 Profile/MIDP-2.0 Configuration/CLDC-1.1'; |
282 | | - $userAgents['wap2'] = 'NokiaN73-2/3.0-630.0.2 Series60/3.0 Profile/MIDP-2.0 Configuration/CLDC-1.1'; |
283 | | - $userAgents['psp'] = 'Mozilla/4.0 (PSP (PlayStation Portable); 2.00)'; |
284 | | - $userAgents['ps3'] = 'Mozilla/5.0 (PLAYSTATION 3; 1.00)'; |
285 | | - |
286 | | - foreach ( $userAgents as $formatName => $userAgent ) { |
287 | | - if ( $this->formatName( $userAgent ) === $formatName ) { |
288 | | - $result = ' has PASSED!'; |
289 | | - } else { |
290 | | - $result = ' has FAILED!'; |
291 | | - } |
292 | | - |
293 | | - $testResults .= $formatName . $result . '<br/>' . PHP_EOL; |
294 | | - } |
295 | | - return $testResults; |
296 | | - } |
297 | | - |
298 | | - /** |
299 | 263 | * @param $userAgent string |
300 | 264 | * @param $acceptHeader string |
301 | 265 | * @return string |
Index: trunk/extensions/MobileFrontend/MobileFrontend.php |
— | — | @@ -82,6 +82,7 @@ |
83 | 83 | */ |
84 | 84 | function efExtMobileFrontendUnitTests( &$files ) { |
85 | 85 | $files[] = dirname( __FILE__ ) . '/tests/MobileFrontendTest.php'; |
| 86 | + $files[] = dirname( __FILE__ ) . '/tests/DeviceDetectionTest.php'; |
86 | 87 | return true; |
87 | 88 | } |
88 | 89 | |