diff options
author | Matthew Somerville <matthew-github@dracos.co.uk> | 2016-09-20 16:49:08 +0100 |
---|---|---|
committer | Matthew Somerville <matthew-github@dracos.co.uk> | 2016-09-20 16:49:08 +0100 |
commit | 35b2e8fbcb4d382377ca8652d058dc263707b82b (patch) | |
tree | 1303dfbea8a36113fc4cbbe36f0f9d19ccbbb656 | |
parent | 9d4e468cc2cbde4592ceada4c7471556154088d7 (diff) | |
parent | 1c5c614af7a0265bd296ef67c0d342b27898185c (diff) |
Merge branch '1529-cobrand-testing'
-rwxr-xr-x | bin/fixmystreet.com/fixture | 39 | ||||
-rw-r--r-- | conf/general.yml-example | 3 | ||||
-rw-r--r-- | perllib/FixMyStreet/Cobrand/FiksGataMi.pm | 2 | ||||
-rw-r--r-- | perllib/FixMyStreet/Cobrand/FixaMinGata.pm | 2 | ||||
-rw-r--r-- | perllib/FixMyStreet/Cobrand/UKCouncils.pm | 4 | ||||
-rw-r--r-- | perllib/Utils.pm | 17 | ||||
-rw-r--r-- | t/utils.t | 36 | ||||
-rw-r--r-- | t/utils/email.t | 34 | ||||
-rw-r--r-- | templates/web/zurich/maps/noscript_map.html | 30 |
9 files changed, 153 insertions, 14 deletions
diff --git a/bin/fixmystreet.com/fixture b/bin/fixmystreet.com/fixture new file mode 100755 index 000000000..93982af8a --- /dev/null +++ b/bin/fixmystreet.com/fixture @@ -0,0 +1,39 @@ +#!/usr/bin/env perl +# +# This script will create a test body and its categories, covering the area of +# Westminster, and a user associated with that body, which should help testing +# of report interactions. + +use strict; +use warnings; + +BEGIN { + use File::Basename qw(dirname); + use File::Spec; + my $d = dirname(File::Spec->rel2abs($0)); + require "$d/../../setenv.pl"; +} + +use FixMyStreet::DB; + +my $body = FixMyStreet::DB->resultset("Body")->find_or_create({ name => 'Test City Council' }); +$body->body_areas->find_or_create({ area_id => 2504 }); +foreach ("Potholes", "Street lighting", "Graffiti") { + (my $email = lc $_) =~ s/ /-/g; + $body->contacts->find_or_create({ + category => $_, + email => $email . '@example.net', + confirmed => 't', + deleted => 'f', + whenedited => \'current_timestamp', + editor => 'fixture', + note => 'Created by fixture' + }); +} + +FixMyStreet::DB->resultset("User")->find_or_create({ + email => 'council@example.net', + name => 'Test City Council User', + from_body => $body, + password => 'password', +}); diff --git a/conf/general.yml-example b/conf/general.yml-example index 54bbd6a7f..3b2c597b9 100644 --- a/conf/general.yml-example +++ b/conf/general.yml-example @@ -46,6 +46,9 @@ STAGING_SITE: 1 # reports to live places. Set this to 1 if you want a dev site to route # reports as normal. SEND_REPORTS_ON_STAGING: 0 +# Manual testing of multiple cobrands can be made easier by skipping some +# checks they have in them, if this variable is set +SKIP_CHECKS_ON_STAGING: 0 # What to use as front page/alert example places placeholder # Defaults to High Street, Main Street diff --git a/perllib/FixMyStreet/Cobrand/FiksGataMi.pm b/perllib/FixMyStreet/Cobrand/FiksGataMi.pm index ba26b7a2c..242735073 100644 --- a/perllib/FixMyStreet/Cobrand/FiksGataMi.pm +++ b/perllib/FixMyStreet/Cobrand/FiksGataMi.pm @@ -29,6 +29,8 @@ sub disambiguate_location { } sub area_types { + my $self = shift; + return $self->next::method() if FixMyStreet->config('STAGING_SITE') && FixMyStreet->config('SKIP_CHECKS_ON_STAGING'); [ 'NKO', 'NFY', 'NRA' ]; } diff --git a/perllib/FixMyStreet/Cobrand/FixaMinGata.pm b/perllib/FixMyStreet/Cobrand/FixaMinGata.pm index 9ffbf00b8..a321d5c7c 100644 --- a/perllib/FixMyStreet/Cobrand/FixaMinGata.pm +++ b/perllib/FixMyStreet/Cobrand/FixaMinGata.pm @@ -30,6 +30,8 @@ sub disambiguate_location { } sub area_types { + my $self = shift; + return $self->next::method() if FixMyStreet->config('STAGING_SITE') && FixMyStreet->config('SKIP_CHECKS_ON_STAGING'); [ 'KOM' ]; } diff --git a/perllib/FixMyStreet/Cobrand/UKCouncils.pm b/perllib/FixMyStreet/Cobrand/UKCouncils.pm index 5d72c4962..42c9c5cbc 100644 --- a/perllib/FixMyStreet/Cobrand/UKCouncils.pm +++ b/perllib/FixMyStreet/Cobrand/UKCouncils.pm @@ -42,11 +42,13 @@ sub restriction { sub problems_restriction { my ($self, $rs) = @_; + return $rs if FixMyStreet->config('STAGING_SITE') && FixMyStreet->config('SKIP_CHECKS_ON_STAGING'); return $rs->to_body($self->council_id); } sub updates_restriction { my ($self, $rs) = @_; + return $rs if FixMyStreet->config('STAGING_SITE') && FixMyStreet->config('SKIP_CHECKS_ON_STAGING'); return $rs->to_body($self->council_id); } @@ -96,6 +98,8 @@ sub enter_postcode_text { sub area_check { my ( $self, $params, $context ) = @_; + return 1 if FixMyStreet->config('STAGING_SITE') && FixMyStreet->config('SKIP_CHECKS_ON_STAGING'); + my $councils = $params->{all_areas}; my $council_match = defined $councils->{$self->council_id}; if ($council_match) { diff --git a/perllib/Utils.pm b/perllib/Utils.pm index 87c1a10d6..84c09d09d 100644 --- a/perllib/Utils.pm +++ b/perllib/Utils.pm @@ -15,6 +15,7 @@ use Encode; use File::Slurp qw(); use mySociety::GeoUtil; use mySociety::Locale; +use FixMyStreet; =head2 convert_latlon_to_en @@ -199,7 +200,7 @@ sub prettify_duration { $s = int(($s+60*60*12)/60/60/24)*60*60*24; } elsif ($nearest eq 'hour') { $s = int(($s+60*30)/60/60)*60*60; - } elsif ($nearest eq 'minute') { + } else { # minute $s = int(($s+30)/60)*60; return _('less than a minute') if $s == 0; } @@ -221,7 +222,7 @@ sub _part { $str = mySociety::Locale::nget("%d day", "%d days", $i); } elsif ($m == 60*60) { $str = mySociety::Locale::nget("%d hour", "%d hours", $i); - } elsif ($m == 60) { + } else { $str = mySociety::Locale::nget("%d minute", "%d minutes", $i); } push @$o, sprintf($str, $i); @@ -229,17 +230,5 @@ sub _part { } } -=head2 read_file - -Reads in a UTF-8 encoded file using File::Slurp and decodes it from UTF-8. -This appears simplest, rather than getting confused with binmodes and so on. - -=cut -sub read_file { - my $filename = shift; - my $data = File::Slurp::read_file( $filename ); - $data = Encode::decode( 'utf8', $data ); - return $data; -} 1; @@ -4,6 +4,9 @@ use strict; use warnings; use Test::More; +use mySociety::Locale; +mySociety::Locale::gettext_domain('FixMyStreet'); + use Utils; my @truncate_tests = ( @@ -34,9 +37,14 @@ foreach my $test (@convert_en_to_latlon_tests) { [ Utils::convert_en_to_latlon_truncated( $e, $n ) ], # [ $lat, $lon ], # "convert ($e,$n) to ($lat,$lon)"; + is_deeply + [ Utils::convert_latlon_to_en( $lat, $lon ) ], + [ $e, $n ], + "convert ($lat,$lon) to ($e,$n)"; } my @cleanup_tests = ( + [ '', '', '' ], [ 'dog shit', 'Dog poo', 'dog poo' ], [ 'dog shit', 'Dog poo', 'with spaces' ], [ 'dog shite', 'Dog poo', 'with extra e' ], @@ -57,4 +65,32 @@ foreach my $test ( @cleanup_tests ) { is Utils::cleanup_text( "This has new\n\n\nlines in it", { allow_multiline => 1 } ), "This has new\n\nLines in it", 'new lines allowed'; + +is Utils::prettify_dt(), "[unknown time]"; +my $dt = DateTime->now; +is Utils::prettify_dt($dt), $dt->strftime("%H:%M today"); + +# Same week test +if ($dt->day_of_week == 7) { # Sunday + $dt = DateTime->now->add(days => 1); +} else { + $dt = DateTime->now->subtract(days => 1); +} +is Utils::prettify_dt($dt), $dt->strftime("%H:%M, %A"); + +$dt = DateTime->now->subtract(days => 100); +is Utils::prettify_dt($dt), $dt->strftime("%H:%M, %A %e %B %Y"); +is Utils::prettify_dt($dt, "date"), $dt->strftime("%A %e %B %Y"); +is Utils::prettify_dt($dt, "zurich"), $dt->strftime("%H:%M, %e. %B %Y"); +is Utils::prettify_dt($dt, "short"), $dt->strftime("%H:%M, %e %b %Y"); +is Utils::prettify_dt($dt, 1), $dt->strftime("%H:%M, %e %b %Y"); +$dt = DateTime->now->subtract(days => 400); +is Utils::prettify_dt($dt), $dt->strftime("%H:%M, %a %e %B %Y"); + +is Utils::prettify_duration(7*86400+3600+60+1, 'week'), '1 week'; +is Utils::prettify_duration(86400+3600+60+1, 'day'), '1 day'; +is Utils::prettify_duration(86400+3600+60+1, 'hour'), '1 day, 1 hour'; +is Utils::prettify_duration(86400+3600+60+1, 'minute'), '1 day, 1 hour, 1 minute'; +is Utils::prettify_duration(20, 'minute'), 'less than a minute'; + done_testing(); diff --git a/t/utils/email.t b/t/utils/email.t new file mode 100644 index 000000000..23814c1d7 --- /dev/null +++ b/t/utils/email.t @@ -0,0 +1,34 @@ +#!/usr/bin/env perl + +use strict; +use warnings; +use Test::More; +use Test::MockModule; + +use Utils::Email; + +my $resolver = Test::MockModule->new('Net::DNS::Resolver'); +$resolver->mock('send', sub { + my ($self, $domain, $type) = @_; + my @rrs; + is $type, 'TXT'; + if ($domain eq '_dmarc.yahoo.com') { + @rrs = ( + Net::DNS::RR->new(name => '_dmarc.yahoo.com', type => 'TXT', txtdata => 'p=reject'), + Net::DNS::RR->new(name => '_dmarc.yahoo.com', type => 'A'), + ); + } elsif ($domain eq 'cname.example.com') { + @rrs = Net::DNS::RR->new(name => 'cname.example.com', type => 'TXT', txtdata => 'p=none'); + } else { + @rrs = Net::DNS::RR->new(name => '_dmarc.example.net', type => 'CNAME', cname => 'cname.example.com'); + } + my $pkt = Net::DNS::Packet->new; + push @{$pkt->{answer}}, @rrs; + return $pkt; +}); + +is Utils::Email::test_dmarc('BAD'), undef; +is Utils::Email::test_dmarc('test@yahoo.com'), 1; +is Utils::Email::test_dmarc('test@example.net'), undef; + +done_testing(); diff --git a/templates/web/zurich/maps/noscript_map.html b/templates/web/zurich/maps/noscript_map.html index dcd577c52..4925f9260 100644 --- a/templates/web/zurich/maps/noscript_map.html +++ b/templates/web/zurich/maps/noscript_map.html @@ -1,3 +1,4 @@ +[% IF map.cols %] <div class="noscript square-map__outer"> <div class="square-map__inner"> <div id="[% nsm_prefix %]drag"> @@ -19,6 +20,35 @@ [% INCLUDE 'maps/_compass.html' %] </div> </div> +[% ELSE %] +<div class="noscript"> + <div id="[% nsm_prefix %]drag"> + <[% map.img_type %] + alt="NW map tile" id="[% nsm_prefix %]t2.2" + name="tile_[% map.x_tile - 1 %].[% map.y_tile - 1 %]" + src="[% map.tiles.0 %]" + style="top:0; left:0;"> + <[% map.img_type %] + alt="NE map tile" id="[% nsm_prefix %]t2.3" + name="tile_[% map.x_tile %].[% map.y_tile - 1 %]" + src="[% map.tiles.1 %]" + style="top:0px; left:256px;"> + <br> + <[% map.img_type %] + alt="SW map tile" id="[% nsm_prefix %]t3.2" + name="tile_[% map.x_tile - 1 %].[% map.y_tile %]" + src="[% map.tiles.2 %]" + style="top:256px; left:0;"> + <[% map.img_type %] + alt="SE map tile" id="[% nsm_prefix %]t3.3" + name="tile_[% map.x_tile %].[% map.y_tile %]" + src="[% map.tiles.3 %]" + style="top:256px; left:256px;"> + </div> + <div id="[% nsm_prefix %]pins">[% FOR pin IN map.pins %][% INCLUDE 'maps/pin.html' %][% END %]</div> + [% INCLUDE 'maps/_compass.html' %] +</div> +[% END %] [% BLOCK pin %] [% |