b374k
m1n1 1.01
Apache/2.4.41 (Ubuntu)
Linux vmi616275.contaboserver.net 5.4.0-84-generic #94-Ubuntu SMP Thu Aug 26 20:27:37 UTC 2021 x86_64
uid=33(www-data) gid=33(www-data) groups=33(www-data)
server ip : 62.171.164.128 | your ip : 127.0.0.1
safemode OFF
 >  / home / dev2.destoffenstraat.com / vendor / donatj / phpuseragentparser / tests /
Filename/home/dev2.destoffenstraat.com/vendor/donatj/phpuseragentparser/tests/UserAgentParserTest.php
Size1.65 kb
Permissionrw-r--r--
Ownerroot : root
Create time17-Aug-2025 10:26
Last modified30-Oct-2023 17:14
Last accessed21-Aug-2025 20:32
Actionsedit | rename | delete | download (gzip)
Viewtext | code | image
<?php

class UserAgentParserTest extends \PHPUnit\Framework\TestCase {

/**
* @dataProvider userAgentDataProvider
*/
public function test_parse_user_agent( $string, $expected ) {
$result = parse_user_agent($string);
$this->assertSame($expected, $result, $string . " test failed!");
}

public function userAgentDataProvider() {
$out = array();
$uas = json_decode(file_get_contents(__DIR__ . '/user_agents.dist.json'), true);
foreach( $uas as $string => $parts ) {
$out[] = array( $string, $parts );
}

return $out;
}

public function test_parse_user_agent_empty() {
$expected = array(
'platform' => null,
'browser' => null,
'version' => null,
);

$result = parse_user_agent('');
$this->assertSame($result, $expected);

$result = parse_user_agent('Mozilla (asdjkakljasdkljasdlkj) BlahBlah');
$this->assertSame($result, $expected);
}

/**
* I'm no longer using expectedException/setExpectedException because the
* semantics around expecting exceptions have changed so many times I can't
* reliably do it across as wide of a PHP version history as I wish to
* support
*
* @see https://thephp.cc/news/2016/02/questioning-phpunit-best-practices
*/
public function test_no_user_agent_exception() {
unset($_SERVER['HTTP_USER_AGENT']);
try {
parse_user_agent();
} catch(\InvalidArgumentException $ex) {
$this->assertTrue(true); // quiet warning
return;
}

$this->fail("Expected \InvalidArgumentException");
}

public function test_global_user_agent() {
$_SERVER['HTTP_USER_AGENT'] = 'Test/1.0';
$this->assertSame(array( 'platform' => null, 'browser' => 'Test', 'version' => '1.0' ), parse_user_agent());
}

}