UserAgentParserObjectTest.php 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. <?php
  2. use donatj\UserAgent\UserAgentParser;
  3. class UserAgentParserObjectTest extends \PHPUnit_Framework_TestCase {
  4. public function userAgentDataProvider() {
  5. $out = array();
  6. $uas = json_decode(file_get_contents(__DIR__ . '/user_agents.json'), true);
  7. foreach( $uas as $string => $parts ) {
  8. $out[] = array( $string );
  9. }
  10. return $out;
  11. }
  12. /**
  13. * @dataProvider userAgentDataProvider
  14. */
  15. public function test_parse( $string ) {
  16. $parser = new UserAgentParser;
  17. $result = $parser->parse($string);
  18. $expected = parse_user_agent($string);
  19. $this->assertSame($expected[\donatj\UserAgent\PLATFORM], $result->platform());
  20. $this->assertSame($expected[\donatj\UserAgent\BROWSER], $result->browser());
  21. $this->assertSame($expected[\donatj\UserAgent\BROWSER_VERSION], $result->browserVersion());
  22. }
  23. /**
  24. * @dataProvider userAgentDataProvider
  25. */
  26. public function test_invoke( $string ) {
  27. $parser = new UserAgentParser;
  28. $result = $parser($string);
  29. $expected = parse_user_agent($string);
  30. $this->assertSame($expected[\donatj\UserAgent\PLATFORM], $result->platform());
  31. $this->assertSame($expected[\donatj\UserAgent\BROWSER], $result->browser());
  32. $this->assertSame($expected[\donatj\UserAgent\BROWSER_VERSION], $result->browserVersion());
  33. }
  34. }