1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140
|
#!/usr/bin/perl -w
use Test::More 'no_plan';
BEGIN { use_ok 'Gravatar::URL';
use_ok 'Libravatar::URL'; }
my %interfaces = (
libravatar => {
func => \&libravatar_url,
base => 'http://cdn.libravatar.org/avatar',
https_base => 'https://seccdn.libravatar.org/avatar',
},
gravatar => {
func => \&gravatar_url,
base => 'http://www.gravatar.com/avatar',
https_base => 'https://secure.gravatar.com/avatar',
},
);
for my $interface_name (keys %interfaces) {
my $interface = $interfaces{$interface_name};
my $base = $interface->{base};
my $https_base = $interface->{https_base};
my $func = $interface->{func};
my $id = 'a60fc0828e808b9a6a9d50f1792240c8';
my $email = 'whatever@wherever.whichever';
my @tests = (
[{ email => $email },
"$base/$id",
],
[{ id => $id },
"$base/$id",
],
[{ email => $email,
https => 1
},
"$https_base/$id",
],
[{ email => $email,
https => 0
},
"$base/$id",
],
[{ email => $email,
base => 'http://example.com/gravatar'
},
"http://example.com/gravatar/$id",
],
[{ email => $email,
base => 'http://example.com/gravatar',
https => 1
},
"http://example.com/gravatar/$id",
],
# Make sure we don't get a double slash after the base.
[{ email => $email,
base => 'http://example.com/gravatar/'
},
"http://example.com/gravatar/$id",
],
[{ default => "/local.png",
email => $email
},
"$base/$id?d=%2Flocal.png",
],
[{ default => "/local.png",
rating => 'X',
email => $email,
},
"$base/$id?r=x&d=%2Flocal.png",
],
[{ default => "/local.png",
email => $email,
rating => 'R',
size => 80
},
"$base/$id?r=r&s=80&d=%2Flocal.png"
],
[{ default => "/local.png",
rating => 'PG',
size => 45,
email => $email,
},
"$base/$id?r=pg&s=45&d=%2Flocal.png"
],
[{ default => "/local.png",
rating => 'PG',
size => 45,
email => $email,
},
"$base/$id?r=pg&s=45&d=%2Flocal.png"
],
[{ default => "/local.png",
rating => 'PG',
size => 45,
email => $email,
short_keys => 1,
},
"$base/$id?r=pg&s=45&d=%2Flocal.png"
],
[{ default => "/local.png",
rating => 'PG',
size => 45,
email => $email,
short_keys => 0,
},
"$base/$id?rating=pg&size=45&default=%2Flocal.png"
],
);
# Add tests for the special defaults.
for my $special ("identicon", "mm", "monsterid", "retro", "wavatar") {
my $test = [{ default => $special,
email => $email,
},
"$base/$id?d=$special",
];
push @tests, $test;
}
for my $test (@tests) {
my($args, $url) = @$test;
is &$func( %$args ), $url, join ", ", keys %$args;
}
}
|