/** * @param $test * @param $type * @return bool */ private function runTest($test, $type) { $expected = array_diff_key($test, array('user_agent_string' => 1, 'js_ua' => 1, 'js_user_agent_v1' => 1)); $parsed = $this->parser->parse($test['user_agent_string']); if ($this->diff($expected, (array) $parsed[$type])) { $this->printError($test['user_agent_string'], $parsed[$type], $expected); return false; } if ($this->output->getVerbosity() >= OutputInterface::VERBOSITY_VERY_VERBOSE) { $this->printError($test['user_agent_string'], $parsed[$type], $expected, true); } return true; }
public function testItCorrectlyReadsDataFromDefaultLocation() { $string = "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"; $expected = array('user_agent' => array("family" => "Mobile Safari", "major" => "5", "minor" => "1", "patch" => null), "os" => array("family" => "iOS", "major" => "5", "minor" => "0", "patch" => null), "device" => array("device" => "iPhone", "brand" => "Apple", "model" => "iPhone")); $parser = new Parser(); $result = $parser->parse($string); $this->assertEquals($expected, $result); }
public function testItCorrectlyParsesAMatchingString() { $regexData = array('user_agent' => array('@som(est)r(in)g@' => array('family' => 'foo', 'major' => 'bar $2', 'minor' => 1, 'patch' => 2, 'custom' => 'fizz $1')), 'device' => array('@somestring@' => array('device' => 'fizz', 'brand' => 'buzz', 'model' => 3)), 'os' => array('@(some)str(ing)@' => array('minor' => 5, 'patch' => 6))); $expected = array('user_agent' => array('family' => 'foo', 'major' => 'bar in', 'minor' => '1', 'patch' => '2', 'custom' => 'fizz est'), 'device' => array('device' => 'fizz', 'brand' => 'buzz', 'model' => '3'), 'os' => array('family' => 'some', 'major' => 'ing', 'minor' => '5', 'patch' => '6')); $string = "somestring"; $parser = new Parser($regexData); $result = $parser->parse($string); $this->assertEquals($expected, $result); }
public function testToString_2() { $userAgentString = 'PingdomBot 1.4/Other Pingdom.com_bot_version_1.4_(http://www.pingdom.com/)'; $result = $this->parser->parse($userAgentString); $this->assertSame('PingdomBot 1.4/Other', $result->toString()); $this->assertSame('PingdomBot 1.4/Other', (string) $result); $this->assertSame('PingdomBot 1.4', $result->ua->toString()); $this->assertSame('PingdomBot 1.4', (string) $result->ua); $this->assertSame('1.4', $result->ua->toVersion()); $this->assertSame('Other', $result->os->toString()); $this->assertSame('Other', (string) $result->os); $this->assertSame('', $result->os->toVersion()); $this->assertSame($userAgentString, $result->originalUserAgent); }
/** * Parse the user agent string. * * @param string $agent Agent string * * @return \UAParser\Result\Client */ public function parseAgent($agent) { return $this->parser->parse($agent); }