Skip to content

Commit

Permalink
Merge pull request #146 from oalders/fix-tests
Browse files Browse the repository at this point in the history
Stop clobbering useragent tests
  • Loading branch information
oalders committed Oct 10, 2018
2 parents c1cd746 + 7ed58a0 commit 108c0fe
Show file tree
Hide file tree
Showing 4 changed files with 109 additions and 245 deletions.
1 change: 1 addition & 0 deletions cpanfile
Expand Up @@ -7,6 +7,7 @@ on 'test' => sub {
requires "ExtUtils::MakeMaker" => "0";
requires "File::Spec" => "0";
requires "FindBin" => "0";
requires "Hash::Merge" => "0";
requires "JSON::PP" => "0";
requires "List::Util" => "1.49";
requires "Path::Tiny" => "0";
Expand Down
43 changes: 28 additions & 15 deletions t/01-detect.t
Expand Up @@ -7,6 +7,7 @@ use Test::Most;
use Test::FailWarnings;

use FindBin;
use Hash::Merge qw( merge );
use JSON::PP ();
use List::Util 1.49 qw(uniq);
use Path::Tiny qw( path );
Expand All @@ -19,31 +20,43 @@ my $w;
}
ok( !$w, 'no warnings on require' );

my $json = path("$FindBin::Bin/useragents.json")->slurp;
my $tests = JSON::PP->new->ascii->decode($json);
my $tests = get_json('useragents.json');
my $more_tests = get_json('more-useragents.json');

$json = path("$FindBin::Bin/more-useragents.json")->slurp;
my $more_tests = JSON::PP->new->ascii->decode($json);
$tests = { %$tests, %$more_tests };
sub get_json {
my $file = shift;
my $json = path( $FindBin::Bin, $file )->slurp;
return JSON::PP->new->ascii->decode($json);
}

my $first_test_count = keys %{$tests};
my $second_test_count = keys %{$more_tests};
my $expected_total_test_count = $first_test_count + $second_test_count;

my $all_tests = merge( $tests, $more_tests );

my $got_total_test_count = keys %{$all_tests};
is( $expected_total_test_count, $got_total_test_count, 'no tests clobbered' );

my @robot_tests = uniq map { $_->[1] } HTTP::BrowserDetect->_robot_tests;

my %ids = map { $_ => 1 } HTTP::BrowserDetect->all_robot_ids;

foreach my $ua ( sort ( keys %{$tests} ) ) {
my @methods = (
'browser', 'browser_beta', 'browser_string', 'device',
'device_beta', 'device_name', 'device_string', 'engine',
'engine_beta', 'engine_string', 'language', 'os', 'os_beta',
'os_string', 'robot', 'robot_beta', 'robot_name', 'robot_string',
'webview',
);

my $test = $tests->{$ua};
foreach my $ua ( sort ( keys %{$all_tests} ) ) {

my $test = $all_tests->{$ua};

my $detected = HTTP::BrowserDetect->new($ua);
subtest $ua => sub {

foreach my $method (
'browser', 'browser_beta', 'browser_string', 'device',
'device_beta', 'device_name', 'device_string', 'engine',
'engine_beta', 'engine_string', 'language', 'os', 'os_beta',
'os_string', 'robot', 'robot_beta', 'robot_name', 'robot_string',
'webview',
) {
foreach my $method (@methods) {
if ( exists $test->{$method} ) {
if ( defined $test->{$method} ) {
eq_or_diff(
Expand Down
104 changes: 80 additions & 24 deletions t/more-useragents.json
Expand Up @@ -21,14 +21,22 @@
"AdsBot-Google (+http://www.google.com/adsbot.html)" : {
"browser_major" : 0,
"browser_minor" : ".0",
"country" : null,
"language" : null,
"major" : null,
"match" : [
"google",
"googleadsbot",
"robot",
"robot_id"
],
"minor" : null,
"no_match" : null,
"other" : null,
"robot" : "googleadsbot",
"robot_name" : "Google AdsBot"
"robot_name" : "Google AdsBot",
"robot_string" : "Google AdsBot",
"version" : null
},
"AdsBot-Google-Mobile (+http://www.google.com/mobile/adsbot.html) Mozilla (iPhone; U; CPU iPhone OS 3 0 like Mac OS X) AppleWebKit (KHTML, like Gecko) Mobile Safari" : {
"browser" : "safari",
Expand Down Expand Up @@ -303,18 +311,25 @@
"DoCoMo/2.0 N905i(c100;TB;W24H16) (compatible; Googlebot-Mobile/2.1; +http://www.google.com/bot.html)" : {
"browser_major" : "2",
"browser_minor" : ".1",
"major" : "2",
"match" : [
"mobile",
"robot",
"google",
"googlemobile",
"google"
"mobile",
"robot"
],
"minor" : "0.1",
"public_major" : "2",
"public_minor" : ".1",
"public_version" : "2.1",
"robot" : "googlemobile",
"robot_beta" : "",
"robot_major" : "2",
"robot_minor" : ".1",
"robot_name" : "Googlebot Mobile",
"robot_version" : "2.1"
"robot_string" : "Googlebot Mobile",
"robot_version" : "2.1",
"version" : "2.1"
},
"Dolphin http client/11.3.8(421) (Android)" : {
"beta" : ".8(421)",
Expand Down Expand Up @@ -410,17 +425,21 @@
"Googlebot-Image/1.0" : {
"browser_major" : "1",
"browser_minor" : ".0",
"major" : "1",
"match" : [
"robot",
"google",
"googlebotimage",
"google"
"robot"
],
"minor" : "0",
"robot" : "googlebotimage",
"robot_beta" : "",
"robot_major" : "1",
"robot_minor" : ".0",
"robot_name" : "Googlebot Images",
"robot_version" : "1.0"
"robot_string" : "Googlebot Images",
"robot_version" : "1.0",
"version" : "1"
},
"Googlebot/2.1 (+http://www.googlebawt.com/bot.html)" : {
"browser_major" : "2",
Expand Down Expand Up @@ -10712,8 +10731,16 @@
"robot" : null
},
"Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/46.0.2490.86 Safari/537.36 Scanning for research (researchscan.comsys.rwth-aachen.de)" : {
"browser_major" : "5",
"browser" : "chrome",
"browser_beta" : ".2490.86",
"browser_major" : "46",
"browser_minor" : ".0",
"browser_string" : "Chrome",
"engine" : "webkit",
"engine_beta" : "",
"engine_major" : "537",
"engine_minor" : ".36",
"engine_string" : "WebKit",
"match" : [
"chrome",
"mac",
Expand All @@ -10722,8 +10749,14 @@
"robot",
"webkit"
],
"os" : "macosx",
"os_beta" : ".1",
"os_major" : "10",
"os_minor" : ".11",
"os_string" : "Mac OS X",
"robot" : "researchscan",
"robot_name" : "Researchscan RWTH Aachen"
"robot_name" : "Researchscan RWTH Aachen",
"robot_string" : "Researchscan RWTH Aachen"
},
"Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_3) AppleWebKit/537.36 (KHTML, like Gecko) brave/0.7.9 Chrome/47.0.2526.73 Electron/0.36.2 Safari/537.36" : {
"browser" : "brave",
Expand Down Expand Up @@ -11484,7 +11517,7 @@
"os_string" : "Mac OS X",
"public_major" : "1",
"public_minor" : ".2",
"public_version" : 1.2,
"public_version" : "1.2",
"version" : 0.12
},
"Mozilla/5.0 (Macintosh; U; PPC Mac OS X; ru-ru) AppleWebKit/412 (KHTML, like Gecko) Safari/412" : {
Expand Down Expand Up @@ -16428,14 +16461,15 @@
"browser_major" : "5",
"browser_minor" : ".0",
"match" : [
"robot",
"ahrefs"
"ahrefs",
"robot"
],
"robot" : "ahrefs",
"robot_beta" : "",
"robot_major" : "5",
"robot_minor" : ".0",
"robot_name" : "Ahrefs",
"robot_string" : "Ahrefs",
"robot_version" : "5.0"
},
"Mozilla/5.0 (compatible; BLEXBot/1.0; +http://webmeup-crawler.com/)" : {
Expand Down Expand Up @@ -16698,14 +16732,15 @@
"browser_major" : "5",
"browser_minor" : ".0",
"match" : [
"robot",
"mj12bot"
"mj12bot",
"robot"
],
"robot" : "mj12bot",
"robot_beta" : ".5",
"robot_major" : "1",
"robot_minor" : ".4",
"robot_name" : "Majestic-12 DSearch",
"robot_string" : "Majestic-12 DSearch",
"robot_version" : "1.4"
},
"Mozilla/5.0 (compatible; MSIE 10.0; Windows NT 6.1; Trident/6.0; MDDRJS)" : {
Expand Down Expand Up @@ -17556,6 +17591,7 @@
"robot_major" : "3",
"robot_minor" : ".0",
"robot_name" : "Yandex",
"robot_string" : "Yandex",
"robot_version" : "3.0"
},
"Mozilla/5.0 (compatible; YandexImages/3.0; +http://yandex.com/bots)" : {
Expand All @@ -17570,6 +17606,7 @@
"robot_major" : "3",
"robot_minor" : ".0",
"robot_name" : "YandexImages",
"robot_string" : "YandexImages",
"robot_version" : "3.0"
},
"Mozilla/5.0 (compatible; archive.org_bot; Wayback Machine Live Record; +http://archive.org/details/archive.org_bot)" : {
Expand Down Expand Up @@ -19611,20 +19648,27 @@
"browser_minor" : ".1",
"device" : "wap",
"device_string" : "SAMSUNG-SGH-E250",
"major" : "2",
"match" : [
"device",
"wap",
"google",
"googlemobile",
"mobile",
"robot",
"googlemobile",
"google"
"wap"
],
"minor" : "0.1",
"public_major" : "2",
"public_minor" : ".1",
"public_version" : "2.1",
"robot" : "googlemobile",
"robot_beta" : "",
"robot_major" : "2",
"robot_minor" : ".1",
"robot_name" : "Googlebot Mobile",
"robot_version" : "2.1"
"robot_string" : "Googlebot Mobile",
"robot_version" : "2.1",
"version" : "2.1"
},
"SafeSearch microdata crawler (https://safesearch.avira.com, safesearch-abuse@avira.com)" : {
"major" : 0,
Expand Down Expand Up @@ -20002,14 +20046,15 @@
"browser_major" : "1",
"browser_minor" : ".1",
"match" : [
"robot",
"facebook"
"facebook",
"robot"
],
"robot" : "facebook",
"robot_beta" : "",
"robot_major" : "1",
"robot_minor" : ".1",
"robot_name" : "Facebook",
"robot_string" : "Facebook",
"robot_version" : "1.1"
},
"finbot" : {
Expand Down Expand Up @@ -20120,16 +20165,27 @@
"browser_beta" : "b",
"browser_major" : "2",
"browser_minor" : ".0",
"country" : null,
"language" : null,
"major" : "2",
"match" : [
"robot",
"msn"
"msn",
"robot"
],
"minor" : "0",
"no_match" : null,
"other" : null,
"public_major" : "2",
"public_minor" : "0",
"public_version" : "2.0",
"robot" : "msn",
"robot_beta" : "b",
"robot_major" : "2",
"robot_minor" : ".0",
"robot_name" : "MSN",
"robot_version" : "2.0"
"robot_string" : "MSN",
"robot_version" : "2.0",
"version" : "2.0"
},
"my sypder/Nutch-1.9" : {
"browser_major" : 0,
Expand Down

0 comments on commit 108c0fe

Please sign in to comment.