Geo-Google-MapObject
view release on metacpan or search on metacpan
t/googlemap.t view on Meta::CPAN
#!perl
use strict;
use warnings;
use Test::More tests => 17;
use Geo::Google::MapObject;
use Test::Differences;
use Test::JSON;
use HTML::Template::Pluggable;
use HTML::Template::Plugin::Dot;
our $template =<<EOS;
<html>
<head>
<title>Test</title>
<script src="<TMPL_VAR NAME="map.javascript_url">" type="text/javascript"></script>
</head>
<body>
<img alt="TEST" src="<TMPL_VAR NAME="map.static_map_url">" width="<TMPL_VAR NAME="map.width">" height="<TMPL_VAR NAME="map.height">"/>
<TMPL_IF NAME="map.markers">
<table>
<TMPL_LOOP NAME="map.markers">
<tr><td><TMPL_VAR NAME="this.location"></td></tr>
</TMPL_LOOP>
</table>
</TMPL_IF>
</body>
</html>
EOS
;
{
my $map = Geo::Google::MapObject->new ( key=>'api1', center=>'Berlin',zoom=>10,size=>"512x512");
ok($map, "map created");
ok($map->static_map_url eq "http://maps.google.com/maps/api/staticmap?center=Berlin&zoom=10&mobile=false&key=api1&sensor=false&size=512x512", "static_map_url");
ok($map->javascript_url eq "http://maps.google.com/maps?file=api&v=2&key=api1&sensor=false", "javascript_url");
is_json($map->json, '{"sensor":"false","zoom":"10","markers":[],"mobile":"false","center":"Berlin","size":{"width":"512","height":"512"}}', "json");
ok($map->width == 512, "width");
ok($map->height == 512, "height");
}
{
my $map = Geo::Google::MapObject->new ( key=>'api2', center=>'Berlin',zoom=>10, size=>"512x512");
my $t = HTML::Template::Pluggable->new(scalarref=>\$template, die_on_bad_params=>0);
$t->param(map=>$map);
my $output =<<EOS;
<html>
<head>
<title>Test</title>
<script src="http://maps.google.com/maps?file=api&v=2&key=api2&sensor=false" type="text/javascript"></script>
</head>
<body>
<img alt="TEST" src="http://maps.google.com/maps/api/staticmap?center=Berlin&zoom=10&mobile=false&key=api2&sensor=false&size=512x512" width="512" height="512"/>
</body>
</html>
EOS
;
eq_or_diff($t->output, $output, "zero markers");
}
{
my $map = Geo::Google::MapObject->new ( key=>'api3', center=>'Berlin',zoom=>10, markers=>[{location=>'Zoo'},{location=>'Garten'},{location=>'Polizei'}], size=>"512x512");
my $t = HTML::Template::Pluggable->new(scalarref=>\$template, die_on_bad_params=>0);
$t->param(map=>$map);
my $output =<<EOS;
( run in 0.919 second using v1.01-cache-2.11-cpan-39bf76dae61 )