From 6fa8fc672bcec7bc0eab250906f7028a05f843c4 Mon Sep 17 00:00:00 2001 From: Martin Keckeis Date: Mon, 4 Apr 2016 12:57:48 +0200 Subject: [PATCH] more generics + better test --- src/Provider/AbstractBrowscap.php | 1 + src/Provider/Http/DeviceAtlasCom.php | 4 +- src/Provider/Http/NeutrinoApiCom.php | 4 +- src/Provider/Http/UdgerCom.php | 2 +- src/Provider/Http/WhatIsMyBrowserCom.php | 11 +- src/Provider/WhichBrowser.php | 2 +- src/Provider/Woothee.php | 10 +- src/Provider/Wurfl.php | 6 +- src/Provider/Zsxsoft.php | 10 +- tests/unit/Provider/AbstractBrowscapTest.php | 130 +++------- tests/unit/Provider/AbstractProviderTest.php | 6 +- .../Provider/AbstractProviderTestCase.php | 13 +- tests/unit/Provider/BrowscapFullTest.php | 2 +- tests/unit/Provider/BrowscapLiteTest.php | 2 +- tests/unit/Provider/BrowscapPhpTest.php | 2 +- tests/unit/Provider/ChainTest.php | 71 +++++- tests/unit/Provider/DonatjUAParserTest.php | 16 +- .../unit/Provider/Http/DeviceAtlasComTest.php | 33 ++- .../unit/Provider/Http/NeutrinoApiComTest.php | 182 ++++++-------- tests/unit/Provider/Http/UdgerComTest.php | 71 +++--- .../Provider/Http/UserAgentApiComTest.php | 35 ++- .../Provider/Http/UserAgentStringComTest.php | 60 ++--- .../Provider/Http/WhatIsMyBrowserComTest.php | 174 ++++++------- tests/unit/Provider/JenssegersAgentTest.php | 18 +- .../unit/Provider/PiwikDeviceDetectorTest.php | 98 ++------ .../RequiredProviderTestInterface.php | 27 ++ .../Provider/SinergiBrowserDetectorTest.php | 80 ++---- tests/unit/Provider/UAParserTest.php | 237 +++++++----------- tests/unit/Provider/WhichBrowserTest.php | 16 +- tests/unit/Provider/WootheeTest.php | 98 ++++---- tests/unit/Provider/WurflTest.php | 197 ++++++--------- tests/unit/Provider/ZsxsoftTest.php | 68 ++++- 32 files changed, 812 insertions(+), 874 deletions(-) create mode 100644 tests/unit/Provider/RequiredProviderTestInterface.php diff --git a/src/Provider/AbstractBrowscap.php b/src/Provider/AbstractBrowscap.php index d0352f0..ef81bcc 100644 --- a/src/Provider/AbstractBrowscap.php +++ b/src/Provider/AbstractBrowscap.php @@ -53,6 +53,7 @@ abstract class AbstractBrowscap extends AbstractProvider 'bot' => [ 'name' => [ '/^General Crawlers/i', + '/^Generic/i', ], ], ]; diff --git a/src/Provider/Http/DeviceAtlasCom.php b/src/Provider/Http/DeviceAtlasCom.php index 07fd197..9bc4123 100644 --- a/src/Provider/Http/DeviceAtlasCom.php +++ b/src/Provider/Http/DeviceAtlasCom.php @@ -143,11 +143,11 @@ protected function getResult($userAgent, array $headers) */ private function hydrateBrowser(Model\Browser $browser, stdClass $resultRaw) { - if (isset($resultRaw->browserName) && $this->isRealResult($resultRaw->browserName) === true) { + if (isset($resultRaw->browserName) && $this->isRealResult($resultRaw->browserName, 'browser', 'name') === true) { $browser->setName($resultRaw->browserName); } - if (isset($resultRaw->browserVersion) && $this->isRealResult($resultRaw->browserVersion) === true) { + if (isset($resultRaw->browserVersion) && $this->isRealResult($resultRaw->browserVersion, 'browser', 'version') === true) { $browser->getVersion()->setComplete($resultRaw->browserVersion); } } diff --git a/src/Provider/Http/NeutrinoApiCom.php b/src/Provider/Http/NeutrinoApiCom.php index 548286b..fcf5b92 100644 --- a/src/Provider/Http/NeutrinoApiCom.php +++ b/src/Provider/Http/NeutrinoApiCom.php @@ -72,11 +72,11 @@ class NeutrinoApiCom extends AbstractHttpProvider 'brand' => [ '/^Generic$/i', + '/^generic web browser$/i', ], 'model' => [ '/^Android/i', - '/^SmartTV$/i', '/^Windows Phone/i', '/^Windows Mobile/i', '/^Firefox/i', @@ -240,7 +240,7 @@ private function hydrateBot(Model\Bot $bot, stdClass $resultRaw) */ private function hydrateBrowser(Model\Browser $browser, stdClass $resultRaw) { - if (isset($resultRaw->browser_name) && $this->isRealResult($resultRaw->browser_name) === true) { + if (isset($resultRaw->browser_name) && $this->isRealResult($resultRaw->browser_name, 'browser', 'name') === true) { $browser->setName($resultRaw->browser_name); } diff --git a/src/Provider/Http/UdgerCom.php b/src/Provider/Http/UdgerCom.php index bf31612..f79c169 100644 --- a/src/Provider/Http/UdgerCom.php +++ b/src/Provider/Http/UdgerCom.php @@ -190,7 +190,7 @@ private function hydrateBot(Model\Bot $bot, stdClass $resultRaw) */ private function hydrateBrowser(Model\Browser $browser, stdClass $resultRaw) { - if (isset($resultRaw->ua_family) && $this->isRealResult($resultRaw->ua_family) === true) { + if (isset($resultRaw->ua_family) && $this->isRealResult($resultRaw->ua_family, 'browser', 'name') === true) { $browser->setName($resultRaw->ua_family); } diff --git a/src/Provider/Http/WhatIsMyBrowserCom.php b/src/Provider/Http/WhatIsMyBrowserCom.php index 6a90bd0..ee39031 100644 --- a/src/Provider/Http/WhatIsMyBrowserCom.php +++ b/src/Provider/Http/WhatIsMyBrowserCom.php @@ -72,6 +72,13 @@ class WhatIsMyBrowserCom extends AbstractHttpProvider '/^Unknown Mobile Browser$/i', '/^Unknown browser$/i', '/^Webkit based browser$/i', + '/^a UNIX based OS$/i', + ], + ], + + 'operatingSystem' => [ + 'name' => [ + '/^Smart TV$/i', ], ], @@ -195,7 +202,7 @@ private function hasResult(stdClass $resultRaw) return true; } - if (isset($resultRaw->operating_system_name) && $this->isRealResult($resultRaw->operating_system_name) === true) { + if (isset($resultRaw->operating_system_name) && $this->isRealResult($resultRaw->operating_system_name, 'operatingSystem', 'name') === true) { return true; } @@ -249,7 +256,7 @@ private function hydrateRenderingEngine(Model\RenderingEngine $engine, stdClass */ private function hydrateOperatingSystem(Model\OperatingSystem $os, stdClass $resultRaw) { - if (isset($resultRaw->operating_system_name) && $this->isRealResult($resultRaw->operating_system_name) === true) { + if (isset($resultRaw->operating_system_name) && $this->isRealResult($resultRaw->operating_system_name, 'operatingSystem', 'name') === true) { $os->setName($resultRaw->operating_system_name); } diff --git a/src/Provider/WhichBrowser.php b/src/Provider/WhichBrowser.php index 0cf3596..350cf93 100644 --- a/src/Provider/WhichBrowser.php +++ b/src/Provider/WhichBrowser.php @@ -122,7 +122,7 @@ private function hydrateBot(Model\Bot $bot, \WhichBrowser\Model\Browser $browser */ private function hydrateBrowser(Model\Browser $browser, \WhichBrowser\Model\Browser $browserRaw) { - if ($this->isRealResult($browserRaw->getName()) === true) { + if ($this->isRealResult($browserRaw->getName(), 'browser', 'name') === true) { $browser->setName($browserRaw->getName()); if ($this->isRealResult($browserRaw->getVersion()) === true) { diff --git a/src/Provider/Woothee.php b/src/Provider/Woothee.php index 79caca1..389c75b 100644 --- a/src/Provider/Woothee.php +++ b/src/Provider/Woothee.php @@ -75,6 +75,12 @@ class Woothee extends AbstractProvider '/^UNKNOWN$/i', ], + 'device' => [ + 'type' => [ + '/^misc$/i', + ], + ], + 'bot' => [ 'name' => [ '/^misc crawler$/i', @@ -118,7 +124,7 @@ public function getParser() */ private function hasResult(array $resultRaw) { - if (isset($resultRaw['category']) && $this->isRealResult($resultRaw['category'])) { + if (isset($resultRaw['category']) && $this->isRealResult($resultRaw['category'], 'device', 'type')) { return true; } @@ -180,7 +186,7 @@ private function hydrateBrowser(Model\Browser $browser, array $resultRaw) */ private function hydrateDevice(Model\Device $device, array $resultRaw) { - if (isset($resultRaw['category']) && $this->isRealResult($resultRaw['category']) === true) { + if (isset($resultRaw['category']) && $this->isRealResult($resultRaw['category'], 'device', 'type') === true) { $device->setType($resultRaw['category']); } } diff --git a/src/Provider/Wurfl.php b/src/Provider/Wurfl.php index a2b81bf..aaf5894 100644 --- a/src/Provider/Wurfl.php +++ b/src/Provider/Wurfl.php @@ -75,6 +75,11 @@ class Wurfl extends AbstractProvider 'operatingSystem' => [ 'name' => [ '/^Unknown$/i', + '/^en$/i', + '/^en_US$/i', + '/^Desktop$/i', + '/^Mobile$/i', + '/^Randomized by FreeSafeIP.com$/i', ], ], @@ -86,7 +91,6 @@ class Wurfl extends AbstractProvider 'model' => [ '/^Android/i', - '/^SmartTV$/i', '/^Windows Phone/i', '/^Windows Mobile/i', '/^Firefox/i', diff --git a/src/Provider/Zsxsoft.php b/src/Provider/Zsxsoft.php index 3721090..c14a43d 100644 --- a/src/Provider/Zsxsoft.php +++ b/src/Provider/Zsxsoft.php @@ -74,6 +74,12 @@ class Zsxsoft extends AbstractProvider '/^Unknown$/i', ], + 'browser' => [ + 'name' => [ + '/^Mozilla Compatible$/i', + ], + ], + 'device' => [ 'model' => [ '/^Browser$/i', @@ -123,7 +129,7 @@ public function getParser() */ private function hasResult(array $browser, array $os, array $device) { - if (isset($browser['name']) && $this->isRealResult($browser['name'])) { + if (isset($browser['name']) && $this->isRealResult($browser['name'], 'browser', 'name')) { return true; } @@ -149,7 +155,7 @@ private function hasResult(array $browser, array $os, array $device) */ private function hydrateBrowser(Model\Browser $browser, array $browserRaw) { - if (isset($browserRaw['name']) && $this->isRealResult($browserRaw['name']) === true) { + if (isset($browserRaw['name']) && $this->isRealResult($browserRaw['name'], 'browser', 'name') === true) { $browser->setName($browserRaw['name']); } diff --git a/tests/unit/Provider/AbstractBrowscapTest.php b/tests/unit/Provider/AbstractBrowscapTest.php index a52edd2..5fc6e7e 100644 --- a/tests/unit/Provider/AbstractBrowscapTest.php +++ b/tests/unit/Provider/AbstractBrowscapTest.php @@ -11,7 +11,7 @@ * * @covers UserAgentParser\Provider\AbstractBrowscap */ -class AbstractBrowscapTest extends AbstractProviderTestCase +class AbstractBrowscapTest extends AbstractProviderTestCase implements RequiredProviderTestInterface { /** * @@ -58,7 +58,7 @@ public function testConstructException() ]); } - public function testName() + public function testGetName() { $provider = $this->getMockForAbstractClass('UserAgentParser\Provider\AbstractBrowscap', [ $this->getParser(), @@ -151,6 +151,45 @@ public function testDetectionCapabilities() ], $provider->getDetectionCapabilities()); } + public function testIsRealResult() + { + $parser = $this->getParser(); + + $provider = new BrowscapPhp($parser); + + /* + * general + */ + $this->assertIsRealResult($provider, false, 'unknown'); + $this->assertIsRealResult($provider, true, 'unknown something'); + $this->assertIsRealResult($provider, true, 'something unknown'); + + /* + * browser name + */ + $this->assertIsRealResult($provider, false, 'Default Browser', 'browser', 'name'); + $this->assertIsRealResult($provider, true, 'Default Browser something', 'browser', 'name'); + $this->assertIsRealResult($provider, true, 'something Default Browser', 'browser', 'name'); + + /* + * device model + */ + $this->assertIsRealResult($provider, false, 'general', 'device', 'model'); + $this->assertIsRealResult($provider, false, 'general something', 'device', 'model'); + $this->assertIsRealResult($provider, true, 'something general', 'device', 'model'); + + /* + * bot name + */ + $this->assertIsRealResult($provider, false, 'General Crawlers', 'bot', 'name'); + $this->assertIsRealResult($provider, false, 'General Crawlers something', 'bot', 'name'); + $this->assertIsRealResult($provider, true, 'something General Crawlers', 'bot', 'name'); + + $this->assertIsRealResult($provider, false, 'Generic', 'bot', 'name'); + $this->assertIsRealResult($provider, false, 'Generic something', 'bot', 'name'); + $this->assertIsRealResult($provider, true, 'something Generic', 'bot', 'name'); + } + public function testParser() { $parser = $this->getParser(); @@ -532,91 +571,4 @@ public function testParseDeviceModelDefault2() $this->assertProviderResult($result, $expectedResult); } - - /** - * @dataProvider isRealResult - */ - public function testRealResult($value, $group, $part, $expectedResult) - { - $class = new \ReflectionClass('UserAgentParser\Provider\AbstractBrowscap'); - $method = $class->getMethod('isRealResult'); - $method->setAccessible(true); - - $result = new \stdClass(); - - $provider = $this->getMockForAbstractClass('UserAgentParser\Provider\AbstractBrowscap', [ - $this->getParser($result), - ]); - - $actualResult = $method->invokeArgs($provider, [ - $value, - $group, - $part, - ]); - - $this->assertEquals($expectedResult, $actualResult); - } - - public function isRealResult() - { - return [ - /* - * general - */ - [ - 'unknown', - null, - null, - false, - ], - - /* - * browserName - */ - [ - 'Default Browser', - 'browser', - 'name', - false, - ], - - /* - * deviceModel - */ - [ - 'general', - 'device', - 'model', - false, - ], - [ - 'general Mobile Device', - 'device', - 'model', - false, - ], - [ - 'Linux Desktop', - 'device', - 'model', - false, - ], - [ - 'Windows Desktop', - 'device', - 'model', - false, - ], - - /* - * botName - */ - [ - 'General Crawlers', - 'bot', - 'name', - false, - ], - ]; - } } diff --git a/tests/unit/Provider/AbstractProviderTest.php b/tests/unit/Provider/AbstractProviderTest.php index 46a42b6..7fa612d 100644 --- a/tests/unit/Provider/AbstractProviderTest.php +++ b/tests/unit/Provider/AbstractProviderTest.php @@ -11,7 +11,7 @@ */ class AbstractProviderTest extends AbstractProviderTestCase { - public function testName() + public function testGetName() { $provider = $this->getMockForAbstractClass('UserAgentParser\Provider\AbstractProvider'); @@ -25,7 +25,7 @@ public function testName() $this->assertEquals('MyName', $provider->getName()); } - public function testHomepage() + public function testGetHomepage() { $provider = $this->getMockForAbstractClass('UserAgentParser\Provider\AbstractProvider'); @@ -39,7 +39,7 @@ public function testHomepage() $this->assertEquals('https://github.com/vendor/package', $provider->getHomepage()); } - public function testPackageName() + public function testGetPackageName() { $provider = $this->getMockForAbstractClass('UserAgentParser\Provider\AbstractProvider'); diff --git a/tests/unit/Provider/AbstractProviderTestCase.php b/tests/unit/Provider/AbstractProviderTestCase.php index db4bff1..3af46c9 100644 --- a/tests/unit/Provider/AbstractProviderTestCase.php +++ b/tests/unit/Provider/AbstractProviderTestCase.php @@ -6,16 +6,16 @@ use GuzzleHttp\HandlerStack; use PHPUnit_Framework_TestCase; use UserAgentParser\Model\UserAgent; +use UserAgentParser\Provider\AbstractProvider; /** - * * * @author Martin Keckeis * @license MIT */ abstract class AbstractProviderTestCase extends PHPUnit_Framework_TestCase { - public function assertProviderResult($result, array $expectedResult) + protected function assertProviderResult($result, array $expectedResult) { $this->assertInstanceOf('UserAgentParser\Model\UserAgent', $result); @@ -25,6 +25,15 @@ public function assertProviderResult($result, array $expectedResult) $this->assertEquals($result->toArray(), $expectedResult); } + protected function assertIsRealResult(AbstractProvider $provider, $expected, $value, $group = null, $part = null) + { + $reflection = new \ReflectionClass($provider); + $method = $reflection->getMethod('isRealResult'); + $method->setAccessible(true); + + $this->assertSame($expected, $method->invoke($provider, $value, $group, $part), $value); + } + /** * * @return Client diff --git a/tests/unit/Provider/BrowscapFullTest.php b/tests/unit/Provider/BrowscapFullTest.php index 8892611..d83c0da 100644 --- a/tests/unit/Provider/BrowscapFullTest.php +++ b/tests/unit/Provider/BrowscapFullTest.php @@ -36,7 +36,7 @@ private function getParser(\stdClass $result = null) return $parser; } - public function testName() + public function testGetName() { $provider = new BrowscapFull($this->getParser()); diff --git a/tests/unit/Provider/BrowscapLiteTest.php b/tests/unit/Provider/BrowscapLiteTest.php index 3aa7a0a..e443629 100644 --- a/tests/unit/Provider/BrowscapLiteTest.php +++ b/tests/unit/Provider/BrowscapLiteTest.php @@ -36,7 +36,7 @@ private function getParser(\stdClass $result = null) return $parser; } - public function testName() + public function testGetName() { $provider = new BrowscapLite($this->getParser()); diff --git a/tests/unit/Provider/BrowscapPhpTest.php b/tests/unit/Provider/BrowscapPhpTest.php index 3f6884a..ef63db4 100644 --- a/tests/unit/Provider/BrowscapPhpTest.php +++ b/tests/unit/Provider/BrowscapPhpTest.php @@ -35,7 +35,7 @@ private function getParser(\stdClass $result = null) return $parser; } - public function testName() + public function testGetName() { $provider = new BrowscapPhp($this->getParser()); diff --git a/tests/unit/Provider/ChainTest.php b/tests/unit/Provider/ChainTest.php index e68ee03..112572b 100644 --- a/tests/unit/Provider/ChainTest.php +++ b/tests/unit/Provider/ChainTest.php @@ -4,14 +4,13 @@ use UserAgentParser\Provider\Chain; /** - * * * @author Martin Keckeis * @license MIT - * + * * @covers UserAgentParser\Provider\Chain */ -class ChainTest extends AbstractProviderTestCase +class ChainTest extends AbstractProviderTestCase implements RequiredProviderTestInterface { /** * @@ -51,7 +50,7 @@ public function testProvider() ], $chain->getProviders()); } - public function testName() + public function testGetName() { $chain = new Chain(); @@ -65,6 +64,13 @@ public function testGetHomepage() $this->assertNull($provider->getHomepage()); } + public function testGetPackageName() + { + $provider = new Chain(); + + $this->assertNull($provider->getPackageName()); + } + public function testVersion() { $provider = new Chain(); @@ -72,7 +78,62 @@ public function testVersion() $this->assertNull($provider->getVersion()); } + public function testUpdateDate() + { + $provider = new Chain(); + + $this->assertNull($provider->getUpdateDate()); + } + + public function testDetectionCapabilities() + { + $provider = new Chain(); + + $this->assertEquals([ + + 'browser' => [ + 'name' => false, + 'version' => false, + ], + + 'renderingEngine' => [ + 'name' => false, + 'version' => false, + ], + + 'operatingSystem' => [ + 'name' => false, + 'version' => false, + ], + + 'device' => [ + 'model' => false, + 'brand' => false, + 'type' => false, + 'isMobile' => false, + 'isTouch' => false, + ], + + 'bot' => [ + 'isBot' => false, + 'name' => false, + 'type' => false, + ], + ], $provider->getDetectionCapabilities()); + } + + public function testIsRealResult() + { + $provider = new Chain(); + + /* + * general + */ + $this->assertIsRealResult($provider, true, 'something UNKNOWN'); + } + /** + * @todo should throw another exception! since no provider was provided! * @expectedException \UserAgentParser\Exception\NoResultFoundException */ public function testParseNoProviderNoResultFoundException() @@ -87,7 +148,7 @@ public function testParseNoProviderNoResultFoundException() /** * @expectedException \UserAgentParser\Exception\NoResultFoundException */ - public function testParseWithProviderNoResultFoundException() + public function testParseNoResultFoundException() { $provider = $this->provider; $provider->expects($this->any()) diff --git a/tests/unit/Provider/DonatjUAParserTest.php b/tests/unit/Provider/DonatjUAParserTest.php index f9444c5..1a5537a 100644 --- a/tests/unit/Provider/DonatjUAParserTest.php +++ b/tests/unit/Provider/DonatjUAParserTest.php @@ -33,7 +33,7 @@ function parse_user_agent($userAgent) /** * @covers UserAgentParser\Provider\DonatjUAParser */ - class DonatjUAParserTest extends AbstractProviderTestCase + class DonatjUAParserTest extends AbstractProviderTestCase implements RequiredProviderTestInterface { public static $browser = null; @@ -57,7 +57,7 @@ public function testPackageNotLoadedException() rename($tempFile, $file); } - public function testName() + public function testGetName() { $provider = new DonatjUAParser(); @@ -129,10 +129,20 @@ public function testDetectionCapabilities() ], $provider->getDetectionCapabilities()); } + public function testIsRealResult() + { + $provider = new DonatjUAParser(); + + /* + * general + */ + $this->assertIsRealResult($provider, true, 'UNKNOWN something'); + } + /** * @expectedException \UserAgentParser\Exception\NoResultFoundException */ - public function testNoResultFoundException() + public function testParseNoResultFoundException() { self::$browser = null; self::$version = null; diff --git a/tests/unit/Provider/Http/DeviceAtlasComTest.php b/tests/unit/Provider/Http/DeviceAtlasComTest.php index 71f44dc..aefe508 100644 --- a/tests/unit/Provider/Http/DeviceAtlasComTest.php +++ b/tests/unit/Provider/Http/DeviceAtlasComTest.php @@ -13,9 +13,9 @@ * * @covers UserAgentParser\Provider\Http\DeviceAtlasCom */ -class DeviceAtlasComTest extends AbstractProviderTestCase +class DeviceAtlasComTest extends AbstractProviderTestCase implements RequiredProviderTestInterface { - public function testName() + public function testGetName() { $provider = new DeviceAtlasCom($this->getClient(), 'apiKey123'); @@ -43,6 +43,13 @@ public function testVersion() $this->assertNull($provider->getVersion()); } + public function testUpdateDate() + { + $provider = new DeviceAtlasCom($this->getClient(), 'apiKey123'); + + $this->assertNull($provider->getUpdateDate()); + } + public function testDetectionCapabilities() { $provider = new DeviceAtlasCom($this->getClient(), 'apiKey123'); @@ -80,12 +87,22 @@ public function testDetectionCapabilities() ], $provider->getDetectionCapabilities()); } + public function testIsRealResult() + { + $provider = new DeviceAtlasCom($this->getClient(), 'apiKey123'); + + /* + * general + */ + $this->assertIsRealResult($provider, true, 'something UNKNOWN'); + } + /** * Empty user agent * * @expectedException \UserAgentParser\Exception\NoResultFoundException */ - public function testGetResultNoResultFoundExceptionEmptyUserAgent() + public function testParseNoResultFoundExceptionEmptyUserAgent() { $responseQueue = [ new Response(200), @@ -101,7 +118,7 @@ public function testGetResultNoResultFoundExceptionEmptyUserAgent() * * @expectedException \UserAgentParser\Exception\InvalidCredentialsException */ - public function testGetResultInvalidCredentialsException() + public function testParseInvalidCredentialsException() { $responseQueue = [ new Response(403), @@ -119,7 +136,7 @@ public function testGetResultInvalidCredentialsException() * * @expectedException \UserAgentParser\Exception\RequestException */ - public function testGetResultRequestException() + public function testParseRequestException() { $responseQueue = [ new Response(500), @@ -135,7 +152,7 @@ public function testGetResultRequestException() * * @expectedException \UserAgentParser\Exception\RequestException */ - public function testGetResultRequestExceptionContentType() + public function testParseRequestExceptionContentType() { $responseQueue = [ new Response(200, [ @@ -153,7 +170,7 @@ public function testGetResultRequestExceptionContentType() * * @expectedException \UserAgentParser\Exception\RequestException */ - public function testGetResultRequestExceptionNoData() + public function testParseRequestExceptionNoData() { $responseQueue = [ new Response(200, [ @@ -171,7 +188,7 @@ public function testGetResultRequestExceptionNoData() * * @expectedException \UserAgentParser\Exception\NoResultFoundException */ - public function testNoResultFoundException() + public function testParseNoResultFoundException() { $rawResult = new stdClass(); $rawResult->properties = new stdClass(); diff --git a/tests/unit/Provider/Http/NeutrinoApiComTest.php b/tests/unit/Provider/Http/NeutrinoApiComTest.php index 2db0101..82a6098 100644 --- a/tests/unit/Provider/Http/NeutrinoApiComTest.php +++ b/tests/unit/Provider/Http/NeutrinoApiComTest.php @@ -13,9 +13,9 @@ * * @covers UserAgentParser\Provider\Http\NeutrinoApiCom */ -class NeutrinoApiComTest extends AbstractProviderTestCase +class NeutrinoApiComTest extends AbstractProviderTestCase implements RequiredProviderTestInterface { - public function testName() + public function testGetName() { $provider = new NeutrinoApiCom($this->getClient(), 'apiUser', 'apiKey123'); @@ -43,6 +43,13 @@ public function testVersion() $this->assertNull($provider->getVersion()); } + public function testUpdateDate() + { + $provider = new NeutrinoApiCom($this->getClient(), 'apiUser', 'apiKey123'); + + $this->assertNull($provider->getUpdateDate()); + } + public function testDetectionCapabilities() { $provider = new NeutrinoApiCom($this->getClient(), 'apiUser', 'apiKey123'); @@ -80,12 +87,66 @@ public function testDetectionCapabilities() ], $provider->getDetectionCapabilities()); } + public function testIsRealResult() + { + $provider = new NeutrinoApiCom($this->getClient(), 'apiUser', 'apiKey123'); + + /* + * general + */ + $this->assertIsRealResult($provider, false, 'unknown'); + $this->assertIsRealResult($provider, true, 'unknown something'); + $this->assertIsRealResult($provider, true, 'something unknown'); + + /* + * device brand + */ + $this->assertIsRealResult($provider, false, 'Generic', 'device', 'brand'); + $this->assertIsRealResult($provider, true, 'Generic something', 'device', 'brand'); + $this->assertIsRealResult($provider, true, 'something Generic', 'device', 'brand'); + + $this->assertIsRealResult($provider, false, 'generic web browser', 'device', 'brand'); + $this->assertIsRealResult($provider, true, 'generic web browser something', 'device', 'brand'); + $this->assertIsRealResult($provider, true, 'something generic web browser', 'device', 'brand'); + + /* + * device model + */ + $this->assertIsRealResult($provider, false, 'Android', 'device', 'model'); + $this->assertIsRealResult($provider, false, 'Android something', 'device', 'model'); + $this->assertIsRealResult($provider, true, 'something Android', 'device', 'model'); + + $this->assertIsRealResult($provider, false, 'Windows Phone', 'device', 'model'); + $this->assertIsRealResult($provider, false, 'Windows Phone something', 'device', 'model'); + $this->assertIsRealResult($provider, true, 'something Windows Phone', 'device', 'model'); + + $this->assertIsRealResult($provider, false, 'Windows Mobile', 'device', 'model'); + $this->assertIsRealResult($provider, false, 'Windows Mobile something', 'device', 'model'); + $this->assertIsRealResult($provider, true, 'something Windows Mobile', 'device', 'model'); + + $this->assertIsRealResult($provider, false, 'Firefox', 'device', 'model'); + $this->assertIsRealResult($provider, false, 'Firefox something', 'device', 'model'); + $this->assertIsRealResult($provider, true, 'something Firefox', 'device', 'model'); + + $this->assertIsRealResult($provider, false, 'Generic', 'device', 'model'); + $this->assertIsRealResult($provider, false, 'Generic something', 'device', 'model'); + $this->assertIsRealResult($provider, true, 'something AndGenericroid', 'device', 'model'); + + $this->assertIsRealResult($provider, false, 'Tablet on Android', 'device', 'model'); + $this->assertIsRealResult($provider, true, 'Tablet on Android something', 'device', 'model'); + $this->assertIsRealResult($provider, true, 'something Tablet on Android', 'device', 'model'); + + $this->assertIsRealResult($provider, false, 'Tablet', 'device', 'model'); + $this->assertIsRealResult($provider, true, 'Tablet something', 'device', 'model'); + $this->assertIsRealResult($provider, true, 'something Tablet', 'device', 'model'); + } + /** * Empty user agent * * @expectedException \UserAgentParser\Exception\NoResultFoundException */ - public function testGetResultNoResultFoundExceptionEmptyUserAgent() + public function testParseNoResultFoundExceptionEmptyUserAgent() { $responseQueue = [ new Response(200), @@ -101,7 +162,7 @@ public function testGetResultNoResultFoundExceptionEmptyUserAgent() * * @expectedException \UserAgentParser\Exception\InvalidCredentialsException */ - public function testGetResultInvalidCredentialsException() + public function testParseInvalidCredentialsException() { $responseQueue = [ new Response(403), @@ -117,7 +178,7 @@ public function testGetResultInvalidCredentialsException() * * @expectedException \UserAgentParser\Exception\RequestException */ - public function testGetResultRequestException() + public function testParseRequestException() { $responseQueue = [ new Response(500), @@ -133,7 +194,7 @@ public function testGetResultRequestException() * * @expectedException \UserAgentParser\Exception\RequestException */ - public function testGetResultRequestExceptionContentType() + public function testParseRequestExceptionContentType() { $responseQueue = [ new Response(200, [ @@ -151,7 +212,7 @@ public function testGetResultRequestExceptionContentType() * * @expectedException \UserAgentParser\Exception\RequestException */ - public function testGetResultRequestExceptionCode1() + public function testParseRequestExceptionCode1() { $rawResult = new stdClass(); $rawResult->api_error = 1; @@ -173,7 +234,7 @@ public function testGetResultRequestExceptionCode1() * * @expectedException \UserAgentParser\Exception\LimitationExceededException */ - public function testGetResultLimitationExceededExceptionCode2() + public function testParseLimitationExceededExceptionCode2() { $rawResult = new stdClass(); $rawResult->api_error = 2; @@ -195,7 +256,7 @@ public function testGetResultLimitationExceededExceptionCode2() * * @expectedException \UserAgentParser\Exception\RequestException */ - public function testGetResultRequestExceptionCodeSomething() + public function testParseRequestExceptionCodeSomething() { $rawResult = new stdClass(); $rawResult->api_error = 1337; @@ -217,7 +278,7 @@ public function testGetResultRequestExceptionCodeSomething() * * @expectedException \UserAgentParser\Exception\RequestException */ - public function testGetResultRequestExceptionNoData() + public function testParseRequestExceptionNoData() { $responseQueue = [ new Response(200, [ @@ -235,7 +296,7 @@ public function testGetResultRequestExceptionNoData() * * @expectedException \UserAgentParser\Exception\NoResultFoundException */ - public function testNoResultFoundException() + public function testParseNoResultFoundException() { $rawResult = new stdClass(); $rawResult->type = 'unknown'; @@ -417,7 +478,7 @@ public function testParseDeviceDefaultValue() { $rawResult = new stdClass(); $rawResult->type = 'mobile-browser'; - $rawResult->mobile_model = 'SmartTV'; + $rawResult->mobile_model = 'Android'; $rawResult->mobile_brand = 'Generic'; $responseQueue = [ @@ -443,101 +504,4 @@ public function testParseDeviceDefaultValue() $this->assertProviderResult($result, $expectedResult); } - - /** - * @dataProvider isRealResult - */ - public function testRealResult($value, $group, $part, $expectedResult) - { - $class = new \ReflectionClass('UserAgentParser\Provider\Http\NeutrinoApiCom'); - $method = $class->getMethod('isRealResult'); - $method->setAccessible(true); - - $provider = new NeutrinoApiCom($this->getClient([]), 'apiUser', 'apiKey123'); - - $actualResult = $method->invokeArgs($provider, [ - $value, - $group, - $part, - ]); - - $this->assertEquals($expectedResult, $actualResult); - } - - public function isRealResult() - { - return [ - /* - * general - */ - [ - 'unknown', - null, - null, - false, - ], - - /* - * deviceBrand - */ - [ - 'Generic', - 'device', - 'brand', - false, - ], - - /* - * deviceModel - */ - [ - 'Android', - 'device', - 'model', - false, - ], - [ - 'SmartTV', - 'device', - 'model', - false, - ], - [ - 'Windows Phone', - 'device', - 'model', - false, - ], - [ - 'Windows Mobile', - 'device', - 'model', - false, - ], - [ - 'Firefox', - 'device', - 'model', - false, - ], - [ - 'Generic', - 'device', - 'model', - false, - ], - [ - 'Tablet on Android', - 'device', - 'model', - false, - ], - [ - 'Tablet', - 'device', - 'model', - false, - ], - ]; - } } diff --git a/tests/unit/Provider/Http/UdgerComTest.php b/tests/unit/Provider/Http/UdgerComTest.php index aeca6f2..cc60c5b 100644 --- a/tests/unit/Provider/Http/UdgerComTest.php +++ b/tests/unit/Provider/Http/UdgerComTest.php @@ -13,9 +13,9 @@ * * @covers UserAgentParser\Provider\Http\UdgerCom */ -class UdgerComTest extends AbstractProviderTestCase +class UdgerComTest extends AbstractProviderTestCase implements RequiredProviderTestInterface { - public function testName() + public function testGetName() { $provider = new UdgerCom($this->getClient(), 'apiKey123'); @@ -43,6 +43,13 @@ public function testVersion() $this->assertNull($provider->getVersion()); } + public function testUpdateDate() + { + $provider = new UdgerCom($this->getClient(), 'apiKey123'); + + $this->assertNull($provider->getUpdateDate()); + } + public function testDetectionCapabilities() { $provider = new UdgerCom($this->getClient(), 'apiKey123'); @@ -80,12 +87,24 @@ public function testDetectionCapabilities() ], $provider->getDetectionCapabilities()); } + public function testIsRealResult() + { + $provider = new UdgerCom($this->getClient(), 'apiKey123'); + + /* + * general + */ + $this->assertIsRealResult($provider, false, 'unknown'); + $this->assertIsRealResult($provider, true, 'unknown something'); + $this->assertIsRealResult($provider, true, 'something unknown'); + } + /** * Empty user agent * * @expectedException \UserAgentParser\Exception\NoResultFoundException */ - public function testGetResultNoResultFoundExceptionEmptyUserAgent() + public function testParseNoResultFoundExceptionEmptyUserAgent() { $responseQueue = [ new Response(200), @@ -101,7 +120,7 @@ public function testGetResultNoResultFoundExceptionEmptyUserAgent() * * @expectedException \UserAgentParser\Exception\InvalidCredentialsException */ - public function testGetResultInvalidCredentialsException() + public function testParseInvalidCredentialsException() { $rawResult = new stdClass(); $rawResult->flag = 4; @@ -122,7 +141,7 @@ public function testGetResultInvalidCredentialsException() * * @expectedException \UserAgentParser\Exception\LimitationExceededException */ - public function testGetResultLimitationExceededException() + public function testParseLimitationExceededException() { $rawResult = new stdClass(); $rawResult->flag = 6; @@ -143,7 +162,7 @@ public function testGetResultLimitationExceededException() * * @expectedException \UserAgentParser\Exception\RequestException */ - public function testGetResultRequestException1() + public function testParseRequestException1() { $rawResult = new stdClass(); $rawResult->flag = 99; @@ -164,7 +183,7 @@ public function testGetResultRequestException1() * * @expectedException \UserAgentParser\Exception\RequestException */ - public function testGetResultRequestException2() + public function testParseRequestException2() { $responseQueue = [ new Response(500), @@ -180,7 +199,7 @@ public function testGetResultRequestException2() * * @expectedException \UserAgentParser\Exception\RequestException */ - public function testGetResultRequestExceptionContentType() + public function testParseRequestExceptionContentType() { $responseQueue = [ new Response(200, [ @@ -198,7 +217,7 @@ public function testGetResultRequestExceptionContentType() * * @expectedException \UserAgentParser\Exception\NoResultFoundException */ - public function testGetResultNoResultFoundException() + public function testParseNoResultFoundException() { $rawResult = new stdClass(); $rawResult->flag = 3; @@ -219,7 +238,7 @@ public function testGetResultNoResultFoundException() * * @expectedException \UserAgentParser\Exception\RequestException */ - public function testGetResultRequestExceptionNoData() + public function testParseRequestExceptionNoData() { $rawResult = new stdClass(); @@ -419,36 +438,4 @@ public function testParseDevice() $this->assertProviderResult($result, $expectedResult); } - - /** - * @dataProvider isRealResult - */ - public function testRealResult($value, $group, $part, $expectedResult) - { - $class = new \ReflectionClass('UserAgentParser\Provider\Http\UdgerCom'); - $method = $class->getMethod('isRealResult'); - $method->setAccessible(true); - - $provider = new UdgerCom($this->getClient([]), 'apiUser', 'apiKey123'); - - $actualResult = $method->invokeArgs($provider, [ - $value, - $group, - $part, - ]); - - $this->assertEquals($expectedResult, $actualResult); - } - - public function isRealResult() - { - return [ - [ - 'unknown', - null, - null, - false, - ], - ]; - } } diff --git a/tests/unit/Provider/Http/UserAgentApiComTest.php b/tests/unit/Provider/Http/UserAgentApiComTest.php index 6245d12..511ac37 100644 --- a/tests/unit/Provider/Http/UserAgentApiComTest.php +++ b/tests/unit/Provider/Http/UserAgentApiComTest.php @@ -13,9 +13,9 @@ * * @covers UserAgentParser\Provider\Http\UserAgentApiCom */ -class UserAgentApiComTest extends AbstractProviderTestCase +class UserAgentApiComTest extends AbstractProviderTestCase implements RequiredProviderTestInterface { - public function testName() + public function testGetName() { $provider = new UserAgentApiCom($this->getClient(), 'apiKey123'); @@ -43,6 +43,13 @@ public function testVersion() $this->assertNull($provider->getVersion()); } + public function testUpdateDate() + { + $provider = new UserAgentApiCom($this->getClient(), 'apiKey123'); + + $this->assertNull($provider->getUpdateDate()); + } + public function testDetectionCapabilities() { $provider = new UserAgentApiCom($this->getClient(), 'apiKey123'); @@ -80,12 +87,22 @@ public function testDetectionCapabilities() ], $provider->getDetectionCapabilities()); } + public function testIsRealResult() + { + $provider = new UserAgentApiCom($this->getClient(), 'apiKey123'); + + /* + * general + */ + $this->assertIsRealResult($provider, true, 'something UNKNOWN'); + } + /** * Empty user agent * * @expectedException \UserAgentParser\Exception\NoResultFoundException */ - public function testGetResultNoResultFoundExceptionEmptyUserAgent() + public function testParseNoResultFoundExceptionEmptyUserAgent() { $responseQueue = [ new Response(200), @@ -101,7 +118,7 @@ public function testGetResultNoResultFoundExceptionEmptyUserAgent() * * @expectedException \UserAgentParser\Exception\InvalidCredentialsException */ - public function testGetResultInvalidCredentialsException() + public function testParseInvalidCredentialsException() { $rawResult = new stdClass(); $rawResult->error = new stdClass(); @@ -121,7 +138,7 @@ public function testGetResultInvalidCredentialsException() * * @expectedException \UserAgentParser\Exception\RequestException */ - public function testGetResultRequestExceptionUserAgentInvalid() + public function testParseRequestExceptionUserAgentInvalid() { $rawResult = new stdClass(); $rawResult->error = new stdClass(); @@ -141,7 +158,7 @@ public function testGetResultRequestExceptionUserAgentInvalid() * * @expectedException \UserAgentParser\Exception\RequestException */ - public function testGetResultRequestException() + public function testParseRequestException() { $responseQueue = [ new Response(500), @@ -157,7 +174,7 @@ public function testGetResultRequestException() * * @expectedException \UserAgentParser\Exception\RequestException */ - public function testGetResultRequestExceptionContentType() + public function testParseRequestExceptionContentType() { $responseQueue = [ new Response(200, [ @@ -175,7 +192,7 @@ public function testGetResultRequestExceptionContentType() * * @expectedException \UserAgentParser\Exception\NoResultFoundException */ - public function testGetResultNoResultFoundException() + public function testParseNoResultFoundException() { $rawResult = new stdClass(); $rawResult->error = new stdClass(); @@ -197,7 +214,7 @@ public function testGetResultNoResultFoundException() * * @expectedException \UserAgentParser\Exception\RequestException */ - public function testGetResultRequestExceptionNoData() + public function testParseRequestExceptionNoData() { $rawResult = new stdClass(); diff --git a/tests/unit/Provider/Http/UserAgentStringComTest.php b/tests/unit/Provider/Http/UserAgentStringComTest.php index 741fdfc..b3d5a3e 100644 --- a/tests/unit/Provider/Http/UserAgentStringComTest.php +++ b/tests/unit/Provider/Http/UserAgentStringComTest.php @@ -13,9 +13,9 @@ * * @covers UserAgentParser\Provider\Http\UserAgentStringCom */ -class UserAgentStringComTest extends AbstractProviderTestCase +class UserAgentStringComTest extends AbstractProviderTestCase implements RequiredProviderTestInterface { - public function testName() + public function testGetName() { $provider = new UserAgentStringCom($this->getClient()); @@ -42,6 +42,12 @@ public function testVersion() $this->assertNull($provider->getVersion()); } + public function testUpdateDate() + { + $provider = new UserAgentStringCom($this->getClient()); + + $this->assertNull($provider->getUpdateDate()); + } public function testDetectionCapabilities() { @@ -80,12 +86,24 @@ public function testDetectionCapabilities() ], $provider->getDetectionCapabilities()); } + public function testIsRealResult() + { + $provider = new UserAgentStringCom($this->getClient()); + + /* + * general + */ + $this->assertIsRealResult($provider, false, 'unknown'); + $this->assertIsRealResult($provider, true, 'unknown something'); + $this->assertIsRealResult($provider, true, 'something unknown'); + } + /** * Empty user agent * * @expectedException \UserAgentParser\Exception\NoResultFoundException */ - public function testGetResultNoResultFoundExceptionEmptyUserAgent() + public function testParseNoResultFoundExceptionEmptyUserAgent() { $responseQueue = [ new Response(200), @@ -101,7 +119,7 @@ public function testGetResultNoResultFoundExceptionEmptyUserAgent() * * @expectedException \UserAgentParser\Exception\RequestException */ - public function testGetResultRequestExceptionContentType() + public function testParseRequestExceptionContentType() { $responseQueue = [ new Response(200, [ @@ -119,7 +137,7 @@ public function testGetResultRequestExceptionContentType() * * @expectedException \UserAgentParser\Exception\RequestException */ - public function testGetResultRequestExceptionNoData() + public function testParseRequestExceptionNoData() { $rawResult = 'something'; @@ -325,36 +343,4 @@ public function testVersionUnderscore() $this->assertProviderResult($result, $expectedResult); } - - /** - * @dataProvider isRealResult - */ - public function testRealResult($value, $group, $part, $expectedResult) - { - $class = new \ReflectionClass('UserAgentParser\Provider\Http\UserAgentStringCom'); - $method = $class->getMethod('isRealResult'); - $method->setAccessible(true); - - $provider = new UserAgentStringCom($this->getClient([]), 'apiUser', 'apiKey123'); - - $actualResult = $method->invokeArgs($provider, [ - $value, - $group, - $part, - ]); - - $this->assertEquals($expectedResult, $actualResult); - } - - public function isRealResult() - { - return [ - [ - 'unknown', - null, - null, - false, - ], - ]; - } } diff --git a/tests/unit/Provider/Http/WhatIsMyBrowserComTest.php b/tests/unit/Provider/Http/WhatIsMyBrowserComTest.php index 8ac8357..443630c 100644 --- a/tests/unit/Provider/Http/WhatIsMyBrowserComTest.php +++ b/tests/unit/Provider/Http/WhatIsMyBrowserComTest.php @@ -13,9 +13,9 @@ * * @covers UserAgentParser\Provider\Http\WhatIsMyBrowserCom */ -class WhatIsMyBrowserComTest extends AbstractProviderTestCase +class WhatIsMyBrowserComTest extends AbstractProviderTestCase implements RequiredProviderTestInterface { - public function testName() + public function testGetName() { $provider = new WhatIsMyBrowserCom($this->getClient(), 'apiKey123'); @@ -43,6 +43,13 @@ public function testVersion() $this->assertNull($provider->getVersion()); } + public function testUpdateDate() + { + $provider = new WhatIsMyBrowserCom($this->getClient(), 'apiKey123'); + + $this->assertNull($provider->getUpdateDate()); + } + public function testDetectionCapabilities() { $provider = new WhatIsMyBrowserCom($this->getClient(), 'apiKey123'); @@ -80,12 +87,66 @@ public function testDetectionCapabilities() ], $provider->getDetectionCapabilities()); } + public function testIsRealResult() + { + $provider = new WhatIsMyBrowserCom($this->getClient(), 'apiKey123'); + + /* + * browser name + */ + $this->assertIsRealResult($provider, false, 'Unknown Mobile Browser', 'browser', 'name'); + $this->assertIsRealResult($provider, true, 'Unknown Mobile Browser something', 'browser', 'name'); + $this->assertIsRealResult($provider, true, 'something Unknown Mobile Browser', 'browser', 'name'); + + $this->assertIsRealResult($provider, false, 'Unknown browser', 'browser', 'name'); + $this->assertIsRealResult($provider, true, 'Unknown browser something', 'browser', 'name'); + $this->assertIsRealResult($provider, true, 'something Unknown browser', 'browser', 'name'); + + $this->assertIsRealResult($provider, false, 'Webkit based browser', 'browser', 'name'); + $this->assertIsRealResult($provider, true, 'Webkit based browser something', 'browser', 'name'); + $this->assertIsRealResult($provider, true, 'something Webkit based browser', 'browser', 'name'); + + $this->assertIsRealResult($provider, false, 'a UNIX based OS', 'browser', 'name'); + $this->assertIsRealResult($provider, true, 'a UNIX based OS something', 'browser', 'name'); + $this->assertIsRealResult($provider, true, 'something a UNIX based OS', 'browser', 'name'); + + /* + * OS name + */ + $this->assertIsRealResult($provider, false, 'Smart TV', 'operatingSystem', 'name'); + $this->assertIsRealResult($provider, true, 'Smart TV something', 'operatingSystem', 'name'); + $this->assertIsRealResult($provider, true, 'something Smart TV', 'operatingSystem', 'name'); + + /* + * device model + */ + $this->assertIsRealResult($provider, false, 'HTC', 'device', 'model'); + $this->assertIsRealResult($provider, true, 'HTC something', 'device', 'model'); + $this->assertIsRealResult($provider, true, 'something HTC', 'device', 'model'); + + $this->assertIsRealResult($provider, false, 'Mobile', 'device', 'model'); + $this->assertIsRealResult($provider, true, 'Mobile something', 'device', 'model'); + $this->assertIsRealResult($provider, true, 'something Mobile', 'device', 'model'); + + $this->assertIsRealResult($provider, false, 'Android Phone', 'device', 'model'); + $this->assertIsRealResult($provider, true, 'Android Phone something', 'device', 'model'); + $this->assertIsRealResult($provider, true, 'something Android Phone', 'device', 'model'); + + $this->assertIsRealResult($provider, false, 'Android Tablet', 'device', 'model'); + $this->assertIsRealResult($provider, true, 'Android Tablet something', 'device', 'model'); + $this->assertIsRealResult($provider, true, 'something Android Tablet', 'device', 'model'); + + $this->assertIsRealResult($provider, false, 'Tablet', 'device', 'model'); + $this->assertIsRealResult($provider, true, 'Tablet something', 'device', 'model'); + $this->assertIsRealResult($provider, true, 'something Tablet', 'device', 'model'); + } + /** * Empty user agent * * @expectedException \UserAgentParser\Exception\NoResultFoundException */ - public function testGetResultNoResultFoundExceptionEmptyUserAgent() + public function testParseNoResultFoundExceptionEmptyUserAgent() { $responseQueue = [ new Response(200), @@ -101,7 +162,7 @@ public function testGetResultNoResultFoundExceptionEmptyUserAgent() * * @expectedException \UserAgentParser\Exception\RequestException */ - public function testGetResultRequestExceptionContentType() + public function testParseRequestExceptionContentType() { $responseQueue = [ new Response(200, [ @@ -138,7 +199,7 @@ public function testParseNoResultFoundException() * * @expectedException \UserAgentParser\Exception\LimitationExceededException */ - public function testGetResultLimitationExceededException() + public function testParseLimitationExceededException() { $rawResult = new stdClass(); $rawResult->message_code = 'usage_limit_exceeded'; @@ -159,7 +220,7 @@ public function testGetResultLimitationExceededException() * * @expectedException \UserAgentParser\Exception\InvalidCredentialsException */ - public function testGetResultInvalidCredentialsExceptionNoKey() + public function testParseInvalidCredentialsExceptionNoKey() { $rawResult = new stdClass(); $rawResult->message_code = 'no_api_user_key'; @@ -180,7 +241,7 @@ public function testGetResultInvalidCredentialsExceptionNoKey() * * @expectedException \UserAgentParser\Exception\InvalidCredentialsException */ - public function testGetResultInvalidCredentialsExceptionInvalidKey() + public function testParseInvalidCredentialsExceptionInvalidKey() { $rawResult = new stdClass(); $rawResult->message_code = 'user_key_invalid'; @@ -201,7 +262,7 @@ public function testGetResultInvalidCredentialsExceptionInvalidKey() * * @expectedException \UserAgentParser\Exception\RequestException */ - public function testGetResultRequestExceptionUnknown() + public function testParseRequestExceptionUnknown() { $rawResult = new stdClass(); $rawResult->result = 'unknown'; @@ -222,7 +283,7 @@ public function testGetResultRequestExceptionUnknown() * * @expectedException \UserAgentParser\Exception\RequestException */ - public function testGetResultRequestExceptionMissingData() + public function testParseRequestExceptionMissingData() { $rawResult = new stdClass(); $rawResult->result = 'success'; @@ -586,99 +647,4 @@ public function testParseDeviceDefaultValue() $this->assertProviderResult($result, $expectedResult); } - - /** - * @dataProvider isRealResult - */ - public function testRealResult($value, $group, $part, $expectedResult) - { - $class = new \ReflectionClass('UserAgentParser\Provider\Http\WhatIsMyBrowserCom'); - $method = $class->getMethod('isRealResult'); - $method->setAccessible(true); - - $provider = new WhatIsMyBrowserCom($this->getClient([]), 'apiUser', 'apiKey123'); - - $actualResult = $method->invokeArgs($provider, [ - $value, - $group, - $part, - ]); - - $this->assertEquals($expectedResult, $actualResult); - } - - public function isRealResult() - { - return [ - /* - * general - */ - [ - 'Unknown', - null, - null, - true, - ], - /* - * browserName - */ - [ - 'Unknown Mobile Browser', - 'browser', - 'name', - false, - ], - [ - 'Unknown browser', - 'browser', - 'name', - false, - ], - [ - 'Webkit based browser', - 'browser', - 'name', - false, - ], - /* - * deviceModel - */ - [ - 'HTC', - 'device', - 'model', - false, - ], - [ - 'HTC one', - 'device', - 'model', - true, - ], - [ - 'Mobile', - 'device', - 'model', - false, - ], - [ - 'Android Phone', - 'device', - 'model', - false, - ], - [ - 'Android Tablet', - 'device', - 'model', - false, - ], - [ - 'Tablet', - 'device', - 'model', - false, - ], - ]; - } } diff --git a/tests/unit/Provider/JenssegersAgentTest.php b/tests/unit/Provider/JenssegersAgentTest.php index ab2ee67..fdfe85e 100644 --- a/tests/unit/Provider/JenssegersAgentTest.php +++ b/tests/unit/Provider/JenssegersAgentTest.php @@ -11,7 +11,7 @@ * * @covers UserAgentParser\Provider\JenssegersAgent */ -class JenssegersAgentTest extends AbstractProviderTestCase +class JenssegersAgentTest extends AbstractProviderTestCase implements RequiredProviderTestInterface { /** * @@ -46,7 +46,7 @@ public function testPackageNotLoadedException() rename($tempFile, $file); } - public function testName() + public function testGetName() { $provider = new JenssegersAgent(); @@ -118,6 +118,18 @@ public function testDetectionCapabilities() ], $provider->getDetectionCapabilities()); } + public function testIsRealResult() + { + $provider = new JenssegersAgent(); + + /* + * browser name + */ + $this->assertIsRealResult($provider, false, 'GenericBrowser', 'browser', 'name'); + $this->assertIsRealResult($provider, true, 'GenericBrowser something', 'browser', 'name'); + $this->assertIsRealResult($provider, true, 'something GenericBrowser', 'browser', 'name'); + } + public function testParser() { $provider = new JenssegersAgent(); @@ -128,7 +140,7 @@ public function testParser() /** * @expectedException \UserAgentParser\Exception\NoResultFoundException */ - public function testNoResultFoundException() + public function testParseNoResultFoundException() { $parser = $this->getParser(); diff --git a/tests/unit/Provider/PiwikDeviceDetectorTest.php b/tests/unit/Provider/PiwikDeviceDetectorTest.php index bf4419d..43c4dc4 100644 --- a/tests/unit/Provider/PiwikDeviceDetectorTest.php +++ b/tests/unit/Provider/PiwikDeviceDetectorTest.php @@ -12,7 +12,7 @@ * * @covers UserAgentParser\Provider\PiwikDeviceDetector */ -class PiwikDeviceDetectorTest extends AbstractProviderTestCase +class PiwikDeviceDetectorTest extends AbstractProviderTestCase implements RequiredProviderTestInterface { /** * @@ -43,7 +43,7 @@ public function testPackageNotLoadedException() rename($tempFile, $file); } - public function testName() + public function testGetName() { $provider = new PiwikDeviceDetector(); @@ -115,6 +115,29 @@ public function testDetectionCapabilities() ], $provider->getDetectionCapabilities()); } + public function testIsRealResult() + { + $provider = new PiwikDeviceDetector(); + + /* + * general + */ + $this->assertIsRealResult($provider, false, 'UNK'); + $this->assertIsRealResult($provider, true, 'UNK something'); + $this->assertIsRealResult($provider, true, 'something UNK'); + + /* + * bot name + */ + $this->assertIsRealResult($provider, false, 'Bot', 'bot', 'name'); + $this->assertIsRealResult($provider, true, 'Bot something', 'bot', 'name'); + $this->assertIsRealResult($provider, true, 'something Bot', 'bot', 'name'); + + $this->assertIsRealResult($provider, false, 'Generic Bot', 'bot', 'name'); + $this->assertIsRealResult($provider, true, 'Generic Bot something', 'bot', 'name'); + $this->assertIsRealResult($provider, true, 'something Generic Bot', 'bot', 'name'); + } + public function testParser() { $provider = new PiwikDeviceDetector(); @@ -130,7 +153,7 @@ public function testParser() /** * @expectedException \UserAgentParser\Exception\NoResultFoundException */ - public function testNoResultFoundException() + public function testParseNoResultFoundException() { $parser = $this->getParser(); @@ -142,7 +165,7 @@ public function testNoResultFoundException() /** * @expectedException \UserAgentParser\Exception\NoResultFoundException */ - public function testNoResultFoundExceptionDefaultValue() + public function testParseNoResultFoundExceptionDefaultValue() { $parser = $this->getParser(); $parser->expects($this->any()) @@ -391,71 +414,4 @@ public function testParseDevice() $this->assertProviderResult($result, $expectedResult); } - - /** - * @dataProvider isRealResult - */ - public function testRealResult($value, $group, $part, $expectedResult) - { - $class = new \ReflectionClass('UserAgentParser\Provider\PiwikDeviceDetector'); - $method = $class->getMethod('isRealResult'); - $method->setAccessible(true); - - $parser = $this->getParser(); - $provider = new PiwikDeviceDetector($parser); - - $actualResult = $method->invokeArgs($provider, [ - $value, - $group, - $part, - ]); - - $this->assertEquals($expectedResult, $actualResult); - } - - public function isRealResult() - { - return [ - /* - * general - */ - [ - DeviceDetector::UNKNOWN, - 'browser', - 'name', - false, - ], - - [ - 'UNKNOWN', - 'browser', - 'name', - true, - ], - - /* - * botName - */ - [ - 'Bot', - 'bot', - 'name', - false, - ], - - [ - 'Bot123', - 'bot', - 'name', - true, - ], - - [ - 'Generic bot', - 'bot', - 'name', - false, - ], - ]; - } } diff --git a/tests/unit/Provider/RequiredProviderTestInterface.php b/tests/unit/Provider/RequiredProviderTestInterface.php new file mode 100644 index 0000000..eb7cb00 --- /dev/null +++ b/tests/unit/Provider/RequiredProviderTestInterface.php @@ -0,0 +1,27 @@ + + * @license MIT + */ +interface RequiredProviderTestInterface +{ + public function testGetName(); + + public function testGetHomepage(); + + public function testGetPackageName(); + + public function testVersion(); + + public function testUpdateDate(); + + public function testDetectionCapabilities(); + + public function testParseNoResultFoundException(); + + public function testIsRealResult(); +} diff --git a/tests/unit/Provider/SinergiBrowserDetectorTest.php b/tests/unit/Provider/SinergiBrowserDetectorTest.php index 6d00959..4670c3d 100644 --- a/tests/unit/Provider/SinergiBrowserDetectorTest.php +++ b/tests/unit/Provider/SinergiBrowserDetectorTest.php @@ -11,7 +11,7 @@ * * @covers UserAgentParser\Provider\SinergiBrowserDetector */ -class SinergiBrowserDetectorTest extends AbstractProviderTestCase +class SinergiBrowserDetectorTest extends AbstractProviderTestCase implements RequiredProviderTestInterface { /** * @@ -64,7 +64,7 @@ public function testPackageNotLoadedException() rename($tempFile, $file); } - public function testName() + public function testGetName() { $provider = new SinergiBrowserDetector(); @@ -136,6 +136,25 @@ public function testDetectionCapabilities() ], $provider->getDetectionCapabilities()); } + public function testIsRealResult() + { + $provider = new SinergiBrowserDetector(); + + /* + * general + */ + $this->assertIsRealResult($provider, false, 'unknown'); + $this->assertIsRealResult($provider, true, 'unknown something'); + $this->assertIsRealResult($provider, true, 'something unknown'); + + /* + * device model + */ + $this->assertIsRealResult($provider, false, 'Windows Phone', 'device', 'model'); + $this->assertIsRealResult($provider, true, 'Windows Phone something', 'device', 'model'); + $this->assertIsRealResult($provider, true, 'something Windows Phone', 'device', 'model'); + } + public function testProvider() { $provider = new SinergiBrowserDetector(); @@ -148,7 +167,7 @@ public function testProvider() /** * @expectedException \UserAgentParser\Exception\NoResultFoundException */ - public function testNoResultFoundException() + public function testParseNoResultFoundException() { $provider = new SinergiBrowserDetector(); @@ -171,7 +190,7 @@ public function testNoResultFoundException() /** * @expectedException \UserAgentParser\Exception\NoResultFoundException */ - public function testNoResultFoundExceptionDefaultValue() + public function testParseNoResultFoundExceptionDefaultValue() { $browserParser = $this->getBrowserParser(); $browserParser->expects($this->any()) @@ -202,7 +221,7 @@ public function testNoResultFoundExceptionDefaultValue() /** * @expectedException \UserAgentParser\Exception\NoResultFoundException */ - public function testNoResultFoundExceptionDefaultValue2() + public function testParseNoResultFoundExceptionDefaultValue2() { $browserParser = $this->getBrowserParser(); $browserParser->expects($this->any()) @@ -480,55 +499,4 @@ public function testParseDeviceDefaultValue() $this->assertProviderResult($result, $expectedResult); } - - /** - * @dataProvider isRealResult - */ - public function testRealResult($value, $group, $part, $expectedResult) - { - $class = new \ReflectionClass('UserAgentParser\Provider\SinergiBrowserDetector'); - $method = $class->getMethod('isRealResult'); - $method->setAccessible(true); - - $provider = new SinergiBrowserDetector(); - - $actualResult = $method->invokeArgs($provider, [ - $value, - $group, - $part, - ]); - - $this->assertEquals($expectedResult, $actualResult); - } - - public function isRealResult() - { - return [ - /* - * general - */ - [ - 'unknown', - null, - null, - false, - ], - [ - 'Not unknown', - null, - null, - true, - ], - - /* - * deviceModel - */ - [ - 'Windows Phone', - 'device', - 'model', - false, - ], - ]; - } } diff --git a/tests/unit/Provider/UAParserTest.php b/tests/unit/Provider/UAParserTest.php index cf3431e..118b6a1 100644 --- a/tests/unit/Provider/UAParserTest.php +++ b/tests/unit/Provider/UAParserTest.php @@ -5,14 +5,13 @@ use UserAgentParser\Provider\UAParser; /** - * * * @author Martin Keckeis * @license MIT - * - * @covers UserAgentParser\Provider\UAParser + * + * @covers UserAgentParser\Provider\UAParser */ -class UAParserTest extends AbstractProviderTestCase +class UAParserTest extends AbstractProviderTestCase implements RequiredProviderTestInterface { /** * @@ -64,7 +63,7 @@ public function testPackageNotLoadedException() rename($tempFile, $file); } - public function testName() + public function testGetName() { $provider = new UAParser(); @@ -136,6 +135,91 @@ public function testDetectionCapabilities() ], $provider->getDetectionCapabilities()); } + public function testIsRealResult() + { + $provider = new UAParser(); + + /* + * general + */ + $this->assertIsRealResult($provider, false, 'Other'); + $this->assertIsRealResult($provider, true, 'Other something'); + $this->assertIsRealResult($provider, true, 'something Other'); + + /* + * device brand + */ + $this->assertIsRealResult($provider, false, 'Generic', 'device', 'brand'); + $this->assertIsRealResult($provider, false, 'Generic something', 'device', 'brand'); + $this->assertIsRealResult($provider, true, 'something Generic', 'device', 'brand'); + + $this->assertIsRealResult($provider, false, 'unknown', 'device', 'brand'); + $this->assertIsRealResult($provider, true, 'unknown something', 'device', 'brand'); + $this->assertIsRealResult($provider, true, 'something unknown', 'device', 'brand'); + + /* + * device model + */ + $this->assertIsRealResult($provider, false, 'generic', 'device', 'model'); + $this->assertIsRealResult($provider, true, 'generic something', 'device', 'model'); + $this->assertIsRealResult($provider, true, 'something generic', 'device', 'model'); + + $this->assertIsRealResult($provider, false, 'Smartphone', 'device', 'model'); + $this->assertIsRealResult($provider, true, 'Smartphone something', 'device', 'model'); + $this->assertIsRealResult($provider, true, 'something Smartphone', 'device', 'model'); + + $this->assertIsRealResult($provider, false, 'Feature Phone', 'device', 'model'); + $this->assertIsRealResult($provider, true, 'Feature Phone something', 'device', 'model'); + $this->assertIsRealResult($provider, true, 'something Feature Phone', 'device', 'model'); + + $this->assertIsRealResult($provider, false, 'iOS-Device', 'device', 'model'); + $this->assertIsRealResult($provider, true, 'iOS-Device something', 'device', 'model'); + $this->assertIsRealResult($provider, true, 'something iOS-Device', 'device', 'model'); + + $this->assertIsRealResult($provider, false, 'Tablet', 'device', 'model'); + $this->assertIsRealResult($provider, true, 'Tablet something', 'device', 'model'); + $this->assertIsRealResult($provider, true, 'something Tablet', 'device', 'model'); + + $this->assertIsRealResult($provider, false, 'Touch', 'device', 'model'); + $this->assertIsRealResult($provider, true, 'Touch something', 'device', 'model'); + $this->assertIsRealResult($provider, true, 'something Touch', 'device', 'model'); + + $this->assertIsRealResult($provider, false, 'Windows', 'device', 'model'); + $this->assertIsRealResult($provider, true, 'Windows something', 'device', 'model'); + $this->assertIsRealResult($provider, true, 'something Windows', 'device', 'model'); + + $this->assertIsRealResult($provider, false, 'Windows Phone', 'device', 'model'); + $this->assertIsRealResult($provider, true, 'Windows Phone something', 'device', 'model'); + $this->assertIsRealResult($provider, true, 'something Windows Phone', 'device', 'model'); + + $this->assertIsRealResult($provider, false, 'Android', 'device', 'model'); + $this->assertIsRealResult($provider, true, 'Android something', 'device', 'model'); + $this->assertIsRealResult($provider, true, 'something Android', 'device', 'model'); + + /* + * bot name + */ + $this->assertIsRealResult($provider, false, 'Other', 'bot', 'name'); + $this->assertIsRealResult($provider, true, 'Other something', 'bot', 'name'); + $this->assertIsRealResult($provider, true, 'something Other', 'bot', 'name'); + + $this->assertIsRealResult($provider, false, 'crawler', 'bot', 'name'); + $this->assertIsRealResult($provider, true, 'crawler something', 'bot', 'name'); + $this->assertIsRealResult($provider, true, 'something crawler', 'bot', 'name'); + + $this->assertIsRealResult($provider, false, 'robot', 'bot', 'name'); + $this->assertIsRealResult($provider, true, 'robot something', 'bot', 'name'); + $this->assertIsRealResult($provider, true, 'something robot', 'bot', 'name'); + + $this->assertIsRealResult($provider, false, 'crawl', 'bot', 'name'); + $this->assertIsRealResult($provider, true, 'crawl something', 'bot', 'name'); + $this->assertIsRealResult($provider, true, 'something crawl', 'bot', 'name'); + + $this->assertIsRealResult($provider, false, 'Spider', 'bot', 'name'); + $this->assertIsRealResult($provider, true, 'Spider something', 'bot', 'name'); + $this->assertIsRealResult($provider, true, 'something Spider', 'bot', 'name'); + } + public function testParser() { $provider = new UAParser(); @@ -151,7 +235,7 @@ public function testParser() /** * @expectedException \UserAgentParser\Exception\NoResultFoundException */ - public function testNoResultFoundException() + public function testParseNoResultFoundException() { $parser = $this->getParser($this->getResultMock()); @@ -163,7 +247,7 @@ public function testNoResultFoundException() /** * @expectedException \UserAgentParser\Exception\NoResultFoundException */ - public function testNoResultFoundExceptionDefaultValue() + public function testParseNoResultFoundExceptionDefaultValue() { $result = $this->getResultMock(); $result->ua->family = 'Other'; @@ -178,7 +262,7 @@ public function testNoResultFoundExceptionDefaultValue() /** * @expectedException \UserAgentParser\Exception\NoResultFoundException */ - public function testNoResultFoundExceptionDefaultValueDeviceModel() + public function testParseNoResultFoundExceptionDefaultValueDeviceModel() { $result = $this->getResultMock(); $result->device->model = 'Smartphone'; @@ -385,141 +469,4 @@ public function testParseDeviceDefaultValue() $this->assertProviderResult($result, $expectedResult); } - - /** - * @dataProvider isRealResult - */ - public function testRealResult($value, $group, $part, $expectedResult) - { - $class = new \ReflectionClass('UserAgentParser\Provider\UAParser'); - $method = $class->getMethod('isRealResult'); - $method->setAccessible(true); - - $provider = new UAParser($this->getParser($this->getResultMock())); - - $actualResult = $method->invokeArgs($provider, [ - $value, - $group, - $part, - ]); - - $this->assertEquals($expectedResult, $actualResult); - } - - public function isRealResult() - { - return [ - /* - * general - */ - [ - 'Other', - null, - null, - false, - ], - - /* - * deviceBrand - */ - [ - 'Generic', - 'device', - 'brand', - false, - ], - [ - 'Generic', - null, - null, - true, - ], - - /* - * deviceModel - */ - [ - 'generic', - 'device', - 'model', - false, - ], - [ - 'Smartphone', - 'device', - 'model', - false, - ], - [ - 'Feature Phone', - 'device', - 'model', - false, - ], - [ - 'iOS-Device', - 'device', - 'model', - false, - ], - [ - 'Tablet', - 'device', - 'model', - false, - ], - [ - 'Touch', - 'device', - 'model', - false, - ], - [ - 'Windows', - 'device', - 'model', - false, - ], - [ - 'Windows Phone', - 'device', - 'model', - false, - ], - - /* - * botName - */ - [ - 'Other', - 'bot', - 'name', - false, - ], - [ - 'crawler', - 'bot', - 'name', - false, - ], - [ - 'robot', - 'bot', - 'name', - false, - ], - [ - 'crawl', - 'bot', - 'name', - false, - ], - [ - 'Spider', - 'bot', - 'name', - false, - ], - ]; - } } diff --git a/tests/unit/Provider/WhichBrowserTest.php b/tests/unit/Provider/WhichBrowserTest.php index 0533d68..f49744c 100644 --- a/tests/unit/Provider/WhichBrowserTest.php +++ b/tests/unit/Provider/WhichBrowserTest.php @@ -11,7 +11,7 @@ * * @covers UserAgentParser\Provider\WhichBrowser */ -class WhichBrowserTest extends AbstractProviderTestCase +class WhichBrowserTest extends AbstractProviderTestCase implements RequiredProviderTestInterface { /** * @@ -47,7 +47,7 @@ public function testPackageNotLoadedException() rename($tempFile, $file); } - public function testName() + public function testGetName() { $provider = new WhichBrowser(); @@ -119,6 +119,16 @@ public function testDetectionCapabilities() ], $provider->getDetectionCapabilities()); } + public function testIsRealResult() + { + $provider = new WhichBrowser(); + + /* + * general + */ + $this->assertIsRealResult($provider, true, 'something'); + } + public function testParser() { $provider = new WhichBrowser(); @@ -129,7 +139,7 @@ public function testParser() /** * @expectedException \UserAgentParser\Exception\NoResultFoundException */ - public function testNoResultFoundException() + public function testParseNoResultFoundException() { $parser = $this->getParser(); diff --git a/tests/unit/Provider/WootheeTest.php b/tests/unit/Provider/WootheeTest.php index d5cdcd3..a9142bc 100644 --- a/tests/unit/Provider/WootheeTest.php +++ b/tests/unit/Provider/WootheeTest.php @@ -11,7 +11,7 @@ * * @covers UserAgentParser\Provider\Woothee */ -class WootheeTest extends AbstractProviderTestCase +class WootheeTest extends AbstractProviderTestCase implements RequiredProviderTestInterface { /** * @@ -44,7 +44,7 @@ public function testPackageNotLoadedException() rename($tempFile, $file); } - public function testName() + public function testGetName() { $provider = new Woothee(); @@ -116,6 +116,32 @@ public function testDetectionCapabilities() ], $provider->getDetectionCapabilities()); } + public function testIsRealResult() + { + $provider = new Woothee(); + + /* + * general + */ + $this->assertIsRealResult($provider, false, 'UNKNOWN'); + $this->assertIsRealResult($provider, true, 'UNKNOWN something'); + $this->assertIsRealResult($provider, true, 'something UNKNOWN'); + + /* + * device type + */ + $this->assertIsRealResult($provider, false, 'misc', 'device', 'type'); + $this->assertIsRealResult($provider, true, 'misc something', 'device', 'type'); + $this->assertIsRealResult($provider, true, 'something misc', 'device', 'type'); + + /* + * bot name + */ + $this->assertIsRealResult($provider, false, 'misc crawler', 'bot', 'name'); + $this->assertIsRealResult($provider, true, 'misc crawler something', 'bot', 'name'); + $this->assertIsRealResult($provider, true, 'something misc crawler', 'bot', 'name'); + } + public function testParser() { $provider = new Woothee(); @@ -126,7 +152,7 @@ public function testParser() /** * @expectedException \UserAgentParser\Exception\NoResultFoundException */ - public function testNoResultFoundException() + public function testParseNoResultFoundException() { $parser = $this->getParser(); @@ -143,7 +169,7 @@ public function testNoResultFoundException() /** * @expectedException \UserAgentParser\Exception\NoResultFoundException */ - public function testNoResultFoundExceptionDefaultValue() + public function testParseNoResultFoundExceptionDefaultBrowserName() { $parser = $this->getParser([ 'name' => 'UNKNOWN', @@ -159,6 +185,25 @@ public function testNoResultFoundExceptionDefaultValue() $result = $provider->parse('A real user agent...'); } + /** + * @expectedException \UserAgentParser\Exception\NoResultFoundException + */ + public function testParseNoResultFoundExceptionDefaultDeviceType() + { + $parser = $this->getParser([ + 'category' => 'misc', + ]); + + $provider = new Woothee(); + + $reflection = new \ReflectionClass($provider); + $property = $reflection->getProperty('parser'); + $property->setAccessible(true); + $property->setValue($provider, $parser); + + $result = $provider->parse('A real user agent...'); + } + /** * Bot */ @@ -333,49 +378,4 @@ public function testParseDeviceMobilephone() $this->assertProviderResult($result, $expectedResult); } - - /** - * @dataProvider isRealResult - */ - public function testRealResult($value, $group, $part, $expectedResult) - { - $class = new \ReflectionClass('UserAgentParser\Provider\Woothee'); - $method = $class->getMethod('isRealResult'); - $method->setAccessible(true); - - $provider = new Woothee(); - - $actualResult = $method->invokeArgs($provider, [ - $value, - $group, - $part, - ]); - - $this->assertEquals($expectedResult, $actualResult); - } - - public function isRealResult() - { - return [ - /* - * general - */ - [ - 'UNKNOWN', - null, - null, - false, - ], - - /* - * botName - */ - [ - 'misc crawler', - 'bot', - 'name', - false, - ], - ]; - } } diff --git a/tests/unit/Provider/WurflTest.php b/tests/unit/Provider/WurflTest.php index cab145f..ecc7d0d 100644 --- a/tests/unit/Provider/WurflTest.php +++ b/tests/unit/Provider/WurflTest.php @@ -11,7 +11,7 @@ * * @covers UserAgentParser\Provider\Wurfl */ -class WurflTest extends AbstractProviderTestCase +class WurflTest extends AbstractProviderTestCase implements RequiredProviderTestInterface { private function getManager() { @@ -20,7 +20,7 @@ private function getManager() return $mock; } - public function testName() + public function testGetName() { $provider = new Wurfl($this->getManager()); @@ -155,6 +155,86 @@ public function testDetectionCapabilities() ], $provider->getDetectionCapabilities()); } + public function testIsRealResult() + { + $manager = $this->getManager(); + + $provider = new Wurfl($manager); + + /* + * OS name + */ + $this->assertIsRealResult($provider, false, 'unknown', 'operatingSystem', 'name'); + $this->assertIsRealResult($provider, true, 'unknown something', 'operatingSystem', 'name'); + $this->assertIsRealResult($provider, true, 'something unknown', 'operatingSystem', 'name'); + + $this->assertIsRealResult($provider, false, 'en', 'operatingSystem', 'name'); + $this->assertIsRealResult($provider, true, 'en something', 'operatingSystem', 'name'); + $this->assertIsRealResult($provider, true, 'something en', 'operatingSystem', 'name'); + + $this->assertIsRealResult($provider, false, 'en_US', 'operatingSystem', 'name'); + $this->assertIsRealResult($provider, true, 'en_US something', 'operatingSystem', 'name'); + $this->assertIsRealResult($provider, true, 'something en_US', 'operatingSystem', 'name'); + + $this->assertIsRealResult($provider, false, 'Desktop', 'operatingSystem', 'name'); + $this->assertIsRealResult($provider, true, 'Desktop something', 'operatingSystem', 'name'); + $this->assertIsRealResult($provider, true, 'something Desktop', 'operatingSystem', 'name'); + + $this->assertIsRealResult($provider, false, 'Mobile', 'operatingSystem', 'name'); + $this->assertIsRealResult($provider, true, 'Mobile something', 'operatingSystem', 'name'); + $this->assertIsRealResult($provider, true, 'something Mobile', 'operatingSystem', 'name'); + + $this->assertIsRealResult($provider, false, 'Randomized by FreeSafeIP.com', 'operatingSystem', 'name'); + $this->assertIsRealResult($provider, true, 'Randomized by FreeSafeIP.com something', 'operatingSystem', 'name'); + $this->assertIsRealResult($provider, true, 'something Randomized by FreeSafeIP.com', 'operatingSystem', 'name'); + + /* + * Device brand + */ + $this->assertIsRealResult($provider, false, 'Generic', 'device', 'brand'); + $this->assertIsRealResult($provider, true, 'Generic something', 'device', 'brand'); + $this->assertIsRealResult($provider, true, 'something Generic', 'device', 'brand'); + + /* + * Device model + */ + $this->assertIsRealResult($provider, false, 'Android', 'device', 'model'); + $this->assertIsRealResult($provider, false, 'Android 5.0', 'device', 'model'); + $this->assertIsRealResult($provider, true, 'something Android', 'device', 'model'); + + $this->assertIsRealResult($provider, false, 'Windows Phone', 'device', 'model'); + $this->assertIsRealResult($provider, false, 'Windows Phone something', 'device', 'model'); + $this->assertIsRealResult($provider, true, 'something Windows Phone', 'device', 'model'); + + $this->assertIsRealResult($provider, false, 'Windows Mobile', 'device', 'model'); + $this->assertIsRealResult($provider, false, 'Windows Mobile something', 'device', 'model'); + $this->assertIsRealResult($provider, true, 'something Windows Mobile', 'device', 'model'); + + $this->assertIsRealResult($provider, false, 'Firefox', 'device', 'model'); + $this->assertIsRealResult($provider, false, 'Firefox something', 'device', 'model'); + $this->assertIsRealResult($provider, true, 'something Firefox', 'device', 'model'); + + $this->assertIsRealResult($provider, false, 'unrecognized', 'device', 'model'); + $this->assertIsRealResult($provider, false, 'unrecognized something', 'device', 'model'); + $this->assertIsRealResult($provider, true, 'something unrecognized', 'device', 'model'); + + $this->assertIsRealResult($provider, false, 'Generic', 'device', 'model'); + $this->assertIsRealResult($provider, false, 'Generic something', 'device', 'model'); + $this->assertIsRealResult($provider, true, 'something Generic', 'device', 'model'); + + $this->assertIsRealResult($provider, false, 'Disguised as Macintosh', 'device', 'model'); + $this->assertIsRealResult($provider, true, 'Disguised as Macintosh something', 'device', 'model'); + $this->assertIsRealResult($provider, true, 'something Disguised as Macintosh', 'device', 'model'); + + $this->assertIsRealResult($provider, false, 'Windows RT', 'device', 'model'); + $this->assertIsRealResult($provider, false, 'Windows RT something', 'device', 'model'); + $this->assertIsRealResult($provider, true, 'something Windows RT', 'device', 'model'); + + $this->assertIsRealResult($provider, false, 'Tablet on Android', 'device', 'model'); + $this->assertIsRealResult($provider, true, 'Tablet on Android something', 'device', 'model'); + $this->assertIsRealResult($provider, true, 'something Tablet on Android', 'device', 'model'); + } + public function testParser() { $manager = $this->getManager(); @@ -167,7 +247,7 @@ public function testParser() /** * @expectedException \UserAgentParser\Exception\NoResultFoundException */ - public function testNoResultFoundException() + public function testParseNoResultFoundException() { $return = $this->getMock('Wurfl\CustomDevice', [], [], '', false); @@ -508,115 +588,4 @@ public function testParseDeviceDefaultValue() $this->assertProviderResult($result, $expectedResult); } - - /** - * @dataProvider isRealResult - */ - public function testRealResult($value, $group, $part, $expectedResult) - { - $class = new \ReflectionClass('UserAgentParser\Provider\Wurfl'); - $method = $class->getMethod('isRealResult'); - $method->setAccessible(true); - - $manager = $this->getManager(); - - $provider = new Wurfl($manager); - - $actualResult = $method->invokeArgs($provider, [ - $value, - $group, - $part, - ]); - - $this->assertEquals($expectedResult, $actualResult); - } - - public function isRealResult() - { - return [ - /* - * osName - */ - [ - 'Unknown', - 'operatingSystem', - 'name', - false, - ], - - /* - * deviceBrand - */ - [ - 'Generic', - 'device', - 'brand', - false, - ], - - /* - * deviceModel - */ - [ - 'Android', - 'device', - 'model', - false, - ], - [ - 'SmartTV', - 'device', - 'model', - false, - ], - [ - 'Windows Phone', - 'device', - 'model', - false, - ], - [ - 'Windows Mobile', - 'device', - 'model', - false, - ], - [ - 'Firefox', - 'device', - 'model', - false, - ], - [ - 'unrecognized', - 'device', - 'model', - false, - ], - [ - 'Generic', - 'device', - 'model', - false, - ], - [ - 'Disguised as Macintosh', - 'device', - 'model', - false, - ], - [ - 'Windows RT', - 'device', - 'model', - false, - ], - [ - 'Tablet on Android', - 'device', - 'model', - false, - ], - ]; - } } diff --git a/tests/unit/Provider/ZsxsoftTest.php b/tests/unit/Provider/ZsxsoftTest.php index 719313c..c2444d5 100644 --- a/tests/unit/Provider/ZsxsoftTest.php +++ b/tests/unit/Provider/ZsxsoftTest.php @@ -4,14 +4,13 @@ use UserAgentParser\Provider\Zsxsoft; /** - * * * @author Martin Keckeis * @license MIT - * - * @covers UserAgentParser\Provider\Zsxsoft + * + * @covers UserAgentParser\Provider\Zsxsoft */ -class ZsxsoftTest extends AbstractProviderTestCase +class ZsxsoftTest extends AbstractProviderTestCase implements RequiredProviderTestInterface { /** * @@ -55,7 +54,7 @@ public function testPackageNotLoadedException() rename($tempFile, $file); } - public function testName() + public function testGetName() { $provider = new Zsxsoft(); @@ -127,6 +126,24 @@ public function testDetectionCapabilities() ], $provider->getDetectionCapabilities()); } + public function testIsRealResult() + { + $provider = new Zsxsoft(); + + $this->assertIsRealResult($provider, false, 'unknown'); + $this->assertIsRealResult($provider, false, 'UnKnown'); + $this->assertIsRealResult($provider, true, 'Unknown thing'); + + $this->assertIsRealResult($provider, false, 'Mozilla Compatible', 'browser', 'name'); + $this->assertIsRealResult($provider, true, 'Mozilla', 'browser', 'name'); + + $this->assertIsRealResult($provider, false, 'Browser', 'device', 'model'); + $this->assertIsRealResult($provider, true, 'Browser model name', 'device', 'model'); + + $this->assertIsRealResult($provider, false, 'Android', 'device', 'model'); + $this->assertIsRealResult($provider, true, 'Android model name', 'device', 'model'); + } + public function testParser() { $provider = new Zsxsoft(); @@ -142,13 +159,52 @@ public function testParser() /** * @expectedException \UserAgentParser\Exception\NoResultFoundException */ - public function testNoResultFoundException() + public function testParseNoResultFoundException() { $provider = new Zsxsoft($this->getParser()); $result = $provider->parse('A real user agent...'); } + /** + * @expectedException \UserAgentParser\Exception\NoResultFoundException + */ + public function testParseNoResultFoundExceptionDefaultBrowserName() + { + $result = [ + 'browser' => [ + 'name' => 'Mozilla Compatible', + 'version' => '3.2.1', + ], + 'os' => [], + 'device' => [], + 'platform' => [], + ]; + + $provider = new Zsxsoft($this->getParser($result)); + + $result = $provider->parse('A real user agent...'); + } + + /** + * @expectedException \UserAgentParser\Exception\NoResultFoundException + */ + public function testParseNoResultFoundExceptionDefaultDeviceModel() + { + $result = [ + 'browser' => [], + 'os' => [], + 'device' => [ + 'model' => 'Android', + ], + 'platform' => [], + ]; + + $provider = new Zsxsoft($this->getParser($result)); + + $result = $provider->parse('A real user agent...'); + } + /** * Browser only */