diff options
author | Struan Donald <struan@exo.org.uk> | 2011-05-26 10:59:19 +0100 |
---|---|---|
committer | Struan Donald <struan@exo.org.uk> | 2011-05-26 10:59:19 +0100 |
commit | a5a0867562be92483bd43b8f8a773bb7eef56e95 (patch) | |
tree | 48f928b1e15dade99df8991807e275facea40ace | |
parent | 99c9095b0028e6139e2732f7405991b1d8a5cc98 (diff) |
if appropriate generate language specific uris for emails
-rw-r--r-- | perllib/FixMyStreet/App.pm | 2 | ||||
-rw-r--r-- | perllib/FixMyStreet/Cobrand/Default.pm | 15 | ||||
-rw-r--r-- | perllib/FixMyStreet/Cobrand/EmptyHomes.pm | 20 | ||||
-rw-r--r-- | t/app/uri_for.t | 41 |
4 files changed, 77 insertions, 1 deletions
diff --git a/perllib/FixMyStreet/App.pm b/perllib/FixMyStreet/App.pm index 0c3a8d1cf..1d584accb 100644 --- a/perllib/FixMyStreet/App.pm +++ b/perllib/FixMyStreet/App.pm @@ -353,7 +353,7 @@ sub uri_for_email { my @args = @_; my $normal_uri = $c->uri_for(@_); - my $base = $c->cobrand->base_url_for_emails(); + my $base = $c->cobrand->base_url_with_lang( 1 ); my $email_uri = $base . $normal_uri->path_query; diff --git a/perllib/FixMyStreet/Cobrand/Default.pm b/perllib/FixMyStreet/Cobrand/Default.pm index daea586e4..2f0833a0a 100644 --- a/perllib/FixMyStreet/Cobrand/Default.pm +++ b/perllib/FixMyStreet/Cobrand/Default.pm @@ -137,6 +137,21 @@ sub base_url_for_emails { return $self->base_url; } +=head2 base_url_with_lang + +=cut + +sub base_url_with_lang { + my $self = shift; + my $email = shift; + + if ($email) { + return $self->base_url_for_emails; + } else { + return $self->base_url; + } +} + =head2 admin_base_url Base URL for the admin interface. diff --git a/perllib/FixMyStreet/Cobrand/EmptyHomes.pm b/perllib/FixMyStreet/Cobrand/EmptyHomes.pm index cbecb1c34..c40ea5eb7 100644 --- a/perllib/FixMyStreet/Cobrand/EmptyHomes.pm +++ b/perllib/FixMyStreet/Cobrand/EmptyHomes.pm @@ -30,6 +30,26 @@ sub area_types { return qw(DIS LBO MTD UTA LGD COI); # No CTY } + +sub base_url_with_lang { + my $self = shift; + my $email = shift; + + my $base = $self->base_url; + + if ($email) { + $base = $self->base_url_for_emails; + } + + my $lang = $mySociety::Locale::lang; + if ($lang eq 'cy') { + $base =~ s{http://}{$&cy.}; + } else { + $base =~ s{http://}{$&en.}; + } + return $base; +} + =item set_lang_and_domain LANG UNICODE Set the language and text domain for the site based on the query and host. diff --git a/t/app/uri_for.t b/t/app/uri_for.t index 309c3a3b2..67acbc235 100644 --- a/t/app/uri_for.t +++ b/t/app/uri_for.t @@ -35,6 +35,20 @@ my $fgm_c = FixMyStreet::App->new( } ); +my $reh_en_c = FixMyStreet::App->new( + { + request => Catalyst::Request->new( + { + base => URI->new('http://reportemptyhomes.com/'), + uri => URI->new('http://reportemptyhomes.com/test_namespace') + } + ), + namespace => 'test_namespace', + } +); +$reh_en_c->setup_request(); + + is( $fms_c->uri_for('/bar/baz') . "", 'http://www.fixmystreet.com/bar/baz', @@ -60,6 +74,33 @@ is( 'FiksGataMi url with lat not zoom' ); +like( + $reh_en_c->uri_for_email( '/foo' ), + qr{^http://en.}, + 'adds en to retain language' +); + +# instantiate this here otherwise sets locale to cy and breaks test +# above +my $reh_cy_c = FixMyStreet::App->new( + { + request => Catalyst::Request->new( + { + base => URI->new('http://cy.reportemptyhomes.com/'), + uri => URI->new('http://cy.reportemptyhomes.com/test_namespace') + } + ), + namespace => 'test_namespace', + } +); +$reh_cy_c->setup_request(); + +like( + $reh_cy_c->uri_for_email( '/foo' ), + qr{^http://cy.}, + 'retains language' +); + ## Should really test the cities but we'd need to fake up too much of the # request. Following code starts to do this but is not complete. Instead better # to test that the cities produces the correct urls by looking at the html |