| 1 |
<?php |
| 2 |
/** |
| 3 |
* @license MIT License https://github.com/serbanghita/Mobile-Detect/blob/master/LICENSE.txt |
| 4 |
* @link http://mobiledetect.net |
| 5 |
*/ |
| 6 |
class VendorsTest extends PHPUnit_Framework_TestCase |
| 7 |
{ |
| 8 |
protected $detect; |
| 9 |
protected static $items; |
| 10 |
|
| 11 |
public function setUp() |
| 12 |
{ |
| 13 |
$this->detect = new Mobile_Detect; |
| 14 |
|
| 15 |
} |
| 16 |
|
| 17 |
public static function setUpBeforeClass() |
| 18 |
{ |
| 19 |
//this method could be called multiple times |
| 20 |
if (!self::$items) { |
| 21 |
self::$items = include dirname(__FILE__).'/UA_List.inc.php'; |
| 22 |
} |
| 23 |
} |
| 24 |
|
| 25 |
public function testisMobileIsTablet() |
| 26 |
{ |
| 27 |
foreach (self::$items as $brand => $deviceArr) { |
| 28 |
foreach ($deviceArr as $userAgent => $conditions) { |
| 29 |
if (!is_array($conditions)) { |
| 30 |
continue; |
| 31 |
} |
| 32 |
|
| 33 |
$this->detect->setUserAgent($userAgent); |
| 34 |
|
| 35 |
foreach ($conditions as $condition => $assert) { |
| 36 |
// Currently not supporting version and model here. |
| 37 |
// @todo: I need to split this tests! |
| 38 |
if (in_array($condition, array('model'))) { |
| 39 |
continue; |
| 40 |
} // 'version', |
| 41 |
|
| 42 |
switch ($condition) { |
| 43 |
case 'version': |
| 44 |
// Android, iOS, Chrome, Build, etc. |
| 45 |
foreach ($assert as $assertKey => $assertValue) { |
| 46 |
//if ($brand == 'Apple') { |
| 47 |
// echo 'UA ('.$condition.'('.$assertKey.') === '.$assertValue.'): '.$userAgent . "\n"; |
| 48 |
//} |
| 49 |
$this->assertTrue( $this->detect->$condition( $assertKey ) == $assertValue, 'UA ('.$condition.'('.$assertKey.') === '.$assertValue.'): '.$userAgent); |
| 50 |
} |
| 51 |
break; |
| 52 |
|
| 53 |
default: |
| 54 |
$this->assertTrue($this->detect->$condition() === $assert, 'UA ('.$condition.'): '.$userAgent); |
| 55 |
break; |
| 56 |
} |
| 57 |
|
| 58 |
} |
| 59 |
|
| 60 |
} |
| 61 |
|
| 62 |
} |
| 63 |
|
| 64 |
} |
| 65 |
|
| 66 |
public function testVersion() |
| 67 |
{ |
| 68 |
foreach (self::$items as $brand => $deviceArr) { |
| 69 |
|
| 70 |
foreach ($deviceArr as $userAgent => $conditions) { |
| 71 |
|
| 72 |
if ( !is_array($conditions) || !isset($conditions['version']) ) { continue; } |
| 73 |
|
| 74 |
$this->detect->setUserAgent($userAgent); |
| 75 |
|
| 76 |
foreach ($conditions['version'] as $condition => $assertion) { |
| 77 |
|
| 78 |
$this->assertEquals( $this->detect->version($condition), $assertion, 'UA (version("'.$condition.'")): '.$userAgent ); |
| 79 |
|
| 80 |
} |
| 81 |
|
| 82 |
} |
| 83 |
|
| 84 |
} |
| 85 |
|
| 86 |
} |
| 87 |
|
| 88 |
} |
| 89 |
|