diff options
49 files changed, 783 insertions, 204 deletions
diff --git a/bin/update-schema b/bin/update-schema index 94c42d8ae..171b87576 100755 --- a/bin/update-schema +++ b/bin/update-schema @@ -194,6 +194,7 @@ else { # By querying the database schema, we can see where we're currently at # (assuming schema change files are never half-applied, which should be the case) sub get_db_version { + return '0050' if table_exists('defect_types'); return '0049' if column_exists('response_priorities', 'external_id'); return '0048' if column_exists('response_templates', 'state'); return '0047' if column_exists('response_priorities', 'description'); diff --git a/db/schema.sql b/db/schema.sql index 23db82b65..18c1533d9 100644 --- a/db/schema.sql +++ b/db/schema.sql @@ -502,3 +502,21 @@ CREATE TABLE contact_response_priorities ( contact_id int REFERENCES contacts(id) NOT NULL, response_priority_id int REFERENCES response_priorities(id) NOT NULL ); + +CREATE TABLE defect_types ( + id serial not null primary key, + body_id int references body(id) not null, + name text not null, + description text not null, + extra text, + unique(body_id, name) +); + +CREATE TABLE contact_defect_types ( + id serial NOT NULL PRIMARY KEY, + contact_id int REFERENCES contacts(id) NOT NULL, + defect_type_id int REFERENCES defect_types(id) NOT NULL +); + +ALTER TABLE problem + ADD COLUMN defect_type_id int REFERENCES defect_types(id); diff --git a/db/schema_0050-add-defect-type-table.sql b/db/schema_0050-add-defect-type-table.sql new file mode 100644 index 000000000..d65e17940 --- /dev/null +++ b/db/schema_0050-add-defect-type-table.sql @@ -0,0 +1,21 @@ +BEGIN; + +CREATE TABLE defect_types ( + id serial not null primary key, + body_id int references body(id) not null, + name text not null, + description text not null, + extra text, + unique(body_id, name) +); + +CREATE TABLE contact_defect_types ( + id serial NOT NULL PRIMARY KEY, + contact_id int REFERENCES contacts(id) NOT NULL, + defect_type_id int REFERENCES defect_types(id) NOT NULL +); + +ALTER TABLE problem + ADD COLUMN defect_type_id int REFERENCES defect_types(id); + +COMMIT; diff --git a/perllib/FixMyStreet/App/Controller/Admin/DefectTypes.pm b/perllib/FixMyStreet/App/Controller/Admin/DefectTypes.pm new file mode 100644 index 000000000..bcfeb3dd8 --- /dev/null +++ b/perllib/FixMyStreet/App/Controller/Admin/DefectTypes.pm @@ -0,0 +1,113 @@ +package FixMyStreet::App::Controller::Admin::DefectTypes; +use Moose; +use namespace::autoclean; +use mySociety::ArrayUtils; + +BEGIN { extends 'Catalyst::Controller'; } + + +sub begin : Private { + my ( $self, $c ) = @_; + + $c->forward('/admin/begin'); +} + +sub index : Path : Args(0) { + my ( $self, $c ) = @_; + + my $user = $c->user; + + if ($user->is_superuser) { + $c->forward('/admin/fetch_all_bodies'); + } elsif ( $user->from_body ) { + $c->forward('load_user_body', [ $user->from_body->id ]); + $c->res->redirect( $c->uri_for( '', $c->stash->{body}->id ) ); + } else { + $c->detach( '/page_error_404_not_found' ); + } +} + +sub list : Path : Args(1) { + my ($self, $c, $body_id) = @_; + + $c->forward('load_user_body', [ $body_id ]); + + my @defect_types = $c->stash->{body}->defect_types->search( + undef, + { + order_by => 'name' + } + ); + + $c->stash->{defect_types} = \@defect_types; +} + +sub edit : Path : Args(2) { + my ( $self, $c, $body_id, $defect_type_id ) = @_; + + $c->forward('load_user_body', [ $body_id ]); + + my $defect_type; + if ($defect_type_id eq 'new') { + $defect_type = $c->stash->{body}->defect_types->new({}); + } + else { + $defect_type = $c->stash->{body}->defect_types->find( $defect_type_id ) + or $c->detach( '/page_error_404_not_found' ); + } + + $c->forward('/admin/fetch_contacts'); + my @contacts = $defect_type->contacts->all; + my @live_contacts = $c->stash->{live_contacts}->all; + my %active_contacts = map { $_->id => 1 } @contacts; + my @all_contacts = map { { + id => $_->id, + category => $_->category, + active => $active_contacts{$_->id}, + } } @live_contacts; + $c->stash->{contacts} = \@all_contacts; + + if ($c->req->method eq 'POST') { + $defect_type->name( $c->get_param('name') ); + $defect_type->description( $c->get_param('description') ); + + my @extra_fields = @{ $c->cobrand->call_hook('defect_type_extra_fields') || [] }; + foreach ( @extra_fields ) { + $defect_type->set_extra_metadata( $_ => $c->get_param("extra[$_]") ); + } + + $defect_type->update_or_insert; + my @live_contact_ids = map { $_->id } @live_contacts; + my @new_contact_ids = $c->get_param_list('categories'); + @new_contact_ids = @{ mySociety::ArrayUtils::intersection(\@live_contact_ids, \@new_contact_ids) }; + $defect_type->contact_defect_types->search({ + contact_id => { '!=' => \@new_contact_ids }, + })->delete; + foreach my $contact_id (@new_contact_ids) { + $defect_type->contact_defect_types->find_or_create({ + contact_id => $contact_id, + }); + } + + $c->res->redirect( $c->uri_for( '', $c->stash->{body}->id ) ); + } + + $c->stash->{defect_type} = $defect_type; +} + +sub load_user_body : Private { + my ($self, $c, $body_id) = @_; + + my $has_permission = $c->user->has_body_permission_to('defect_type_edit', $body_id); + + unless ( $has_permission ) { + $c->detach( '/page_error_404_not_found' ); + } + + $c->stash->{body} = $c->model('DB::Body')->find($body_id) + or $c->detach( '/page_error_404_not_found' ); +} + +__PACKAGE__->meta->make_immutable; + +1; diff --git a/perllib/FixMyStreet/App/Controller/Admin/ExorDefects.pm b/perllib/FixMyStreet/App/Controller/Admin/ExorDefects.pm index 013d710af..201742c81 100644 --- a/perllib/FixMyStreet/App/Controller/Admin/ExorDefects.pm +++ b/perllib/FixMyStreet/App/Controller/Admin/ExorDefects.pm @@ -141,22 +141,32 @@ sub download : Path('download') : Args(0) { foreach my $report (@$inspections) { my ($eastings, $northings) = $report->local_coords; my $description = sprintf("%s %s", $report->external_id || "", $report->get_extra_metadata('detailed_information') || ""); + my $activity_code = $report->defect_type ? + $report->defect_type->get_extra_metadata('activity_code') + : 'MC'; + my $traffic_information = $report->get_extra_metadata('traffic_information') ? + 'TM ' . $report->get_extra_metadata('traffic_information') + : 'TM none'; + $csv->combine( "I", # beginning of defect record - "MC", # activity code - minor carriageway, also FC (footway) + $activity_code, # activity code - minor carriageway, also FC (footway) "", # empty field, can also be A (seen on MC) or B (seen on FC) sprintf("%03d", ++$i), # randomised sequence number "${eastings}E ${northings}N", # defect location field, which we don't capture from inspectors $report->inspection_log_entry->whenedited->strftime("%H%M"), # defect time raised "","","","","","","", # empty fields - $report->get_extra_metadata('traffic_information') ? 'TM required' : 'TM none', # further description + $traffic_information, $description, # defect description ); push @body, $csv->string; + my $defect_type = $report->defect_type ? + $report->defect_type->get_extra_metadata('defect_code') + : 'SFP2'; $csv->combine( "J", # georeferencing record - $report->get_extra_metadata('defect_type') || 'SFP2', # defect type - SFP2: sweep and fill <1m2, POT2 also seen + $defect_type, # defect type - SFP2: sweep and fill <1m2, POT2 also seen $report->response_priority ? $report->response_priority->external_id : "2", # priority of defect diff --git a/perllib/FixMyStreet/App/Controller/Auth.pm b/perllib/FixMyStreet/App/Controller/Auth.pm index 70821f79d..4efa7abb8 100644 --- a/perllib/FixMyStreet/App/Controller/Auth.pm +++ b/perllib/FixMyStreet/App/Controller/Auth.pm @@ -104,7 +104,7 @@ sub sign_in : Private { Email the user the details they need to sign in. Don't check for an account - if there isn't one we can create it when they come back with a token (which -contains the email addresss). +contains the email address). =cut diff --git a/perllib/FixMyStreet/App/Controller/Report.pm b/perllib/FixMyStreet/App/Controller/Report.pm index 1c2e98bd4..fe7576893 100644 --- a/perllib/FixMyStreet/App/Controller/Report.pm +++ b/perllib/FixMyStreet/App/Controller/Report.pm @@ -340,10 +340,16 @@ sub inspect : Private { my %update_params = (); if ($permissions->{report_inspect}) { - foreach (qw/detailed_information traffic_information duplicate_of defect_type/) { + foreach (qw/detailed_information traffic_information duplicate_of/) { $problem->set_extra_metadata( $_ => $c->get_param($_) ); } + if ( $c->get_param('defect_type') ) { + $problem->defect_type($problem->defect_types->find($c->get_param('defect_type'))); + } else { + $problem->defect_type(undef); + } + if ( $c->get_param('include_update') ) { $update_text = Utils::cleanup_text( $c->get_param('public_update'), { allow_multiline => 1 } ); if (!$update_text) { diff --git a/perllib/FixMyStreet/Cobrand/Oxfordshire.pm b/perllib/FixMyStreet/Cobrand/Oxfordshire.pm index d585a5328..78247e39d 100644 --- a/perllib/FixMyStreet/Cobrand/Oxfordshire.pm +++ b/perllib/FixMyStreet/Cobrand/Oxfordshire.pm @@ -161,9 +161,13 @@ sub admin_pages { # Oxfordshire have a custom admin page for downloading reports in an Exor- # friendly format which anyone with report_instruct permission can use. - if ( $user->is_superuser || $user->has_body_permission_to('report_instruct') ) { + if ( $user->has_body_permission_to('report_instruct') ) { $pages->{exordefects} = [ _('Download Exor RDI'), 10 ]; } + if ( $user->has_body_permission_to('defect_type_edit') ) { + $pages->{defecttypes} = [ _('Defect Types'), 11 ]; + $pages->{defecttype_edit} = [ undef, undef ]; + }; return $pages; } @@ -190,4 +194,20 @@ sub user_extra_fields { sub display_days_ago_threshold { 28 } +sub defect_type_extra_fields { + return [ + 'activity_code', + 'defect_code', + ]; +}; + +sub available_permissions { + my $self = shift; + + my $perms = $self->next::method(); + $perms->{Bodies}->{defect_type_edit} = "Add/edit defect types"; + + return $perms; +} + 1; diff --git a/perllib/FixMyStreet/DB/Result/Body.pm b/perllib/FixMyStreet/DB/Result/Body.pm index 6dac8821c..82015ad2d 100644 --- a/perllib/FixMyStreet/DB/Result/Body.pm +++ b/perllib/FixMyStreet/DB/Result/Body.pm @@ -75,6 +75,12 @@ __PACKAGE__->has_many( { "foreign.body_id" => "self.id" }, { cascade_copy => 0, cascade_delete => 0 }, ); +__PACKAGE__->has_many( + "defect_types", + "FixMyStreet::DB::Result::DefectType", + { "foreign.body_id" => "self.id" }, + { cascade_copy => 0, cascade_delete => 0 }, +); __PACKAGE__->belongs_to( "parent", "FixMyStreet::DB::Result::Body", @@ -112,8 +118,8 @@ __PACKAGE__->has_many( ); -# Created by DBIx::Class::Schema::Loader v0.07035 @ 2016-09-06 15:33:04 -# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:ZuzscnLqcx0k512cTZ/kdg +# Created by DBIx::Class::Schema::Loader v0.07035 @ 2017-02-13 15:11:11 +# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:BOJANVwg3kR/1VjDq0LykA sub url { my ( $self, $c, $args ) = @_; diff --git a/perllib/FixMyStreet/DB/Result/Contact.pm b/perllib/FixMyStreet/DB/Result/Contact.pm index f7e8ac5b5..a620b7358 100644 --- a/perllib/FixMyStreet/DB/Result/Contact.pm +++ b/perllib/FixMyStreet/DB/Result/Contact.pm @@ -56,6 +56,12 @@ __PACKAGE__->belongs_to( { is_deferrable => 0, on_delete => "NO ACTION", on_update => "NO ACTION" }, ); __PACKAGE__->has_many( + "contact_defect_types", + "FixMyStreet::DB::Result::ContactDefectType", + { "foreign.contact_id" => "self.id" }, + { cascade_copy => 0, cascade_delete => 0 }, +); +__PACKAGE__->has_many( "contact_response_priorities", "FixMyStreet::DB::Result::ContactResponsePriority", { "foreign.contact_id" => "self.id" }, @@ -69,8 +75,8 @@ __PACKAGE__->has_many( ); -# Created by DBIx::Class::Schema::Loader v0.07035 @ 2016-09-06 15:33:04 -# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:ocmQGeFJtO3wmvyx6W+EKQ +# Created by DBIx::Class::Schema::Loader v0.07035 @ 2017-02-13 15:11:11 +# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:f9VepR/oPyr3z6PUpJ4w2A __PACKAGE__->load_components("+FixMyStreet::DB::RABXColumn"); __PACKAGE__->rabx_column('extra'); @@ -82,6 +88,7 @@ with 'FixMyStreet::Roles::Extra'; __PACKAGE__->many_to_many( response_templates => 'contact_response_templates', 'response_template' ); __PACKAGE__->many_to_many( response_priorities => 'contact_response_priorities', 'response_priority' ); +__PACKAGE__->many_to_many( defect_types => 'contact_defect_types', 'defect_type' ); sub get_metadata_for_input { my $self = shift; diff --git a/perllib/FixMyStreet/DB/Result/ContactDefectType.pm b/perllib/FixMyStreet/DB/Result/ContactDefectType.pm new file mode 100644 index 000000000..2199f0b42 --- /dev/null +++ b/perllib/FixMyStreet/DB/Result/ContactDefectType.pm @@ -0,0 +1,46 @@ +use utf8; +package FixMyStreet::DB::Result::ContactDefectType; + +# Created by DBIx::Class::Schema::Loader +# DO NOT MODIFY THE FIRST PART OF THIS FILE + +use strict; +use warnings; + +use base 'DBIx::Class::Core'; +__PACKAGE__->load_components("FilterColumn", "InflateColumn::DateTime", "EncodedColumn"); +__PACKAGE__->table("contact_defect_types"); +__PACKAGE__->add_columns( + "id", + { + data_type => "integer", + is_auto_increment => 1, + is_nullable => 0, + sequence => "contact_defect_types_id_seq", + }, + "contact_id", + { data_type => "integer", is_foreign_key => 1, is_nullable => 0 }, + "defect_type_id", + { data_type => "integer", is_foreign_key => 1, is_nullable => 0 }, +); +__PACKAGE__->set_primary_key("id"); +__PACKAGE__->belongs_to( + "contact", + "FixMyStreet::DB::Result::Contact", + { id => "contact_id" }, + { is_deferrable => 0, on_delete => "NO ACTION", on_update => "NO ACTION" }, +); +__PACKAGE__->belongs_to( + "defect_type", + "FixMyStreet::DB::Result::DefectType", + { id => "defect_type_id" }, + { is_deferrable => 0, on_delete => "NO ACTION", on_update => "NO ACTION" }, +); + + +# Created by DBIx::Class::Schema::Loader v0.07035 @ 2017-02-13 15:11:11 +# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:VIczmM0OXXpWgQVpop3SMw + + +# You can replace this text with custom code or comments, and it will be preserved on regeneration +1; diff --git a/perllib/FixMyStreet/DB/Result/DefectType.pm b/perllib/FixMyStreet/DB/Result/DefectType.pm new file mode 100644 index 000000000..a2969f59e --- /dev/null +++ b/perllib/FixMyStreet/DB/Result/DefectType.pm @@ -0,0 +1,66 @@ +use utf8; +package FixMyStreet::DB::Result::DefectType; + +# Created by DBIx::Class::Schema::Loader +# DO NOT MODIFY THE FIRST PART OF THIS FILE + +use strict; +use warnings; + +use base 'DBIx::Class::Core'; +__PACKAGE__->load_components("FilterColumn", "InflateColumn::DateTime", "EncodedColumn"); +__PACKAGE__->table("defect_types"); +__PACKAGE__->add_columns( + "id", + { + data_type => "integer", + is_auto_increment => 1, + is_nullable => 0, + sequence => "defect_types_id_seq", + }, + "body_id", + { data_type => "integer", is_foreign_key => 1, is_nullable => 0 }, + "name", + { data_type => "text", is_nullable => 0 }, + "description", + { data_type => "text", is_nullable => 0 }, + "extra", + { data_type => "text", is_nullable => 1 }, +); +__PACKAGE__->set_primary_key("id"); +__PACKAGE__->add_unique_constraint("defect_types_body_id_name_key", ["body_id", "name"]); +__PACKAGE__->belongs_to( + "body", + "FixMyStreet::DB::Result::Body", + { id => "body_id" }, + { is_deferrable => 0, on_delete => "NO ACTION", on_update => "NO ACTION" }, +); +__PACKAGE__->has_many( + "contact_defect_types", + "FixMyStreet::DB::Result::ContactDefectType", + { "foreign.defect_type_id" => "self.id" }, + { cascade_copy => 0, cascade_delete => 0 }, +); +__PACKAGE__->has_many( + "problems", + "FixMyStreet::DB::Result::Problem", + { "foreign.defect_type_id" => "self.id" }, + { cascade_copy => 0, cascade_delete => 0 }, +); + + +# Created by DBIx::Class::Schema::Loader v0.07035 @ 2017-02-13 15:11:11 +# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:BBLjb/aAoTKJZerdYCeBMQ + +__PACKAGE__->many_to_many( contacts => 'contact_defect_types', 'contact' ); + +__PACKAGE__->load_components("+FixMyStreet::DB::RABXColumn"); +__PACKAGE__->rabx_column('extra'); + +use Moo; +use namespace::clean -except => [ 'meta' ]; + +with 'FixMyStreet::Roles::Extra'; + + +1; diff --git a/perllib/FixMyStreet/DB/Result/Problem.pm b/perllib/FixMyStreet/DB/Result/Problem.pm index 0ab52628e..84db41490 100644 --- a/perllib/FixMyStreet/DB/Result/Problem.pm +++ b/perllib/FixMyStreet/DB/Result/Problem.pm @@ -108,6 +108,8 @@ __PACKAGE__->add_columns( { data_type => "text", is_nullable => 1 }, "response_priority_id", { data_type => "integer", is_foreign_key => 1, is_nullable => 1 }, + "defect_type_id", + { data_type => "integer", is_foreign_key => 1, is_nullable => 1 }, ); __PACKAGE__->set_primary_key("id"); __PACKAGE__->has_many( @@ -116,6 +118,17 @@ __PACKAGE__->has_many( { "foreign.problem_id" => "self.id" }, { cascade_copy => 0, cascade_delete => 0 }, ); +__PACKAGE__->belongs_to( + "defect_type", + "FixMyStreet::DB::Result::DefectType", + { id => "defect_type_id" }, + { + is_deferrable => 0, + join_type => "LEFT", + on_delete => "NO ACTION", + on_update => "NO ACTION", + }, +); __PACKAGE__->has_many( "moderation_original_datas", "FixMyStreet::DB::Result::ModerationOriginalData", @@ -153,8 +166,8 @@ __PACKAGE__->has_many( ); -# Created by DBIx::Class::Schema::Loader v0.07035 @ 2016-09-07 11:01:40 -# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:iH9c4VZZN/ONnhN6g89DFw +# Created by DBIx::Class::Schema::Loader v0.07035 @ 2017-02-13 15:11:11 +# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:8zzWlJX7OQOdvrGxKuZUmg # Add fake relationship to stored procedure table __PACKAGE__->has_one( @@ -754,6 +767,18 @@ sub response_priorities { return $self->result_source->schema->resultset('ResponsePriority')->for_bodies($self->bodies_str_ids, $self->category); } +=head2 defect_types + +Returns all DefectTypes attached to this problem's category/contact, in +alphabetical order of name. + +=cut + +sub defect_types { + my $self = shift; + return $self->result_source->schema->resultset('DefectType')->for_bodies($self->bodies_str_ids, $self->category); +} + # returns true if the external id is the council's ref, i.e., useful to publish it # (by way of an example, the Oxfordshire send method returns a useful reference when # it succeeds, so that is the ref we should show on the problem report page). diff --git a/perllib/FixMyStreet/DB/ResultSet/DefectType.pm b/perllib/FixMyStreet/DB/ResultSet/DefectType.pm new file mode 100644 index 000000000..a873ef252 --- /dev/null +++ b/perllib/FixMyStreet/DB/ResultSet/DefectType.pm @@ -0,0 +1,22 @@ +package FixMyStreet::DB::ResultSet::DefectType; +use base 'DBIx::Class::ResultSet'; + +use strict; +use warnings; + +sub for_bodies { + my ($rs, $bodies, $category) = @_; + my $attrs = { + 'me.body_id' => $bodies, + }; + if ($category) { + $attrs->{'contact.category'} = [ $category, undef ]; + } + $rs->search($attrs, { + order_by => 'name', + join => { 'contact_defect_types' => 'contact' }, + distinct => 1, + }); +} + +1; diff --git a/perllib/FixMyStreet/TestMech.pm b/perllib/FixMyStreet/TestMech.pm index c22789fb0..166ba116f 100644 --- a/perllib/FixMyStreet/TestMech.pm +++ b/perllib/FixMyStreet/TestMech.pm @@ -10,6 +10,7 @@ BEGIN { } use Test::WWW::Mechanize::Catalyst 'FixMyStreet::App'; +use t::Mock::MapIt; use Test::More; use Web::Scraper; use Carp; @@ -611,6 +612,7 @@ sub delete_body { my $body = shift; $mech->delete_problems_for_body($body->id); + $mech->delete_defect_type($_) for $body->defect_types; $mech->delete_contact($_) for $body->contacts; $mech->delete_user($_) for $body->users; $_->delete for $body->response_templates; @@ -642,6 +644,14 @@ sub delete_problems_for_body { } } +sub delete_defect_type { + my $mech = shift; + my $defect_type = shift; + + $defect_type->contact_defect_types->delete_all; + $defect_type->delete; +} + sub create_contact_ok { my $self = shift; my %contact_params = ( diff --git a/t/Mock/MapIt.pm b/t/Mock/MapIt.pm index 9aa8b7e40..43d44d519 100644 --- a/t/Mock/MapIt.pm +++ b/t/Mock/MapIt.pm @@ -2,6 +2,7 @@ package t::Mock::MapIt; use JSON::MaybeXS; use Web::Simple; +use LWP::Protocol::PSGI; use mySociety::Locale; @@ -12,42 +13,83 @@ has json => ( }, ); +sub output { + my ($self, $response) = @_; + # We must make sure we output correctly for testing purposes, we might + # be within a different locale here... + my $json = mySociety::Locale::in_gb_locale { + $self->json->encode($response) }; + return [ 200, [ 'Content-Type' => 'application/json' ], [ $json ] ]; +} + +my @PLACES = ( + [ 'EH1 1BB', 55.952055, -3.189579, 2651, 'Edinburgh City Council', 'UTA', 20728, 'City Centre', 'UTE' ], + [ 'SW1A 1AA', 51.501009, -0.141588, 2504, 'Westminster City Council', 'LBO' ], + [ 'GL50 2PR', 51.896268, -2.093063, 2226, 'Gloucestershire County Council', 'CTY', 2326, 'Cheltenham Borough Council', 'DIS', 4544, 'Lansdown', 'DIW', 143641, 'Lansdown and Park', 'CED' ], + [ '?', 51.754926, -1.256179, 2237, 'Oxfordshire County Council', 'CTY', 2421, 'Oxford City Council', 'DIS' ], + [ 'BR1 3UH', 51.4021, 0.01578, 2482, 'Bromley Council', 'LBO' ], + [ '?', 50.78301, -0.646929 ], + [ 'GU51 4AE', 51.279456, -0.846216, 2333, 'Hart District Council', 'DIS', 2227, 'Hampshire County Council', 'CTY' ], + [ 'WS1 4NH', 52.563074, -1.991032, 2535, 'Sandwell Borough Council', 'MTD' ], +); + sub dispatch_request { my $self = shift; sub (GET + /postcode/*) { my ($self, $postcode) = @_; - my $response = $self->postcode($postcode); - # We must make sure we output correctly for testing purposes, we might - # be within a different locale here... - my $json = mySociety::Locale::in_gb_locale { - $self->json->encode($response) }; - return [ 200, [ 'Content-Type' => 'application/json' ], [ $json ] ]; + foreach (@PLACES) { + if ($postcode eq $_->[0] || $postcode eq $_->[0] =~ s/ //gr) { + return $self->output({wgs84_lat => $_->[1], wgs84_lon => $_->[2], postcode => $postcode, coordsyst => 'G'}); + } + } + my $response = { + wgs84_lat => 51.5, wgs84_lon => -2.1, postcode => $postcode, coordsyst => 'G', + }; + return $self->output($response); }, - sub (GET + /point/**) { + sub (GET + /point/**.*) { my ($self, $point) = @_; + foreach (@PLACES) { + if ($point eq "4326/$_->[2],$_->[1]") { + my %out; + for (my $i=3; $i<@$_; $i+=3) { + $out{"$_->[$i]"} = { id => $_->[$i], name => $_->[$i+1], type => $_->[$i+2] }; + } + return $self->output(\%out); + } + } my $response = { "63999" => {"parent_area" => 2245, "generation_high" => 25, "all_names" => {}, "id" => 63999, "codes" => {"ons" => "00HYNS", "gss" => "E05008366", "unit_id" => "44025"}, "name" => "Kington", "country" => "E", "type_name" => "Unitary Authority electoral division (UTE)", "generation_low" => 12, "country_name" => "England", "type" => "UTE"}, - "65822" => {"parent_area" => undef, "generation_high" => 25, "all_names" => {}, "id" => 65822, "codes" => {"gss" => "E14000860", "unit_id" => "24903"}, "name" => "North Wiltshire", "country" => "E", "type_name" => "UK Parliament constituency", "generation_low" => 13, "country_name" => "England", "type" => "WMC"}, - "11814" => {"parent_area" => undef, "generation_high" => 25, "all_names" => {}, "id" => 11814, "codes" => {"ons" => "09", "gss" => "E15000009", "unit_id" => "41427"}, "name" => "South West", "country" => "E", "type_name" => "European region", "generation_low" => 1, "country_name" => "England", "type" => "EUR"}, "2245" => {"parent_area" => undef, "generation_high" => 25, "all_names" => {}, "id" => 2245, "codes" => {"ons" => "00HY", "gss" => "E06000054", "unit_id" => "43925"}, "name" => "Wiltshire Council", "country" => "E", "type_name" => "Unitary Authority", "generation_low" => 11, "country_name" => "England", "type" => "UTA"} }; - # We must make sure we output correctly for testing purposes, we might - # be within a different locale here... - my $json = mySociety::Locale::in_gb_locale { - $self->json->encode($response) }; - return [ 200, [ 'Content-Type' => 'application/json' ], [ $json ] ]; + return $self->output($response); + }, + + sub (GET + /areas/*) { + my ($self, $areas) = @_; + if ($areas eq 'Hart') { + $self->output({2333 => {parent_area => undef, id => 2333, name => "Hart District Council", type => "DIS"}}); + } elsif ($areas eq 'Birmingham') { + $self->output({2514 => {parent_area => undef, id => 2514, name => "Birmingham City Council", type => "MTD"}}); + } elsif ($areas eq 'Gloucestershire') { + $self->output({2226 => {parent_area => undef, id => 2226, name => "Gloucestershire County Council", type => "CTY"}}); + } elsif ($areas eq 'Cheltenham') { + $self->output({2326 => {parent_area => undef, id => 2326, name => "Cheltenham Borough Council", type => "DIS"}}); + } elsif ($areas eq 'Lansdown and Park') { + $self->output({22261 => {parent_area => 2226, id => 22261, name => "Lansdown and Park", type => "CED"}}); + } elsif ($areas eq 'Lansdown') { + $self->output({23261 => {parent_area => 2326, id => 23261, name => "Lansdown", type => "DIW"}}); + } elsif ($areas eq 'UTA') { + $self->output({2650 => {parent_area => undef, id => 2650, name => "Aberdeen Council", type => "UTA"}}); + } }, sub (GET + /area/*) { my ($self, $area) = @_; - my $response = {"parent_area" => undef, "generation_high" => 25, "all_names" => {}, "id" => 2245, "codes" => {"ons" => "00HY", "gss" => "E06000054", "unit_id" => "43925"}, "name" => "Wiltshire Council", "country" => "E", "type_name" => "Unitary Authority", "generation_low" => 11, "country_name" => "England", "type" => "UTA"}; - # We must make sure we output correctly for testing purposes, we might - # be within a different locale here... - my $json = mySociety::Locale::in_gb_locale { - $self->json->encode($response) }; - return [ 200, [ 'Content-Type' => 'application/json' ], [ $json ] ]; + my $response = { "id" => $area, "name" => "Area $area", "type" => "UTA" }; + return $self->output($response); }, sub (GET + /area/*/children) { @@ -56,19 +98,15 @@ sub dispatch_request { "60705" => { "parent_area" => 2245, "generation_high" => 25, "all_names" => { }, "id" => 60705, "codes" => { "ons" => "00HY226", "gss" => "E04011842", "unit_id" => "17101" }, "name" => "Trowbridge", "country" => "E", "type_name" => "Civil parish/community", "generation_low" => 12, "country_name" => "England", "type" => "CPC" }, "62883" => { "parent_area" => 2245, "generation_high" => 25, "all_names" => { }, "id" => 62883, "codes" => { "ons" => "00HY026", "gss" => "E04011642", "unit_id" => "17205" }, "name" => "Bradford-on-Avon", "country" => "E", "type_name" => "Civil parish/community", "generation_low" => 12, "country_name" => "England", "type" => "CPC" }, }; - # We must make sure we output correctly for testing purposes, we might - # be within a different locale here... - my $json = mySociety::Locale::in_gb_locale { - $self->json->encode($response) }; - return [ 200, [ 'Content-Type' => 'application/json' ], [ $json ] ]; + return $self->output($response); }, -} -sub postcode { - my ($self, $postcode) = @_; - return { - wgs84_lat => 51.5, wgs84_lon => -2.1, postcode => $postcode, coordsyst => 'G', - }; + sub (GET + /area/*/example_postcode) { + my ($self, $area) = @_; + return [ 200, [ 'Content-Type' => 'application/json' ], [ '"AB12 1AA"' ] ]; + }, } +LWP::Protocol::PSGI->register(t::Mock::MapIt->to_psgi_app, host => 'mapit.uk'); + __PACKAGE__->run_if_script; diff --git a/t/app/controller/admin.t b/t/app/controller/admin.t index ab6cac842..2fdd8b74a 100644 --- a/t/app/controller/admin.t +++ b/t/app/controller/admin.t @@ -1,9 +1,7 @@ use strict; use warnings; use Test::More; -use LWP::Protocol::PSGI; -use t::Mock::MapIt; use FixMyStreet::TestMech; my $mech = FixMyStreet::TestMech->new; @@ -148,7 +146,7 @@ subtest 'check summary counts' => sub { # This override is wrapped around ALL the /admin/body tests FixMyStreet::override_config { - MAPIT_URL => 'http://mapit.mysociety.org/', + MAPIT_URL => 'http://mapit.uk/', MAPIT_TYPES => [ 'UTA' ], BASE_URL => 'http://www.example.org', }, sub { @@ -580,7 +578,6 @@ foreach my $test ( } FixMyStreet::override_config { - MAPIT_URL => 'http://mapit.mysociety.org/', ALLOWED_COBRANDS => 'fixmystreet', }, sub { @@ -1204,7 +1201,6 @@ my %default_perms = ( FixMyStreet::override_config { MAPIT_URL => 'http://mapit.uk/', }, sub { - LWP::Protocol::PSGI->register(t::Mock::MapIt->run_if_script, host => 'mapit.uk'); for my $test ( { desc => 'edit user name', diff --git a/t/app/controller/admin_permissions.t b/t/app/controller/admin_permissions.t index 4b05660cc..dd256173d 100644 --- a/t/app/controller/admin_permissions.t +++ b/t/app/controller/admin_permissions.t @@ -1,9 +1,7 @@ use strict; use warnings; use Test::More; -use LWP::Protocol::PSGI; -use t::Mock::MapIt; use FixMyStreet::TestMech; my $mech = FixMyStreet::TestMech->new; @@ -84,8 +82,6 @@ FixMyStreet::override_config { MAPIT_URL => 'http://mapit.uk/', ALLOWED_COBRANDS => [ 'oxfordshire' ], }, sub { - LWP::Protocol::PSGI->register(t::Mock::MapIt->run_if_script, host => 'mapit.uk'); - my $user2_id = $user2->id; $report->update({ bodies_str => $oxfordshire->id }); diff --git a/t/app/controller/alert.t b/t/app/controller/alert.t index c42eba6b8..cb5949b8f 100644 --- a/t/app/controller/alert.t +++ b/t/app/controller/alert.t @@ -17,7 +17,7 @@ $mech->content_contains('html class="no-js" lang="en-gb"'); # check that we can get list page FixMyStreet::override_config { ALLOWED_COBRANDS => [ { 'fixmystreet' => '.' } ], - MAPIT_URL => 'http://mapit.mysociety.org/', + MAPIT_URL => 'http://mapit.uk/', GEOCODER => '', }, sub { $mech->get_ok('/alert/list'); @@ -25,21 +25,21 @@ FixMyStreet::override_config { $mech->content_contains('Local RSS feeds and email alerts'); $mech->content_contains('html class="no-js" lang="en-gb"'); - $mech->get_ok('/alert/list?pc=EH99 1SP'); + $mech->get_ok('/alert/list?pc=EH1 1BB'); $mech->title_like(qr/^Local RSS feeds and email alerts/); - $mech->content_contains('Here are the types of local problem alerts for ‘EH99 1SP’'); + $mech->content_contains('Here are the types of local problem alerts for ‘EH1 1BB’'); $mech->content_contains('html class="no-js" lang="en-gb"'); $mech->content_contains('Problems within 10.0km'); - $mech->content_contains('rss/pc/EH991SP/2'); - $mech->content_contains('rss/pc/EH991SP/5'); - $mech->content_contains('rss/pc/EH991SP/10'); - $mech->content_contains('rss/pc/EH991SP/20'); - $mech->content_contains('Problems within City of Edinburgh'); + $mech->content_contains('rss/pc/EH11BB/2'); + $mech->content_contains('rss/pc/EH11BB/5'); + $mech->content_contains('rss/pc/EH11BB/10'); + $mech->content_contains('rss/pc/EH11BB/20'); + $mech->content_contains('Problems within Edinburgh City'); $mech->content_contains('Problems within City Centre ward'); - $mech->content_contains('/rss/reports/City+of+Edinburgh'); - $mech->content_contains('/rss/reports/City+of+Edinburgh/City+Centre'); - $mech->content_contains('council:2651:City_of_Edinburgh'); - $mech->content_contains('ward:2651:20728:City_of_Edinburgh:City_Centre'); + $mech->content_contains('/rss/reports/Edinburgh'); + $mech->content_contains('/rss/reports/Edinburgh/City+Centre'); + $mech->content_contains('council:2651:Edinburgh'); + $mech->content_contains('ward:2651:20728:Edinburgh:City_Centre'); subtest "Test Nominatim lookup" => sub { LWP::Protocol::PSGI->register(t::Mock::Nominatim->run_if_script, host => 'nominatim.openstreetmap.org'); diff --git a/t/app/controller/alert_new.t b/t/app/controller/alert_new.t index 1b85adf7e..ea38f7c25 100644 --- a/t/app/controller/alert_new.t +++ b/t/app/controller/alert_new.t @@ -208,7 +208,7 @@ foreach my $test ( FixMyStreet::override_config { ALLOWED_COBRANDS => [ { 'fixmystreet' => '.' } ], - MAPIT_URL => 'http://mapit.mysociety.org/', + MAPIT_URL => 'http://mapit.uk/', }, sub { $mech->get_ok('/alert/list?pc=EH991SP'); }; @@ -312,7 +312,7 @@ subtest "Test two-tier council alerts" => sub { ) { FixMyStreet::override_config { ALLOWED_COBRANDS => [ { 'fixmystreet' => '.' } ], - MAPIT_URL => 'http://mapit.mysociety.org/', + MAPIT_URL => 'http://mapit.uk/', }, sub { $mech->get_ok( '/alert/list?pc=GL502PR' ); $mech->submit_form_ok( { @@ -351,7 +351,7 @@ subtest "Test normal alert signups and that alerts are sent" => sub { $mech->get_ok( '/alert' ); FixMyStreet::override_config { ALLOWED_COBRANDS => [ { 'fixmystreet' => '.' } ], - MAPIT_URL => 'http://mapit.mysociety.org/', + MAPIT_URL => 'http://mapit.uk/', }, sub { $mech->submit_form_ok( { with_fields => { pc => 'EH11BB' } } ); $mech->submit_form_ok( { @@ -371,7 +371,7 @@ subtest "Test normal alert signups and that alerts are sent" => sub { } } - my $dt = DateTime->now()->add( days => 2); + my $dt = DateTime->now(time_zone => 'Europe/London')->add(days => 2); my $dt_parser = FixMyStreet::App->model('DB')->schema->storage->datetime_parser; @@ -436,7 +436,7 @@ subtest "Test normal alert signups and that alerts are sent" => sub { ok $update, "created test update - $update_id"; FixMyStreet::override_config { - MAPIT_URL => 'http://mapit.mysociety.org/', + MAPIT_URL => 'http://mapit.uk/', }, sub { FixMyStreet::App->model('DB::AlertType')->email_alerts(); }; @@ -447,7 +447,7 @@ subtest "Test normal alert signups and that alerts are sent" => sub { for (@emails) { my $body = $mech->get_text_body_from_email($_); $count++ if $body =~ /The following updates have been left on this report:/; - $count++ if $body =~ /The following new FixMyStreet reports have been added in the City of\s+Edinburgh\s+Council area:/; + $count++ if $body =~ /The following new FixMyStreet reports have been added in the Area 2651 area:/; $count++ if $body =~ /The following FixMyStreet reports have been made within the area you\s+specified:/; $count++ if $body =~ /\s+-\s+Testing/; } @@ -486,7 +486,7 @@ subtest "Test signature template is used from cobrand" => sub { my $user2 = $mech->create_user_ok('alerts@example.com', name => 'Alert User' ); - my $dt = DateTime->now()->add( days => 2); + my $dt = DateTime->now(time_zone => 'Europe/London')->add(days => 2); my $dt_parser = FixMyStreet::App->model('DB')->schema->storage->datetime_parser; @@ -542,7 +542,7 @@ subtest "Test signature template is used from cobrand" => sub { $mech->clear_emails_ok; FixMyStreet::override_config { - MAPIT_URL => 'http://mapit.mysociety.org/', + MAPIT_URL => 'http://mapit.uk/', ALLOWED_COBRANDS => [ { 'fixmystreet' => '.' } ], }, sub { FixMyStreet::App->model('DB::AlertType')->email_alerts(); @@ -570,7 +570,7 @@ subtest "Test signature template is used from cobrand" => sub { $mech->clear_emails_ok; FixMyStreet::override_config { - MAPIT_URL => 'http://mapit.mysociety.org/', + MAPIT_URL => 'http://mapit.uk/', ALLOWED_COBRANDS => [ { 'fixmystreet' => '.' } ], }, sub { FixMyStreet::App->model('DB::AlertType')->email_alerts(); @@ -665,7 +665,7 @@ for my $test ( $mech->clear_emails_ok; FixMyStreet::override_config { - MAPIT_URL => 'http://mapit.mysociety.org/', + MAPIT_URL => 'http://mapit.uk/', }, sub { FixMyStreet::App->model('DB::AlertType')->email_alerts(); }; @@ -673,7 +673,7 @@ for my $test ( $report->update( { non_public => 0 } ); FixMyStreet::override_config { - MAPIT_URL => 'http://mapit.mysociety.org/', + MAPIT_URL => 'http://mapit.uk/', }, sub { FixMyStreet::App->model('DB::AlertType')->email_alerts(); }; diff --git a/t/app/controller/around.t b/t/app/controller/around.t index 9e2e7c524..c8aca04aa 100644 --- a/t/app/controller/around.t +++ b/t/app/controller/around.t @@ -1,9 +1,7 @@ use strict; use warnings; use Test::More; -use LWP::Protocol::PSGI; -use t::Mock::MapIt; use FixMyStreet::TestMech; my $mech = FixMyStreet::TestMech->new; @@ -17,7 +15,7 @@ subtest "check that if no query we get sent back to the homepage" => sub { subtest "redirect x,y requests to lat/lon (301 - permanent)" => sub { FixMyStreet::override_config { - MAPIT_URL => 'http://mapit.mysociety.org/', + MAPIT_URL => 'http://mapit.uk/', }, sub { $mech->get_ok('/around?x=3281&y=1113'); }; @@ -73,8 +71,8 @@ foreach my $test ( foreach my $test ( { pc => 'SW1A 1AA', - latitude => '51.5', - longitude => '-2.1', + latitude => '51.501009', + longitude => '-0.141588', }, { pc => 'TQ 388 773', @@ -84,8 +82,6 @@ foreach my $test ( ) { subtest "check lat/lng for '$test->{pc}'" => sub { - LWP::Protocol::PSGI->register(t::Mock::MapIt->run_if_script, host => 'mapit.uk'); - $mech->get_ok('/'); FixMyStreet::override_config { ALLOWED_COBRANDS => [ { 'fixmystreet' => '.' } ], @@ -102,7 +98,7 @@ foreach my $test ( subtest 'check non public reports are not displayed on around page' => sub { my $params = { - postcode => 'EH99 1SP', + postcode => 'EH1 1BB', latitude => 55.9519637512, longitude => -3.17492254484, }; @@ -112,9 +108,9 @@ 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.mysociety.org/', + MAPIT_URL => 'http://mapit.uk/', }, sub { - $mech->submit_form_ok( { with_fields => { pc => 'EH99 1SP' } }, + $mech->submit_form_ok( { with_fields => { pc => 'EH1 1BB' } }, "good location" ); }; $mech->content_contains( 'Around page Test 3 for 2651', @@ -126,9 +122,9 @@ 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.mysociety.org/', + MAPIT_URL => 'http://mapit.uk/', }, sub { - $mech->submit_form_ok( { with_fields => { pc => 'EH99 1SP' } }, + $mech->submit_form_ok( { with_fields => { pc => 'EH1 1BB' } }, "good location" ); }; $mech->content_lacks( 'Around page Test 3 for 2651', diff --git a/t/app/controller/auth.t b/t/app/controller/auth.t index 22ade6f4b..3a11cfc4a 100644 --- a/t/app/controller/auth.t +++ b/t/app/controller/auth.t @@ -56,6 +56,10 @@ for my $test ( is_deeply $mech->page_errors, [ $error_message ], 'errors match'; } +# Email address parsing should pass from here +my $resolver = Test::MockModule->new('Email::Valid'); +$resolver->mock('address', sub { $_[1] }); + # create a new account $mech->clear_emails_ok; $mech->get_ok('/auth'); diff --git a/t/app/controller/auth_social.t b/t/app/controller/auth_social.t index f3eae32a7..09fdf22d3 100644 --- a/t/app/controller/auth_social.t +++ b/t/app/controller/auth_social.t @@ -1,13 +1,13 @@ use strict; use warnings; use Test::More; +use Test::MockModule; use LWP::Protocol::PSGI; use LWP::Simple; use JSON::MaybeXS; use t::Mock::Facebook; use t::Mock::Twitter; -use t::Mock::MapIt; use FixMyStreet::TestMech; my $mech = FixMyStreet::TestMech->new; @@ -18,8 +18,6 @@ END { FixMyStreet::App->log->enable('info'); } my ($report) = $mech->create_problems_for_body(1, '2345', 'Test'); -LWP::Protocol::PSGI->register(t::Mock::MapIt->to_psgi_app, host => 'mapit.uk'); - FixMyStreet::override_config { FACEBOOK_APP_ID => 'facebook-app-id', TWITTER_KEY => 'twitter-key', @@ -30,6 +28,9 @@ FixMyStreet::override_config { my $fb_email = 'facebook@example.org'; my $fb_uid = 123456789; +my $resolver = Test::MockModule->new('Email::Valid'); +$resolver->mock('address', sub { 'facebook@example.org' }); + for my $fb_state ( 'refused', 'no email', 'existing UID', 'okay' ) { for my $page ( 'my', 'report', 'update' ) { subtest "test FB '$fb_state' login for page '$page'" => sub { @@ -138,6 +139,8 @@ for my $fb_state ( 'refused', 'no email', 'existing UID', 'okay' ) { } } +$resolver->mock('address', sub { 'twitter@example.org' }); + my $tw_email = 'twitter@example.org'; my $tw_uid = 987654321; diff --git a/t/app/controller/dashboard.t b/t/app/controller/dashboard.t index 5ea5cb9f5..903affdcf 100644 --- a/t/app/controller/dashboard.t +++ b/t/app/controller/dashboard.t @@ -25,7 +25,7 @@ my $p_user = $mech->create_user_ok('p_user@example.com'); set_absolute_time('2014-03-01T12:00:00'); FixMyStreet::override_config { ALLOWED_COBRANDS => [ { fixmystreet => '.' } ], - MAPIT_URL => 'http://mapit.mysociety.org/', + MAPIT_URL => 'http://mapit.uk/', }, sub { $mech->not_logged_in_ok; @@ -48,7 +48,7 @@ FixMyStreet::override_config { with_fields => { email => $test_user, password_sign_in => $test_pass } } ); - $mech->content_contains( 'City of Edinburgh' ); + $mech->content_contains( 'Area 2651' ); FixMyStreet::App->model('DB::Contact')->search( { body_id => $body->id } ) ->delete; diff --git a/t/app/controller/index.t b/t/app/controller/index.t index 6752d4d7e..6b28a03d2 100644 --- a/t/app/controller/index.t +++ b/t/app/controller/index.t @@ -12,12 +12,7 @@ subtest "check that the form goes to /around" => sub { $mech->get_ok('/'); is $mech->uri->path, '/', "still on '/'"; - # submit form - FixMyStreet::override_config { - MAPIT_URL => 'http://mapit.mysociety.org/', - }, sub { - $mech->submit_form_ok( { with_fields => { pc => 'SW1A 1AA', } } ); - }; + $mech->submit_form_ok( { with_fields => { pc => 'SW1A 1AA', } } ); # check that we are at /around is $mech->uri->path, '/around', "Got to /around"; @@ -52,7 +47,7 @@ subtest "does pc, (x,y), (e,n) or (lat,lon) go to /around" => sub { # get the uri and check for 302 FixMyStreet::override_config { - MAPIT_URL => 'http://mapit.mysociety.org/', + MAPIT_URL => 'http://mapit.uk/', }, sub { $mech->get_ok($uri); }; diff --git a/t/app/controller/photo.t b/t/app/controller/photo.t index 69c2ae866..ad857b5e3 100644 --- a/t/app/controller/photo.t +++ b/t/app/controller/photo.t @@ -30,7 +30,7 @@ subtest "Check multiple upload worked" => sub { # submit initial pc form FixMyStreet::override_config { ALLOWED_COBRANDS => [ { fixmystreet => '.' } ], - MAPIT_URL => 'http://mapit.mysociety.org/', + MAPIT_URL => 'http://mapit.uk/', UPLOAD_DIR => $UPLOAD_DIR, }, sub { diff --git a/t/app/controller/report_as_other.t b/t/app/controller/report_as_other.t index b4405be57..551a59481 100644 --- a/t/app/controller/report_as_other.t +++ b/t/app/controller/report_as_other.t @@ -1,9 +1,7 @@ use strict; use warnings; use Test::More; -use LWP::Protocol::PSGI; -use t::Mock::MapIt; use FixMyStreet::TestMech; use FixMyStreet::App; @@ -13,7 +11,7 @@ END { FixMyStreet::App->log->enable('info'); } my $mech = FixMyStreet::TestMech->new; -my $body = $mech->create_body_ok(2245, 'Wiltshire Council'); +my $body = $mech->create_body_ok(2237, 'Oxfordshire County Council'); my $contact1 = $mech->create_contact_ok( body_id => $body->id, category => 'Street lighting', email => 'highways@example.com' ); my $contact2 = $mech->create_contact_ok( body_id => $body->id, category => 'Potholes', email => 'potholes@example.com' ); @@ -38,7 +36,7 @@ subtest "Body user, has permission to add report as council" => sub { detail => 'Test report details.', category => 'Street lighting', ); - is $report->name, 'Wiltshire Council', 'report name is body'; + is $report->name, 'Oxfordshire County Council', 'report name is body'; is $report->user->name, 'Body User', 'user name unchanged'; is $report->user->id, $user->id, 'user matches'; is $report->anonymous, 0, 'report not anonymous'; @@ -59,7 +57,7 @@ subtest "Body user, has permission to add report as another user" => sub { is $report->user->name, 'Another User', 'user name matches'; is $report->user->email, 'another@example.net', 'user email correct'; isnt $report->user->id, $user->id, 'user does not match'; - like $mech->get_text_body_from_email, qr/Your report to Wiltshire Council has been logged/; + like $mech->get_text_body_from_email, qr/Your report to Oxfordshire County Council has been logged/; push @users, $report->user; }; @@ -78,7 +76,7 @@ subtest "Body user, has permission to add report as another (existing) user" => is $report->user->name, 'Existing User', 'user name remains same'; is $report->user->email, 'existing@example.net', 'user email correct'; isnt $report->user->id, $user->id, 'user does not match'; - like $mech->get_text_body_from_email, qr/Your report to Wiltshire Council has been logged/; + like $mech->get_text_body_from_email, qr/Your report to Oxfordshire County Council has been logged/; push @users, $report->user; }; @@ -88,7 +86,7 @@ subtest "Body user, has permission to add update as council" => sub { form_as => 'body', update => 'Test Update', ); - is $update->name, 'Wiltshire Council', 'update name is body'; + is $update->name, 'Oxfordshire County Council', 'update name is body'; is $update->user->name, 'Body User', 'user name unchanged'; is $update->user->id, $user->id, 'user matches'; is $update->anonymous, 0, 'update not anonymous'; @@ -134,7 +132,6 @@ END { sub start_report { my $permission = shift; - LWP::Protocol::PSGI->register(t::Mock::MapIt->run_if_script, host => 'mapit.uk'); $_->delete for $user->user_body_permissions; $user->user_body_permissions->create({ body => $body, permission_type => $permission }) if $permission; diff --git a/t/app/controller/report_import.t b/t/app/controller/report_import.t index 6c0da221c..b956b61ae 100644 --- a/t/app/controller/report_import.t +++ b/t/app/controller/report_import.t @@ -1,13 +1,15 @@ use strict; use warnings; use Test::More; -use LWP::Protocol::PSGI; -use t::Mock::MapIt; use FixMyStreet::TestMech; use FixMyStreet::App; use Web::Scraper; use Path::Class; +use LWP::Protocol::PSGI; +use t::Mock::MapItZurich; + +LWP::Protocol::PSGI->register(t::Mock::MapItZurich->to_psgi_app, host => 'mapit.zurich'); my $mech = FixMyStreet::TestMech->new; $mech->get_ok('/import'); @@ -92,8 +94,6 @@ subtest "Test creating bad partial entries" => sub { }; subtest "Submit a correct entry" => sub { - LWP::Protocol::PSGI->register(t::Mock::MapIt->run_if_script, host => 'mapit.uk'); - $mech->get_ok('/import'); $mech->submit_form_ok( # @@ -259,7 +259,7 @@ subtest "Submit a correct entry (with location)" => sub { # go to the token url FixMyStreet::override_config { ALLOWED_COBRANDS => [ { 'fixmystreet' => '.' } ], - MAPIT_URL => 'http://mapit.mysociety.org/', + MAPIT_URL => 'http://mapit.uk/', }, sub { $mech->get_ok($token_url); }; @@ -285,7 +285,7 @@ subtest "Submit a correct entry (with location)" => sub { # change the details FixMyStreet::override_config { ALLOWED_COBRANDS => [ { 'fixmystreet' => '.' } ], - MAPIT_URL => 'http://mapit.mysociety.org/', + MAPIT_URL => 'http://mapit.uk/', }, sub { $mech->submit_form_ok( # { @@ -318,7 +318,7 @@ subtest "Submit a correct entry (with location)" => sub { subtest "Submit a correct entry (with location) to cobrand" => sub { FixMyStreet::override_config { ALLOWED_COBRANDS => [ 'zurich' ], - MAPIT_URL => 'http://global.mapit.mysociety.org/', + MAPIT_URL => 'http://mapit.zurich/', MAPIT_TYPES => [ 'O08' ], MAPIT_ID_WHITELIST => [], MAP_TYPE => 'Zurich,OSM', diff --git a/t/app/controller/report_inspect.t b/t/app/controller/report_inspect.t index cc98f2b64..69e43ad99 100644 --- a/t/app/controller/report_inspect.t +++ b/t/app/controller/report_inspect.t @@ -34,7 +34,7 @@ my $user = $mech->log_in_ok('test@example.com'); $user->update( { from_body => $oxon } ); FixMyStreet::override_config { - MAPIT_URL => 'http://mapit.mysociety.org/', + MAPIT_URL => 'http://mapit.uk/', ALLOWED_COBRANDS => 'fixmystreet', }, sub { subtest "test inspect page" => sub { @@ -177,7 +177,6 @@ FixMyStreet::override_config { }; FixMyStreet::override_config { - MAPIT_URL => 'http://mapit.mysociety.org/', ALLOWED_COBRANDS => 'oxfordshire', }, sub { subtest "test negative reputation" => sub { @@ -215,7 +214,6 @@ FixMyStreet::override_config { }; FixMyStreet::override_config { - MAPIT_URL => 'http://mapit.mysociety.org/', ALLOWED_COBRANDS => [ 'oxfordshire', 'fixmystreet' ], BASE_URL => 'http://fixmystreet.site', }, sub { diff --git a/t/app/controller/report_new.t b/t/app/controller/report_new.t index c4dd30e47..fd3108438 100644 --- a/t/app/controller/report_new.t +++ b/t/app/controller/report_new.t @@ -25,7 +25,7 @@ subtest "test that bare requests to /report/new get redirected" => sub { is_deeply { $mech->uri->query_form }, {}, "query empty"; FixMyStreet::override_config { - MAPIT_URL => 'http://mapit.mysociety.org/', + MAPIT_URL => 'http://mapit.uk/', }, sub { $mech->get_ok('/report/new?pc=SW1A%201AA'); }; @@ -476,7 +476,7 @@ foreach my $test ( # submit initial pc form FixMyStreet::override_config { ALLOWED_COBRANDS => [ { fixmystreet => '.' } ], - MAPIT_URL => 'http://mapit.mysociety.org/', + MAPIT_URL => 'http://mapit.uk/', }, sub { $mech->submit_form_ok( { with_fields => { pc => $test->{pc} } }, "submit location" ); @@ -549,7 +549,7 @@ foreach my $test ( $mech->get_ok('/around'); FixMyStreet::override_config { ALLOWED_COBRANDS => [ { fixmystreet => '.' } ], - MAPIT_URL => 'http://mapit.mysociety.org/', + MAPIT_URL => 'http://mapit.uk/', }, sub { $mech->submit_form_ok( { with_fields => { pc => 'EH1 1BB', } }, "submit location" ); @@ -665,7 +665,7 @@ subtest "test password errors for a user who is signing in as they report" => su $mech->get_ok('/around'); FixMyStreet::override_config { ALLOWED_COBRANDS => [ { fixmystreet => '.' } ], - MAPIT_URL => 'http://mapit.mysociety.org/', + MAPIT_URL => 'http://mapit.uk/', }, sub { $mech->submit_form_ok( { with_fields => { pc => 'EH1 1BB', } }, "submit location" ); @@ -717,7 +717,7 @@ subtest "test report creation for a user who is signing in as they report" => su $mech->get_ok('/around'); FixMyStreet::override_config { ALLOWED_COBRANDS => [ { fixmystreet => '.' } ], - MAPIT_URL => 'http://mapit.mysociety.org/', + MAPIT_URL => 'http://mapit.uk/', }, sub { $mech->submit_form_ok( { with_fields => { pc => 'EH1 1BB', } }, "submit location" ); @@ -813,7 +813,7 @@ foreach my $test ( $mech->get_ok('/around'); FixMyStreet::override_config { ALLOWED_COBRANDS => [ { fixmystreet => '.' } ], - MAPIT_URL => 'http://mapit.mysociety.org/', + MAPIT_URL => 'http://mapit.uk/', }, sub { $mech->submit_form_ok( { with_fields => { pc => 'GL50 2PR', } }, "submit location" ); @@ -912,7 +912,7 @@ subtest "test report creation for a category that is non public" => sub { $mech->get_ok('/around'); FixMyStreet::override_config { ALLOWED_COBRANDS => [ { fixmystreet => '.' } ], - MAPIT_URL => 'http://mapit.mysociety.org/', + MAPIT_URL => 'http://mapit.uk/', }, sub { $mech->submit_form_ok( { with_fields => { pc => 'EH1 1BB', } }, "submit location" ); @@ -974,7 +974,7 @@ $contact2->update; my $extra_details; FixMyStreet::override_config { ALLOWED_COBRANDS => [ { fixmystreet => '.' } ], - MAPIT_URL => 'http://mapit.mysociety.org/', + MAPIT_URL => 'http://mapit.uk/', }, sub { $extra_details = $mech->get_ok_json( '/report/new/ajax?latitude=' . $saved_lat . '&longitude=' . $saved_lon ); }; @@ -983,7 +983,7 @@ ok !$extra_details->{titles_list}, 'Non Bromley does not send back list of title FixMyStreet::override_config { ALLOWED_COBRANDS => [ { fixmystreet => '.' } ], - MAPIT_URL => 'http://mapit.mysociety.org/', + MAPIT_URL => 'http://mapit.uk/', }, sub { $extra_details = $mech->get_ok_json( '/report/new/ajax?latitude=51.4021&longitude=0.01578'); }; @@ -1003,7 +1003,7 @@ subtest "check that a lat/lon off coast leads to /around" => sub { my $off_coast_longitude = -0.646929; FixMyStreet::override_config { - MAPIT_URL => 'http://mapit.mysociety.org/', + MAPIT_URL => 'http://mapit.uk/', }, sub { $mech->get_ok( # "/report/new" @@ -1025,7 +1025,7 @@ for my $test ( { desc => 'user title not set if not bromley problem', host => 'www.fixmystreet.com', - postcode => 'EH99 1SP', + postcode => 'EH1 1BB', fms_extra_title => '', extra => [], user_title => undef, @@ -1076,7 +1076,7 @@ for my $test ( subtest $test->{desc} => sub { my $override = { ALLOWED_COBRANDS => [ $test->{host} =~ /bromley/ ? 'bromley' : 'fixmystreet' ], - MAPIT_URL => 'http://mapit.mysociety.org/', + MAPIT_URL => 'http://mapit.uk/', }; $mech->host( $test->{host} ); @@ -1193,9 +1193,9 @@ subtest 'user title not reset if no user title in submission' => sub { $mech->get_ok('/'); FixMyStreet::override_config { ALLOWED_COBRANDS => [ { fixmystreet => '.' } ], - MAPIT_URL => 'http://mapit.mysociety.org/', + MAPIT_URL => 'http://mapit.uk/', }, sub { - $mech->submit_form_ok( { with_fields => { pc => 'EH99 1SP', } }, + $mech->submit_form_ok( { with_fields => { pc => 'EH1 1BB', } }, "submit location" ); $mech->follow_link_ok( { text_regex => qr/skip this step/i, }, @@ -1258,7 +1258,7 @@ subtest "test Hart" => sub { FixMyStreet::override_config { ALLOWED_COBRANDS => [ 'hart', 'fixmystreet' ], BASE_URL => 'http://www.fixmystreet.com', - MAPIT_URL => 'http://mapit.mysociety.org/', + MAPIT_URL => 'http://mapit.uk/', }, sub { $mech->get_ok('/around'); $mech->content_contains( "Hart Council" ); @@ -1434,7 +1434,7 @@ subtest "test SeeSomething" => sub { $mech->get_ok( '/around' ); FixMyStreet::override_config { ALLOWED_COBRANDS => [ 'seesomething' ], - MAPIT_URL => 'http://mapit.mysociety.org/', + MAPIT_URL => 'http://mapit.uk/', }, sub { $mech->submit_form_ok( { @@ -1481,15 +1481,15 @@ subtest "test SeeSomething" => sub { subtest "categories from deleted bodies shouldn't be visible for new reports" => sub { FixMyStreet::override_config { ALLOWED_COBRANDS => [ { fixmystreet => '.' } ], - MAPIT_URL => 'http://mapit.mysociety.org/', + MAPIT_URL => 'http://mapit.uk/', }, sub { - $mech->get_ok('/report/new/ajax?latitude=51.89&longitude=-2.09'); # Cheltenham + $mech->get_ok('/report/new/ajax?latitude=51.896268&longitude=-2.093063'); # Cheltenham ok $mech->content_contains( $contact3->category ); # Delete the body which the contact belongs to. $contact3->body->update( { deleted => 1 } ); - $mech->get_ok('/report/new/ajax?latitude=51.89&longitude=-2.09'); # Cheltenham + $mech->get_ok('/report/new/ajax?latitude=51.896268&longitude=-2.093063'); # Cheltenham ok $mech->content_lacks( $contact3->category ); $contact3->body->update( { deleted => 0 } ); @@ -1499,12 +1499,12 @@ subtest "categories from deleted bodies shouldn't be visible for new reports" => subtest "unresponsive body handling works" => sub { FixMyStreet::override_config { ALLOWED_COBRANDS => [ { fixmystreet => '.' } ], - MAPIT_URL => 'http://mapit.mysociety.org/', + MAPIT_URL => 'http://mapit.uk/', }, sub { # Test body-level send method my $old_send = $contact1->body->send_method; $contact1->body->update( { send_method => 'Refused' } ); - $mech->get_ok('/report/new/ajax?latitude=55.9&longitude=-3.2'); # Edinburgh + $mech->get_ok('/report/new/ajax?latitude=55.952055&longitude=-3.189579'); # Edinburgh my $body_id = $contact1->body->id; ok $mech->content_like( qr{Edinburgh.*accept reports.*/unresponsive\?body=$body_id} ); @@ -1553,8 +1553,8 @@ subtest "unresponsive body handling works" => sub { phone => '07903 123 456', category => 'Trees', service => 'iOS', - lat => 55.9, - lon => -3.2, + lat => 55.952055, + lon => -3.189579, pc => '', used_map => '1', submit_register => '1', @@ -1580,7 +1580,7 @@ subtest "unresponsive body handling works" => sub { # And test per-category refusing my $old_email = $contact3->email; $contact3->update( { email => 'REFUSED' } ); - $mech->get_ok('/report/new/category_extras?category=Trees&latitude=51.89&longitude=-2.09'); + $mech->get_ok('/report/new/category_extras?category=Trees&latitude=51.896268&longitude=-2.093063'); ok $mech->content_like( qr/Cheltenham.*Trees.*unresponsive.*category=Trees/ ); $mech->get_ok('/around'); @@ -1614,7 +1614,6 @@ subtest "unresponsive body handling works" => sub { subtest "unresponsive body page works" => sub { FixMyStreet::override_config { ALLOWED_COBRANDS => [ { fixmystreet => '.' } ], - MAPIT_URL => 'http://mapit.mysociety.org/', }, sub { my $old_send = $contact1->body->send_method; my $body_id = $contact1->body->id; @@ -1641,7 +1640,7 @@ subtest "extra google analytics code displayed on logged in problem creation" => FixMyStreet::override_config { ALLOWED_COBRANDS => [ { fixmystreet => '.' } ], BASE_URL => 'https://www.fixmystreet.com', - MAPIT_URL => 'http://mapit.mysociety.org/', + MAPIT_URL => 'http://mapit.uk/', }, sub { # check that the user does not exist my $test_email = 'test-2@example.com'; @@ -1670,7 +1669,7 @@ subtest "extra google analytics code displayed on logged in problem creation" => $mech->submit_form_ok( { with_fields => { - title => "Test Report at café", + title => "Test Report at café", detail => 'Test report details.', photo1 => '', name => 'Joe Bloggs', @@ -1697,7 +1696,7 @@ subtest "extra google analytics code displayed on email confirmation problem cre FixMyStreet::override_config { ALLOWED_COBRANDS => [ { fixmystreet => '.' } ], BASE_URL => 'https://www.fixmystreet.com', - MAPIT_URL => 'http://mapit.mysociety.org/', + MAPIT_URL => 'http://mapit.uk/', }, sub { $mech->log_out_ok; $mech->clear_emails_ok; diff --git a/t/app/controller/report_new_mobile.t b/t/app/controller/report_new_mobile.t index 61cb14a1b..3dfb99b2f 100644 --- a/t/app/controller/report_new_mobile.t +++ b/t/app/controller/report_new_mobile.t @@ -1,5 +1,7 @@ use Test::More; use FixMyStreet::TestMech; +use LWP::Protocol::PSGI; +use t::Mock::MapItZurich; my $mech = FixMyStreet::TestMech->new; @@ -7,10 +9,12 @@ my $mech = FixMyStreet::TestMech->new; FixMyStreet::App->log->disable('info'); END { FixMyStreet::App->log->enable('info'); } +LWP::Protocol::PSGI->register(t::Mock::MapItZurich->to_psgi_app, host => 'mapit.zurich'); + subtest "Check signed up for alert when logged in" => sub { FixMyStreet::override_config { - MAPIT_URL => 'http://global.mapit.mysociety.org', - MAPIT_TYPES => [ 'O06' ], + MAPIT_URL => 'http://mapit.zurich', + MAPIT_TYPES => [ 'O08' ], }, sub { $mech->log_in_ok('user@example.org'); $mech->post_ok( '/report/new/mobile', { diff --git a/t/app/controller/report_new_open311.t b/t/app/controller/report_new_open311.t index a5b742783..e3a464f88 100644 --- a/t/app/controller/report_new_open311.t +++ b/t/app/controller/report_new_open311.t @@ -12,7 +12,7 @@ END { FixMyStreet::App->log->enable('info'); } my $mech = FixMyStreet::TestMech->new; -my $body = $mech->create_body_ok(2651, 'City of Edinburgh Council'); +my $body = $mech->create_body_ok(2245, 'Wiltshire Council'); $body->update({ endpoint => 'http://example.com/open311', jurisdiction => 'mySociety', @@ -27,7 +27,7 @@ my $contact1 = $mech->create_contact_ok( extra => [ { description => 'Lamppost number', code => 'number', required => 'True' }, { description => 'Lamppost type', code => 'type', required => 'False', values => { value => [ { name => ['Gas'], key => ['old'] }, { name => [ 'Yellow' ], key => [ 'modern' ] } ] } - } + } ], ); my $contact1b = $mech->create_contact_ok( @@ -117,7 +117,7 @@ foreach my $test ( # submit initial pc form FixMyStreet::override_config { ALLOWED_COBRANDS => [ { 'fixmystreet' => '.' } ], - MAPIT_URL => 'http://mapit.mysociety.org/', + MAPIT_URL => 'http://mapit.uk/', }, sub { $mech->submit_form_ok( { with_fields => { pc => $test->{pc} } }, "submit location" ); @@ -158,7 +158,7 @@ foreach my $test ( }; FixMyStreet::override_config { ALLOWED_COBRANDS => [ { 'fixmystreet' => '.' } ], - MAPIT_URL => 'http://mapit.mysociety.org/', + MAPIT_URL => 'http://mapit.uk/', }, sub { $mech->submit_form_ok( { with_fields => $new_values } ); }; diff --git a/t/app/controller/reports.t b/t/app/controller/reports.t index 8fa03897b..a21d3ad65 100644 --- a/t/app/controller/reports.t +++ b/t/app/controller/reports.t @@ -107,7 +107,7 @@ is $stats->{'Fife Council'}->[4], 3, 'correct number of fixed reports for Fife'; is $stats->{'Fife Council'}->[5], 1, 'correct number of older fixed reports for Fife'; FixMyStreet::override_config { - MAPIT_URL => 'http://mapit.mysociety.org/', + MAPIT_URL => 'http://mapit.uk/', }, sub { $mech->follow_link_ok( { text_regex => qr/Birmingham/ } ); $mech->get_ok('/reports/Westminster'); @@ -121,7 +121,7 @@ my $problems = $mech->extract_problem_list; is scalar @$problems, 5, 'correct number of problems displayed'; FixMyStreet::override_config { - MAPIT_URL => 'http://mapit.mysociety.org/', + MAPIT_URL => 'http://mapit.uk/', }, sub { $mech->get_ok('/reports'); $mech->follow_link_ok({ url_regex => qr{/reports/Electricity_Gas\+Council} }); @@ -133,7 +133,7 @@ $problems = $mech->extract_problem_list; is scalar @$problems, 2, 'correct number of new problems displayed'; FixMyStreet::override_config { - MAPIT_URL => 'http://mapit.mysociety.org/', + MAPIT_URL => 'http://mapit.uk/', }, sub { $mech->get_ok('/reports/City+of+Edinburgh?t=older'); }; @@ -169,7 +169,7 @@ for my $test ( ) { subtest $test->{desc} => sub { FixMyStreet::override_config { - MAPIT_URL => 'http://mapit.mysociety.org/', + MAPIT_URL => 'http://mapit.uk/', }, sub { $mech->get_ok('/reports/Fife+Council?t=' . $test->{type}); }; @@ -183,7 +183,7 @@ my $private = $westminster_problems[2]; ok $private->update( { non_public => 1 } ), 'problem marked non public'; FixMyStreet::override_config { - MAPIT_URL => 'http://mapit.mysociety.org/', + MAPIT_URL => 'http://mapit.uk/', }, sub { $mech->get_ok('/reports/Westminster'); }; @@ -213,7 +213,7 @@ subtest "test fiksgatami all reports page" => sub { subtest "test greenwich all reports page" => sub { FixMyStreet::override_config { ALLOWED_COBRANDS => [ 'greenwich' ], - MAPIT_URL => 'http://mapit.mysociety.org/' + MAPIT_URL => 'http://mapit.uk/' }, sub { my $body = $mech->create_body_ok(2493, 'Royal Borough of Greenwich'); my $deleted_contact = $mech->create_contact_ok( @@ -235,7 +235,7 @@ subtest "test greenwich all reports page" => sub { subtest "it lists shortlisted reports" => sub { FixMyStreet::override_config { - MAPIT_URL => 'http://mapit.mysociety.org/' + MAPIT_URL => 'http://mapit.uk/' }, sub { my $body = FixMyStreet::App->model('DB::Body')->find( $body_edin_id ); my $user = $mech->log_in_ok( 'test@example.com' ); diff --git a/t/app/controller/rss.t b/t/app/controller/rss.t index 4f737dda7..bec504760 100644 --- a/t/app/controller/rss.t +++ b/t/app/controller/rss.t @@ -44,7 +44,7 @@ my $report = FixMyStreet::App->model('DB::Problem')->find_or_create( { $mech->host('www.fixmystreet.com'); FixMyStreet::override_config { ALLOWED_COBRANDS => [ 'fixmystreet' ], - MAPIT_URL => 'http://mapit.mysociety.org/', + MAPIT_URL => 'http://mapit.uk/', }, sub { $mech->get_ok("/rss/pc/EH11BB/2"); }; @@ -118,7 +118,7 @@ $report->update(); FixMyStreet::override_config { ALLOWED_COBRANDS => [ 'fixmystreet' ], - MAPIT_URL => 'http://mapit.mysociety.org/', + MAPIT_URL => 'http://mapit.uk/', }, sub { $mech->get_ok("/rss/pc/EH11BB/2"); }; @@ -186,7 +186,7 @@ subtest "check RSS feeds on cobrand have correct URLs for non-cobrand reports" = FixMyStreet::override_config { ALLOWED_COBRANDS => [ 'hart' ], - MAPIT_URL => 'http://mapit.mysociety.org/', + MAPIT_URL => 'http://mapit.uk/', }, sub { $mech->get_ok("/rss/area/Hart"); my $cobrand = FixMyStreet::Cobrand->get_class_for_moniker('hart')->new(); diff --git a/t/app/model/alert_type.t b/t/app/model/alert_type.t index 4e8817225..5e4fcec0a 100644 --- a/t/app/model/alert_type.t +++ b/t/app/model/alert_type.t @@ -188,7 +188,7 @@ subtest "correct text for title after URL" => sub { } )->delete; FixMyStreet::override_config { - MAPIT_URL => 'http://mapit.mysociety.org/', + MAPIT_URL => 'http://mapit.uk/', }, sub { FixMyStreet::DB->resultset('AlertType')->email_alerts(); }; @@ -324,7 +324,7 @@ foreach my $test ( $report->update(); FixMyStreet::override_config { - MAPIT_URL => 'http://mapit.mysociety.org/', + MAPIT_URL => 'http://mapit.uk/', }, sub { FixMyStreet::DB->resultset('AlertType')->email_alerts(); }; @@ -432,7 +432,7 @@ subtest "check alerts from cobrand send main site url for alerts for different c )->delete; FixMyStreet::override_config { - MAPIT_URL => 'http://mapit.mysociety.org/', + MAPIT_URL => 'http://mapit.uk/', }, sub { FixMyStreet::DB->resultset('AlertType')->email_alerts(); }; diff --git a/t/app/model/defecttype.t b/t/app/model/defecttype.t new file mode 100644 index 000000000..0f66ac684 --- /dev/null +++ b/t/app/model/defecttype.t @@ -0,0 +1,67 @@ +use strict; +use warnings; +use Test::More; + +use FixMyStreet::App; +use FixMyStreet::TestMech; +my $mech = FixMyStreet::TestMech->new; + +my $oxfordshire = $mech->create_body_ok(2237, 'Oxfordshire County Council', id => 2237); +my $potholes_contact = $mech->create_contact_ok( body_id => $oxfordshire->id, category => 'Potholes', email => 'potholes@example.com' ); +my $traffic_lights_contact =$mech->create_contact_ok( body_id => $oxfordshire->id, category => 'Traffic lights', email => 'lights@example.com' ); + +my $potholes_defect_type = FixMyStreet::App->model('DB::DefectType')->find_or_create( + { + body_id => 2237, + name => 'Potholes', + description => 'This defect type is to do with potholes' + } +); +$potholes_defect_type->contact_defect_types->find_or_create({ + contact_id => $potholes_contact->id, +}); + +my $general_defect_type = FixMyStreet::App->model('DB::DefectType')->find_or_create( + { + body_id => 2237, + name => 'All categories', + description => 'This defect type is for all categories' + } +); + + +subtest 'for_bodies returns correct results' => sub { + my $defect_types = FixMyStreet::App->model('DB::DefectType')->for_bodies( + [ $oxfordshire->id ], + 'Potholes' + ); + + is $defect_types->count, 2, 'Both defect types are included for Potholes category'; + + $defect_types = FixMyStreet::App->model('DB::DefectType')->for_bodies( + [ $oxfordshire->id ], + 'Traffic lights' + ); + + is $defect_types->count, 1, 'Only 1 defect type is included for Traffic lights category'; + is $defect_types->first->name, $general_defect_type->name, 'Correct defect type is returned for Traffic lights category'; +}; + +subtest 'Problem->defect_types behaves correctly' => sub { + my ($problem) = $mech->create_problems_for_body(1, $oxfordshire->id, 'Test', { + category => 'Potholes', + }); + + is $problem->defect_types->count, 2, 'Both defect types are available for the problem'; + + $problem->update({ category => 'Traffic lights' }); + is $problem->defect_types->count, 1, 'Only 1 defect type is included for Traffic lights category'; + is $problem->defect_types->first->name, $general_defect_type->name, 'Correct defect type is returned for Traffic lights category'; +}; + + +END { + $mech->delete_body( $oxfordshire ); + + done_testing(); +} diff --git a/t/app/model/user.t b/t/app/model/user.t index bf73a9d09..d4115d586 100644 --- a/t/app/model/user.t +++ b/t/app/model/user.t @@ -14,7 +14,7 @@ is $problem->user->latest_anonymity, 0, "User's last report was not anonymous"; FixMyStreet::override_config { ALLOWED_COBRANDS => [ { fixmystreet => '.' } ], - MAPIT_URL => 'http://mapit.mysociety.org/', + MAPIT_URL => 'http://mapit.uk/', }, sub { $mech->get_ok('/around?pc=sw1a1aa'); $mech->follow_link_ok( { text_regex => qr/skip this step/i, }, "follow 'skip this step' link" ); @@ -32,7 +32,7 @@ is $problem->user->latest_anonymity, 1, "User's last update was anonymous"; FixMyStreet::override_config { ALLOWED_COBRANDS => [ { fixmystreet => '.' } ], - MAPIT_URL => 'http://mapit.mysociety.org/', + MAPIT_URL => 'http://mapit.uk/', }, sub { $mech->get_ok('/around?pc=sw1a1aa'); $mech->follow_link_ok( { text_regex => qr/skip this step/i, }, "follow 'skip this step' link" ); diff --git a/t/cobrand/fixamingata.t b/t/cobrand/fixamingata.t index 2ef3c09b4..d6a1c2b34 100644 --- a/t/cobrand/fixamingata.t +++ b/t/cobrand/fixamingata.t @@ -1,19 +1,22 @@ use strict; use warnings; use Test::More; -use LWP::Protocol::PSGI; +use Test::MockModule; BEGIN { use FixMyStreet; FixMyStreet->test_mode(1); } -use t::Mock::MapIt; use mySociety::Locale; use FixMyStreet::TestMech; my $mech = FixMyStreet::TestMech->new; +# Closest road reverse geocode mock +my $resolver = Test::MockModule->new('LWP::Simple'); +$resolver->mock('get', sub($) { "<result></result>" }); + # Front page test ok $mech->host("www.fixamingata.se"), "change host to FixaMinGata"; @@ -101,13 +104,9 @@ subtest "Test ajax decimal points" => sub { # requesting the page, so that the code performs a full switch to Swedish mySociety::Locale::push('en-gb'); - # A note to the future - the run_if_script line must be within a subtest - # otherwise it fails to work - LWP::Protocol::PSGI->register(t::Mock::MapIt->run_if_script, host => 'mapit.sweden'); - FixMyStreet::override_config { ALLOWED_COBRANDS => [ 'fixamingata' ], - MAPIT_URL => 'http://mapit.sweden/' + MAPIT_URL => 'http://mapit.uk/' }, sub { $mech->get_ok('/ajax/lookup_location?term=12345'); # We want an actual decimal point in a JSON response... diff --git a/t/cobrand/form_extras.t b/t/cobrand/form_extras.t index c6f6976d5..22a86ef21 100644 --- a/t/cobrand/form_extras.t +++ b/t/cobrand/form_extras.t @@ -29,7 +29,7 @@ my $mech = FixMyStreet::TestMech->new; FixMyStreet::override_config { ALLOWED_COBRANDS => [ { tester => '.' } ], - MAPIT_URL => 'http://mapit.mysociety.org/', + MAPIT_URL => 'http://mapit.uk/', }, sub { $mech->get_ok('/around'); $mech->submit_form_ok( { with_fields => { pc => 'EH1 1BB', } }, "submit location" ); diff --git a/templates/web/base/admin/category-multiselect.html b/templates/web/base/admin/category-multiselect.html new file mode 100644 index 000000000..98416204f --- /dev/null +++ b/templates/web/base/admin/category-multiselect.html @@ -0,0 +1,10 @@ +<p> + <strong>[% loc('Categories:') %]</strong> +</p> +<p> + <select class="form-control js-multiple" name="categories" id="categories" multiple data-all="[% loc('All categories') %]"> + [% FOR contact IN contacts %] + <option value="[% contact.id %]" [% 'selected' IF contact.active %]>[% contact.category | html %]</option> + [% END %] + </select> +</p> diff --git a/templates/web/base/admin/defecttypes/edit.html b/templates/web/base/admin/defecttypes/edit.html new file mode 100644 index 000000000..65c8a5ab7 --- /dev/null +++ b/templates/web/base/admin/defecttypes/edit.html @@ -0,0 +1,37 @@ +[% INCLUDE 'admin/header.html' title=tprintf(loc('Defect Type for %s'), body.name) -%] +[% dt = defect_type %] + +[% UNLESS dt.id %]<h3>[% loc('New defect type') %]</h3>[% END %] + +<form method="post" + action="[% c.uri_for('', body.id, dt.id || 'new' ) %]" + enctype="application/x-www-form-urlencoded" + accept-charset="utf-8" + class="validate"> + + <p> + <strong>[% loc('Name:') %] </strong> + <input type="text" name="name" class="required form-control" size="30" value="[% dt.name | html %]"> + </p> + <p> + <strong>[% loc('Description:') %] </strong> + <input type="text" name="description" class="form-control" size="30" value="[% dt.description | html %]"> + </p> + + <div class="admin-hint"> + <p> + [% loc('If you only want this defect type to be an option for specific categories, pick them here. By default they will show for all categories.') %] + </p> + </div> + + [% INCLUDE 'admin/category-multiselect.html' %] + + [% TRY %][% INCLUDE 'admin/defecttypes/extra_fields.html' %][% CATCH file %][% END %] + + <p> + <input type="hidden" name="token" value="[% csrf_token %]" > + <input type="submit" class="btn" name="save" value="[% dt.id ? loc('Save changes') : loc('Create defect type') %]" > + </p> +</form> + +[% INCLUDE 'admin/footer.html' %] diff --git a/templates/web/base/admin/defecttypes/index.html b/templates/web/base/admin/defecttypes/index.html new file mode 100644 index 000000000..2e6ce7e1b --- /dev/null +++ b/templates/web/base/admin/defecttypes/index.html @@ -0,0 +1,13 @@ +[% INCLUDE 'admin/header.html' title=loc('Defect Types') -%] + +<ul> + [% FOR body IN bodies %] + <li> + <a href="[% c.uri_for('', body.id) %]">[% body.name %]</a> + [% defect_types_count = body.defect_types.count %] + [% IF defect_types_count %]([% defect_types_count %])[% END %] + </li> + [% END %] +</ul> + +[% INCLUDE 'admin/footer.html' %] diff --git a/templates/web/base/admin/defecttypes/list.html b/templates/web/base/admin/defecttypes/list.html new file mode 100644 index 000000000..1a9cb4fa7 --- /dev/null +++ b/templates/web/base/admin/defecttypes/list.html @@ -0,0 +1,35 @@ +[% INCLUDE 'admin/header.html' title=tprintf(loc('Defect Types for %s'), body.name) -%] + +<table> + <thead> + <tr> + <th> [% loc('Name') %] </th> + <th> [% loc('Description') %] </th> + <th> [% loc('Categories') %] </th> + <th> </th> + </tr> + </thead> + <tbody> + [% PROCESS 'defect_type/format.html' %] + [% FOR d IN defect_types %] + <tr> + <td> [% defect_type_format(defect_type=d) %] </td> + <td> [% d.description | html %] </td> + <td> + [% UNLESS d.contacts.size %] + <em>[% loc('All categories') %]</em> + [% ELSE %] + [% FOR contact IN d.contacts %] + [% contact.category %][% ',' UNLESS loop.last %] + [% END %] + [% END %] + </td> + <td> <a href="[% c.uri_for('', body.id, d.id) %]" class="btn">[% loc('Edit') %]</a> </td> + </tr> + [% END %] + </tbody> +</table> + +<a href="[% c.uri_for('', body.id, 'new') %]" class="btn">[% loc('New defect type') %]</a> + +[% INCLUDE 'admin/footer.html' %] diff --git a/templates/web/base/defect_type/format.html b/templates/web/base/defect_type/format.html new file mode 100644 index 000000000..3c0781501 --- /dev/null +++ b/templates/web/base/defect_type/format.html @@ -0,0 +1,9 @@ +[% +# This template can be overridden by cobrands if they've added extra fields +# to the DefectType model (e.g Cobrand::Oxfordshire->defect_type_extra_fields) +# which should be used to represent this DefectType +# to the user in the inspect form. +~%] +[% MACRO defect_type_format BLOCK ~%] +[%~ defect_type.name | html ~%] +[%~ END %]
\ No newline at end of file diff --git a/templates/web/base/report/_inspect.html b/templates/web/base/report/_inspect.html index 625887eff..5e97de3f4 100644 --- a/templates/web/base/report/_inspect.html +++ b/templates/web/base/report/_inspect.html @@ -62,18 +62,17 @@ [% END %] [% IF permissions.report_inspect %] - [% IF c.cobrand.defect_types %] - <p> - <label for="defect_type">[% loc('Defect type') %]</label> - [% defect_type = problem.get_extra_metadata('defect_type') %] - <select id="defect_type" name="defect_type" class="form-control"> - <option value=""[% ' selected' IF NOT defect_type %]>-</option> - [% FOREACH dt IN c.cobrand.defect_types.pairs %] - <option[% ' selected' IF defect_type == dt.key %] value="[% dt.key | html %]">[% dt.value | html %]</option> - [% END %] - </select> - </p> - [% END %] + [% PROCESS 'defect_type/format.html' %] + <p> + <label for="defect_type">[% loc('Defect type') %]</label> + <select id="defect_type" name="defect_type" class="form-control"> + <option value=""[% ' selected' IF NOT problem.defect_type %]>-</option> + [% FOREACH defect_type IN problem.defect_types %] + <option[% ' selected' IF problem.defect_type_id == defect_type.id %] value="[% defect_type.id %]">[% defect_type_format() %]</option> + [% END %] + </select> + </p> + <p> <label for="state">[% loc('State') %]</label> [% INCLUDE 'report/inspect/state_groups_select.html' %] diff --git a/templates/web/oxfordshire/admin/defecttypes/extra_fields.html b/templates/web/oxfordshire/admin/defecttypes/extra_fields.html new file mode 100644 index 000000000..73cc54f0c --- /dev/null +++ b/templates/web/oxfordshire/admin/defecttypes/extra_fields.html @@ -0,0 +1,8 @@ +<p> + <strong>[% loc('Activity Code:') %] </strong> + <input type="text" name="extra[activity_code]" class="form-control" size="30" value="[% dt.get_extra_metadata('activity_code') | html %]"> +</p> +<p> + <strong>[% loc('Defect Code:') %] </strong> + <input type="text" name="extra[defect_code]" class="form-control" size="30" value="[% dt.get_extra_metadata('defect_code') | html %]"> +</p> diff --git a/templates/web/oxfordshire/defect_type/format.html b/templates/web/oxfordshire/defect_type/format.html new file mode 100644 index 000000000..9cbf2d873 --- /dev/null +++ b/templates/web/oxfordshire/defect_type/format.html @@ -0,0 +1,4 @@ +[% MACRO defect_type_format BLOCK ~%] +[%~ defect_type.get_extra_metadata('defect_code') | html %] - [% defect_type.get_extra_metadata('activity_code') | html %] +([% defect_type.name | html %]) +[%~ END %]
\ No newline at end of file diff --git a/web/cobrands/fixmystreet/admin.js b/web/cobrands/fixmystreet/admin.js index 02eb30766..f7fcaf276 100644 --- a/web/cobrands/fixmystreet/admin.js +++ b/web/cobrands/fixmystreet/admin.js @@ -48,6 +48,8 @@ $(function(){ } }); + $("select.js-multiple[multiple]").make_multi(); + // on a body's page, hide/show deleted contact categories var $table_with_deleted_contacts = $('table tr.is-deleted td.contact-category').closest('table'); if ($table_with_deleted_contacts.length == 1) { diff --git a/web/cobrands/fixmystreet/fixmystreet.js b/web/cobrands/fixmystreet/fixmystreet.js index c09eeb803..e92395661 100644 --- a/web/cobrands/fixmystreet/fixmystreet.js +++ b/web/cobrands/fixmystreet/fixmystreet.js @@ -109,6 +109,20 @@ function isR2L() { $drawer.hide(); }); }); + }, + + make_multi: function() { + var $this = $(this), + all = $this.data('all'); + $this.multiSelect({ + allText: all, + noneText: all, + positionMenuWithin: $('#side'), + presets: [{ + name: all, + options: [] + }] + }); } }); @@ -535,23 +549,8 @@ $.extend(fixmystreet.set_up, { // to refresh the map when the filter inputs are changed. $(".report-list-filters [type=submit]").hide(); - function make_multi(id) { - var $id = $('#' + id), - all = $id.data('all'), - none = $id.data('none') || all, - allOpts = $id.data('allOptions') || []; - $id.multiSelect({ - allText: all, - noneText: none, - positionMenuWithin: $('#side'), - presets: [{ - name: all, - options: allOpts - }] - }); - } - make_multi('statuses'); - make_multi('filter_categories'); + $('#statuses').make_multi(); + $('#filter_categories').make_multi(); }, mobile_ui_tweaks: function() { |