public function testRealResultDevice() { if (!defined('CREDENTIALS_FIFTYONE_DEGREES_COM_KEY')) { $this->markTestSkipped('no credentials available. Please provide tests/credentials.php'); } $provider = new FiftyOneDegreesCom($this->getClient(), CREDENTIALS_FIFTYONE_DEGREES_COM_KEY); $result = $provider->parse('Mozilla/5.0 (iPhone; CPU iPhone OS 5_0 like Mac OS X) AppleWebKit/534.46 (KHTML, like Gecko) Version/5.1 Mobile/9A334 Safari/7534.48.3'); $this->assertEquals(['browser' => ['name' => 'Mobile Safari', 'version' => ['major' => 5, 'minor' => 1, 'patch' => null, 'alias' => null, 'complete' => '5.1']], 'renderingEngine' => ['name' => 'Webkit', 'version' => ['major' => null, 'minor' => null, 'patch' => null, 'alias' => null, 'complete' => null]], 'operatingSystem' => ['name' => 'iOS', 'version' => ['major' => 5, 'minor' => 0, 'patch' => null, 'alias' => null, 'complete' => '5.0']], 'device' => ['model' => 'iPhone', 'brand' => 'Apple', 'type' => 'SmartPhone', 'isMobile' => true, 'isTouch' => null], 'bot' => ['isBot' => null, 'name' => null, 'type' => null]], $result->toArray()); /* * Test the raw result */ $rawResult = $result->getProviderResultRaw(); $this->assertInstanceOf('stdClass', $rawResult); $this->assertCount(137, (array) $rawResult); $this->assertObjectHasAttribute('MatchMethod', $rawResult); $this->assertObjectHasAttribute('BrowserName', $rawResult); $this->assertObjectHasAttribute('BrowserVersion', $rawResult); $this->assertObjectHasAttribute('LayoutEngine', $rawResult); $this->assertObjectHasAttribute('PlatformName', $rawResult); $this->assertObjectHasAttribute('PlatformVersion', $rawResult); $this->assertObjectHasAttribute('HardwareVendor', $rawResult); $this->assertObjectHasAttribute('HardwareFamily', $rawResult); $this->assertObjectHasAttribute('DeviceType', $rawResult); $this->assertObjectHasAttribute('IsMobile', $rawResult); $this->assertObjectHasAttribute('IsCrawler', $rawResult); }
/** * Device only */ public function testParseDevice() { $parseResult = new stdClass(); $parseResult->HardwareVendor = ['Dell']; $parseResult->HardwareFamily = ['Galaxy Note']; $parseResult->DeviceType = ['mobile']; $parseResult->IsMobile = ['True']; $rawResult = new stdClass(); $rawResult->MatchMethod = 'Direct'; $rawResult->Values = $parseResult; $responseQueue = [new Response(200, ['Content-Type' => 'application/json; charset=utf-8'], json_encode($rawResult))]; $provider = new FiftyOneDegreesCom($this->getClient($responseQueue), 'apiKey123'); $result = $provider->parse('A real user agent...'); $expectedResult = ['device' => ['model' => 'Galaxy Note', 'brand' => 'Dell', 'type' => 'mobile', 'isMobile' => true, 'isTouch' => null]]; $this->assertProviderResult($result, $expectedResult); }