diff options
-rw-r--r-- | perllib/FixMyStreet/Cobrand/Default.pm | 7 | ||||
-rw-r--r-- | perllib/FixMyStreet/Cobrand/LichfieldDC.pm | 12 | ||||
-rw-r--r-- | perllib/FixMyStreet/Cobrand/Oxfordshire.pm | 12 | ||||
-rw-r--r-- | perllib/FixMyStreet/Cobrand/Stevenage.pm | 1 | ||||
-rw-r--r-- | perllib/FixMyStreet/Cobrand/UKCouncils.pm | 14 | ||||
-rw-r--r-- | t/app/controller/report_new.t | 157 |
6 files changed, 131 insertions, 72 deletions
diff --git a/perllib/FixMyStreet/Cobrand/Default.pm b/perllib/FixMyStreet/Cobrand/Default.pm index 1f3b4d4bb..11851c5a1 100644 --- a/perllib/FixMyStreet/Cobrand/Default.pm +++ b/perllib/FixMyStreet/Cobrand/Default.pm @@ -601,6 +601,13 @@ For UK sub-cobrands, to specify various alternations needed for them. =cut sub is_council { 0; } +=item is_two_tier + +For UK sub-cobrands, to specify various alternations needed for them. + +=cut +sub is_two_tier { 0; } + =item council_rss_alert_options Generate a set of options for council rss alerts. diff --git a/perllib/FixMyStreet/Cobrand/LichfieldDC.pm b/perllib/FixMyStreet/Cobrand/LichfieldDC.pm index b3dbad089..31d5bf987 100644 --- a/perllib/FixMyStreet/Cobrand/LichfieldDC.pm +++ b/perllib/FixMyStreet/Cobrand/LichfieldDC.pm @@ -8,6 +8,7 @@ sub council_id { return 2434; } sub council_area { return 'Lichfield district'; } sub council_name { return 'Lichfield District Council'; } sub council_url { return 'lichfielddc'; } +sub is_two_tier { return 1; } # Different to councils parent due to this being a two-tier council. If we get # more, this can be genericised in the parent. @@ -26,17 +27,6 @@ sub disambiguate_location { }; } -# If we ever link to a county problem report, needs to be to main FixMyStreet -sub base_url_for_report { - my ( $self, $report ) = @_; - my %councils = map { $_ => 1 } @{$report->councils}; - if ( $councils{2434} ) { - return $self->base_url; - } else { - return FixMyStreet->config('BASE_URL'); - } -} - sub map_type { return 'OSM'; } diff --git a/perllib/FixMyStreet/Cobrand/Oxfordshire.pm b/perllib/FixMyStreet/Cobrand/Oxfordshire.pm index 745123fdb..9aa054020 100644 --- a/perllib/FixMyStreet/Cobrand/Oxfordshire.pm +++ b/perllib/FixMyStreet/Cobrand/Oxfordshire.pm @@ -8,6 +8,7 @@ sub council_id { return 2237; } sub council_area { return 'Oxfordshire'; } sub council_name { return 'Oxfordshire County Council'; } sub council_url { return 'oxfordshire'; } +sub is_two_tier { return 1; } sub base_url { return FixMyStreet->config('BASE_URL') if FixMyStreet->config('STAGING_SITE'); @@ -48,17 +49,6 @@ sub example_places { return ( 'OX20 1SZ', 'Park St, Woodstock' ); } -# If we ever link to a district problem report, needs to be to main FixMyStreet -sub base_url_for_report { - my ( $self, $report ) = @_; - my %councils = map { $_ => 1 } @{$report->councils}; - if ( $councils{2237} ) { - return $self->base_url; - } else { - return FixMyStreet->config('BASE_URL'); - } -} - sub default_show_name { 0 } 1; diff --git a/perllib/FixMyStreet/Cobrand/Stevenage.pm b/perllib/FixMyStreet/Cobrand/Stevenage.pm index f7a9ccd84..560baba37 100644 --- a/perllib/FixMyStreet/Cobrand/Stevenage.pm +++ b/perllib/FixMyStreet/Cobrand/Stevenage.pm @@ -8,6 +8,7 @@ sub council_id { return 2347; } sub council_area { return 'Stevenage'; } sub council_name { return 'Stevenage Council'; } sub council_url { return 'stevenage'; } +sub is_two_tier { return 1; } sub path_to_web_templates { my $self = shift; diff --git a/perllib/FixMyStreet/Cobrand/UKCouncils.pm b/perllib/FixMyStreet/Cobrand/UKCouncils.pm index a9ebb1b3f..4c80da4f3 100644 --- a/perllib/FixMyStreet/Cobrand/UKCouncils.pm +++ b/perllib/FixMyStreet/Cobrand/UKCouncils.pm @@ -86,4 +86,18 @@ sub recent_photos { return $self->problems->recent_photos( $num, $lat, $lon, $dist ); } +sub base_url_for_report { + my ( $self, $report ) = @_; + if ( $self->is_two_tier ) { + my %councils = map { $_ => 1 } @{$report->councils}; + if ( $councils{$self->council_id} ) { + return $self->base_url; + } else { + return FixMyStreet->config('BASE_URL'); + } + } else { + return $self->base_url; + } +} + 1; diff --git a/t/app/controller/report_new.t b/t/app/controller/report_new.t index d20f15922..6cfa67116 100644 --- a/t/app/controller/report_new.t +++ b/t/app/controller/report_new.t @@ -1079,67 +1079,124 @@ SKIP: { skip( "Need 'lichfielddc' in ALLOWED_COBRANDS config", 100 ) unless FixMyStreet::Cobrand->exists('lichfielddc'); - my $test_email = 'test-22@example.com'; - $mech->host( 'http://lichfielddc.fixmystreet.com/' ); - $mech->clear_emails_ok; - $mech->log_out_ok; - - $mech->get_ok('/around'); - $mech->content_contains( "Lichfield District Council FixMyStreet" ); - $mech->submit_form_ok( { with_fields => { pc => 'WS13 7RD' } }, "submit location" ); - $mech->follow_link_ok( { text_regex => qr/skip this step/i, }, "follow 'skip this step' link" ); - $mech->submit_form_ok( + for my $test ( { - button => 'submit_register', - with_fields => { - title => 'Test Report', - detail => 'Test report details.', - photo => '', - name => 'Joe Bloggs', - may_show_name => '1', - email => $test_email, - phone => '07903 123 456', - category => 'Street lighting', - } + desc => 'confirm link for cobrand council in two tier cobrand links to cobrand site', + category => 'Trees', + council => 2434, + link_base => 'http://lichfielddc.localhost/', + national => 0, + button => 'submit_register', }, - "submit good details" - ); - is_deeply $mech->page_errors, [], "check there were no errors"; + { + desc => 'confirm link for non cobrand council in two tier cobrand links to national site', + category => 'Street Lighting', + council => 2240, + link_base => 'http://localhost/', + national => 1, + button => 'submit_register', + }, + { + desc => 'confirm redirect for cobrand council in two tier cobrand redirects to cobrand site', + category => 'Trees', + council => 2434, + link_base => 'lichfielddc.localhost', + national => 0, + redirect => 1, + }, + { + desc => 'confirm redirect for non cobrand council in two tier cobrand redirect to national site', + category => 'Street Lighting', + council => 2240, + link_base => 'localhost', + national => 1, + redirect => 1, + }, + ) { + subtest $test->{ desc } => sub { + my $test_email = 'test-22@example.com'; + $mech->host( 'http://lichfielddc.fixmystreet.com/' ); + $mech->clear_emails_ok; + $mech->log_out_ok; - # check that the user has been created/ not changed - my $user = - FixMyStreet::App->model('DB::User')->find( { email => $test_email } ); - ok $user, "user found"; + my $user = $mech->log_in_ok($test_email) if $test->{redirect}; - # find the report - my $report = $user->problems->first; - ok $report, "Found the report"; + $mech->get_ok('/around'); + $mech->content_contains( "Lichfield District Council FixMyStreet" ); + $mech->submit_form_ok( { with_fields => { pc => 'WS13 7RD' } }, "submit location" ); + $mech->follow_link_ok( { text_regex => qr/skip this step/i, }, "follow 'skip this step' link" ); + my %optional_fields = $test->{redirect} ? () : + ( email => $test_email, phone => '07903 123 456' ); - # Check the report has been assigned appropriately - is $report->council, 2240; + # we do this as otherwise test::www::mechanize::catalyst + # goes to the value set in ->host above irregardless and + # that is a 404. It works but it is not pleasant. + $mech->clear_host if $test->{redirect} && $test->{national}; + $mech->submit_form_ok( + { + button => $test->{button}, + with_fields => { + title => 'Test Report', + detail => 'Test report details.', + photo => '', + name => 'Joe Bloggs', + may_show_name => '1', + category => $test->{category}, + %optional_fields + } + }, + "submit good details" + ); + is_deeply $mech->page_errors, [], "check there were no errors"; - # receive token - my $email = $mech->get_email; - ok $email, "got an email"; - like $email->body, qr/confirm the problem/i, "confirm the problem"; + # check that the user has been created/ not changed + $user = + FixMyStreet::App->model('DB::User')->find( { email => $test_email } ); + ok $user, "user found"; - my ($url) = $email->body =~ m{(http://\S+)}; - ok $url, "extracted confirm url '$url'"; + # find the report + my $report = $user->problems->first; + ok $report, "Found the report"; - # confirm token - $mech->get_ok($url); - $report->discard_changes; - is $report->state, 'confirmed', "Report is now confirmed"; + # Check the report has been assigned appropriately + is $report->council, $test->{council}; - # Shouldn't be found, as it was a county problem - is $mech->get( '/report/' . $report->id )->code, 404, "report not found"; + if ( $test->{redirect} ) { + is $mech->uri->path, "/report/" . $report->id, "redirected to report page"; + is $mech->uri->host, $test->{link_base}, 'redirected to correct site'; + } else { + # receive token + my $email = $mech->get_email; + ok $email, "got an email"; + like $email->body, qr/confirm the problem/i, "confirm the problem"; - # But should be on the main site - $mech->host( 'www.fixmystreet.com' ); - $mech->get_ok( '/report/' . $report->id ); - is $report->name, 'Joe Bloggs', 'name updated correctly'; + my ($url) = $email->body =~ m{(http://\S+)}; + ok $url, "extracted confirm url '$url'"; - $mech->delete_user($user); + # confirm token + $mech->get_ok($url); + + $mech->content_contains( $test->{link_base} . 'report/' . + $report->id, 'confirm page links to correct site' ); + + if ( $test->{national} ) { + # Shouldn't be found, as it was a county problem + is $mech->get( '/report/' . $report->id )->code, 404, "report not found"; + + # But should be on the main site + $mech->host( 'www.fixmystreet.com' ); + } + $mech->get_ok( '/report/' . $report->id ); + } + + $report->discard_changes; + is $report->state, 'confirmed', "Report is now confirmed"; + + is $report->name, 'Joe Bloggs', 'name updated correctly'; + + $mech->delete_user($user); + }; + } } SKIP: { |