package FixMyStreet::Map::Tester;
use base 'FixMyStreet::Map::FMS';
use constant ZOOM_LEVELS => 99;
use constant MIN_ZOOM_LEVEL => 88;
1;
package main;
use Test::MockModule;
use FixMyStreet::TestMech;
my $mech = FixMyStreet::TestMech->new;
subtest "check that if no query we get sent back to the homepage" => sub {
$mech->get_ok('/around');
is $mech->uri->path, '/', "redirected to '/'";
};
# test various locations on inital search box
foreach my $test (
{
pc => '', #
errors => [],
pc_alternatives => [],
},
{
pc => 'xxxxxxxxxxxxxxxxxxxxxxxxxxx',
errors => ['Sorry, we could not find that location.'],
pc_alternatives => [],
},
{
pc => 'Glenthorpe Ct, Katy, TX 77494, USA',
errors =>
['Sorry, we could not find that location.'],
pc_alternatives => [],
},
)
{
subtest "test bad pc value '$test->{pc}'" => sub {
$mech->get_ok('/');
FixMyStreet::override_config {
GEOCODER => '',
}, sub {
$mech->submit_form_ok( { with_fields => { pc => $test->{pc} } },
"bad location" );
};
is_deeply $mech->page_errors, $test->{errors},
"expected errors for pc '$test->{pc}'";
is_deeply $mech->pc_alternatives, $test->{pc_alternatives},
"expected alternatives for pc '$test->{pc}'";
};
}
# check that exact queries result in the correct lat,lng
foreach my $test (
{
pc => 'SW1A 1AA',
latitude => '51.501009',
longitude => '-0.141588',
},
{
pc => 'TQ 388 773',
latitude => '51.478074',
longitude => '-0.001966',
},
)
{
subtest "check lat/lng for '$test->{pc}'" => sub {
$mech->get_ok('/');
FixMyStreet::override_config {
ALLOWED_COBRANDS => [ { 'fixmystreet' => '.' } ],
MAPIT_URL => 'http://mapit.uk/',
}, sub {
$mech->submit_form_ok( { with_fields => { pc => $test->{pc} } },
"good location" );
};
is_deeply $mech->page_errors, [], "no errors for pc '$test->{pc}'";
is_deeply $mech->extract_location, $test,
"got expected location for pc '$test->{pc}'";
};
}
my $body_edin_id = $mech->create_body_ok(2651, 'City of Edinburgh Council')->id;
my $body_west_id = $mech->create_body_ok(2504, 'Westminster City Council')->id;
my @edinburgh_problems = $mech->create_problems_for_body( 5, $body_edin_id, 'Around page', {
postcode => 'EH1 1BB',
latitude => 55.9519637512,
longitude => -3.17492254484,
});
subtest 'check lookup by reference' => sub {
$mech->get_ok('/');
$mech->submit_form_ok( { with_fields => { pc => 'ref:12345' } }, 'bad ref');
$mech->content_contains('Searching found no reports');
my $id = $edinburgh_problems[0]->id;
$mech->submit_form_ok( { with_fields => { pc => "ref:$id" } }, 'good ref');
is $mech->uri->path, "/report/$id", "redirected to report page";
};
subtest 'check lookup by reference does not show non_public reports' => sub {
$edinburgh_problems[0]->update({
non_public => 1
});
my $id = $edinburgh_problems[0]->id;
$mech->get_ok('/');
$mech->submit_form_ok( { with_fields => { pc => "ref:$id" } }, 'non_public ref');
$mech->content_contains('Searching found no reports');
};
subtest 'check non public reports are not displayed on around page' => sub {
$mech->get_ok('/');
FixMyStreet::override_config {
ALLOWED_COBRANDS => [ { 'fixmystreet' => '.' } ],
MAPIT_URL => 'http://mapit.uk/',
}, sub {
$mech->submit_form_ok( { with_fields => { pc => 'EH1 1BB' } },
"good location" );
};
$mech->content_contains( "Around page Test 3 for $body_edin_id",
'problem to be marked non public visible' );
my $private = $edinburgh_problems[2];
ok $private->update( { non_public => 1 } ), 'problem marked non public';
$mech->get_ok('/');
FixMyStreet::override_config {
ALLOWED_COBRANDS => [ { 'fixmystreet' => '.' } ],
MAPIT_URL => 'http://mapit.uk/',
}, sub {
$mech->submit_form_ok( { with_fields => { pc => 'EH1 1BB' } },
"good location" );
};
$mech->content_lacks( "Around page Test 3 for $body_edin_id",
'problem marked non public is not visible' );
};
subtest 'check missing body message not shown when it does not need to be' => sub {
$mech->get_ok('/');
FixMyStreet::override_config {
ALLOWED_COBRANDS => 'fixmystreet',
MAPIT_URL => 'http://mapit.uk/',
}, sub {
$mech->submit_form_ok( { with_fields => { pc => 'EH1 1BB' } },
"good location" );
};
$mech->content_lacks('yet have details for the other councils that cover this location');
};
for my $permission ( qw/ report_inspect report_mark_private/ ) {
subtest 'check non public reports are displayed on around page with $permission permission' => sub {
my $body = FixMyStreet::DB->resultset('Body')->find( $body_edin_id );
my $body2 = FixMyStreet::DB->resultset('Body')->find( $body_west_id );
my $user = $mech->log_in_ok( 'test@example.com' );
$user->user_body_permissions->delete();
$user->update({ from_body => $body });
$user->user_body_permissions->find_or_create({
body => $body,
permission_type => $permission,
});
$mech->get_ok('/');
FixMyStreet::override_config {
ALLOWED_COBRANDS => [ { 'fixmystreet' => '.' } ],
MAPIT_URL => 'http://mapit.uk/',
}, sub {
$mech->submit_form_ok( { with_fields => { pc => 'EH1 1BB' } },
"good location" );
};
$mech->content_contains( "Around page Test 3 for $body_edin_id",
'problem marked non public is visible' );
$mech->content_contains( "Around page Test 2 for $body_edin_id",
'problem marked public is visible' );
FixMyStreet::override_config {
ALLOWED_COBRANDS => [ { 'fixmystreet' => '.' } ],
MAPIT_URL => 'http://mapit.uk/',
}, sub {
$mech->get_ok('/around?pc=EH1+1BB&status=non_public');
};
$mech->content_contains( "Around page Test 3 for $body_edin_id",
'problem marked non public is visible' );
$mech->content_lacks( "Around page Test 2 for $body_edin_id",
'problem marked public is not visible' );
$user->user_body_permissions->delete();
$user->update({ from_body => $body2 });
$user->user_body_permissions->find_or_create({
body => $body2,
permission_type => $permission,
});
$mech->get_ok('/');
FixMyStreet::override_config {
ALLOWED_COBRANDS => [ { 'fixmystreet' => '.' } ],
MAPIT_URL => 'http://mapit.uk/',
}, sub {
$mech->submit_form_ok( { with_fields => { pc => 'EH1 1BB' } },
"good location" );
};
$mech->content_lacks( "Around page Test 3 for $body_edin_id",
'problem marked non public is not visible' );
$mech->content_contains( "Around page Test 2 for $body_edin_id",
'problem marked public is visible' );
FixMyStreet::override_config {
ALLOWED_COBRANDS => [ { 'fixmystreet' => '.' } ],
MAPIT_URL => 'http://mapit.uk/',
}, sub {
$mech->get_ok('/around?pc=EH1+1BB&status=non_public');
};
$mech->content_lacks( "Around page Test 3 for $body_edin_id",
'problem marked non public is not visible' );
$mech->content_lacks( "Around page Test 2 for $body_edin_id",
'problem marked public is visible' );
};
}
my $body = $mech->create_body_ok(2237, "Oxfordshire");
subtest 'check category, status and extra filtering works on /around' => sub {
my $categories = [ 'Pothole', 'Vegetation', 'Flytipping' ];
my $params = {
postcode => 'OX20 1SZ',
latitude => 51.754926,
longitude => -1.256179,
};
my $bbox = ($params->{longitude} - 0.01) . ',' . ($params->{latitude} - 0.01)
. ',' . ($params->{longitude} + 0.01) . ',' . ($params->{latitude} + 0.01);
# Create one open and one fixed report in each category
foreach my $category ( @$categories ) {
my $contact = $mech->create_contact_ok( category => $category, body_id => $body->id, email => "$category\@example.org" );
if ($category ne 'Pothole') {
$contact->set_extra_metadata(group => ['Environment']);
$contact->update;
}
foreach my $state ( 'confirmed', 'fixed - user', 'fixed - council' ) {
my %report_params = (
%$params,
category => $category,
state => $state,
external_body => "$category-$state",
);
$mech->create_problems_for_body( 1, $body->id, 'Around page', \%report_params );
}
}
my $json = $mech->get_ok_json( '/around?ajax=1&bbox=' . $bbox );
my $pins = $json->{pins};
is scalar @$pins, 9, 'correct number of reports when no filters';
# Regression test for filter_category in /around URL
FixMyStreet::override_config {
ALLOWED_COBRANDS => 'fixmystreet',
MAPIT_URL => 'http://mapit.uk/',
COBRAND_FEATURES => { category_groups => { fixmystreet => 1 } },
}, sub {
$mech->get_ok( '/around?filter_category=Pothole&bbox=' . $bbox );
$mech->content_contains('