VendorsTest_tmp.php 2.7 KB

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