diff options
Diffstat (limited to 't')
-rw-r--r-- | t/app/controller/alert.t | 2 | ||||
-rw-r--r-- | t/app/controller/alert_new.t | 22 | ||||
-rw-r--r-- | t/app/controller/around.t | 5 | ||||
-rw-r--r-- | t/app/controller/index.t | 13 | ||||
-rw-r--r-- | t/app/controller/questionnaire.t | 26 | ||||
-rw-r--r-- | t/app/controller/report_interest_count.t | 143 | ||||
-rw-r--r-- | t/app/controller/report_new.t | 47 | ||||
-rw-r--r-- | t/app/model/alert_type.t | 47 | ||||
-rw-r--r-- | t/app/model/problem.t | 8 | ||||
-rw-r--r-- | t/cobrand/councils.t | 18 | ||||
-rw-r--r-- | t/cobrand/get_council_sender.t | 8 | ||||
-rw-r--r-- | t/i18n.t | 11 | ||||
-rw-r--r-- | t/open311.t | 3 |
13 files changed, 315 insertions, 38 deletions
diff --git a/t/app/controller/alert.t b/t/app/controller/alert.t index e1ebbecb6..3d95bef6d 100644 --- a/t/app/controller/alert.t +++ b/t/app/controller/alert.t @@ -40,7 +40,7 @@ $mech->get_ok('/alert/list?pc=High Street'); $mech->content_contains('We found more than one match for that location'); $mech->get_ok('/alert/list?pc='); -$mech->content_contains('hat location does not appear to be covered by a council'); +$mech->content_contains('To find out what local alerts we have for you'); $mech->get_ok('/alert/list?pc=GL502PR'); $mech->content_contains('Problems within the boundary of'); diff --git a/t/app/controller/alert_new.t b/t/app/controller/alert_new.t index 84634273a..c849b9485 100644 --- a/t/app/controller/alert_new.t +++ b/t/app/controller/alert_new.t @@ -330,7 +330,7 @@ subtest "Test two-tier council alerts" => sub { feed => $alert->{feed}, } } ); - is $mech->uri->path, $alert->{result}; + is $mech->uri->path, $alert->{result}, 'Redirected to right RSS feed'; } }; @@ -390,7 +390,7 @@ subtest "Test normal alert signups and that alerts are sent" => sub { used_map => 1, name => $user1->name, anonymous => 0, - state => 'confirmed', + state => 'fixed - user', confirmed => $dt, lastupdate => $dt, whensent => $dt->clone->add( minutes => 5 ), @@ -430,7 +430,7 @@ subtest "Test normal alert signups and that alerts are sent" => sub { problem_id => $report_id, user_id => $user2->id, name => 'Anonymous User', - mark_fixed => 'false', + mark_fixed => 'true', text => 'This is some more update text', state => 'confirmed', confirmed => $dt->clone->add( hours => 8 ), @@ -450,13 +450,23 @@ subtest "Test normal alert signups and that alerts are sent" => sub { $count++ if $_->body =~ /The following nearby problems have been added:/; $count++ if $_->body =~ /\s+-\s+Testing/; } - is $count, 5, 'Five emails with the right things in them'; + is $count, 5, 'Three emails, with five matching lines in them'; my $email = $emails[0]; like $email->body, qr/Other User/, 'Update name given'; unlike $email->body, qr/Anonymous User/, 'Update name not given'; - my ( $url, $url_token ) = $emails[0]->body =~ m{http://\S+(/A/(\S+))}; + # The update alert was to the problem reporter, so has a login update URL + $mech->get_ok( "/report/$report_id" ); + $mech->content_lacks( 'has not been fixed' ); + my ($url) = $email->body =~ m{(http://\S+/M/\S+)}; + ok $url, "extracted update url '$url'"; + $mech->get_ok( $url ); + is $mech->uri->path, "/report/" . $report_id, "redirected to report page"; + $mech->content_contains( 'has not been fixed' ); + $mech->logged_in_ok; + + ($url) = $emails[0]->body =~ m{http://\S+(/A/\S+)}; $mech->get_ok( $url ); $mech->content_contains('successfully deleted'); @@ -553,7 +563,7 @@ for my $test ( FixMyStreet::App->model('DB::AlertType')->email_alerts(); $mech->email_count_is(1); my $email = $mech->get_email; - like $email->body, qr/Alert test for non public reports/, 'alert contains public report'; + like $email->body, qr/Alert\s+test\s+for\s+non\s+public\s+reports/, 'alert contains public report'; $mech->delete_user( $user1 ); $mech->delete_user( $user2 ); diff --git a/t/app/controller/around.t b/t/app/controller/around.t index e1c76ff9f..d973543ce 100644 --- a/t/app/controller/around.t +++ b/t/app/controller/around.t @@ -66,6 +66,11 @@ foreach my $test ( latitude => '51.50101', longitude => '-0.141587', }, + { + pc => 'TQ 388 773', + latitude => '51.478074', + longitude => '-0.001966', + }, ) { subtest "check lat/lng for '$test->{pc}'" => sub { diff --git a/t/app/controller/index.t b/t/app/controller/index.t index 86d5e2d8c..462b21064 100644 --- a/t/app/controller/index.t +++ b/t/app/controller/index.t @@ -57,18 +57,21 @@ subtest "does pc, (x,y), (e,n) or (lat,lon) go to /around" => sub { $mech->delete_problems_for_council( 2651 ); +my $problem_rs = FixMyStreet::App->model('DB::Problem'); +my $num = $problem_rs->count; + my @edinburgh_problems = $mech->create_problems_for_council(5, 2651, 'Front page'); is scalar @edinburgh_problems, 5, 'correct number of edinburgh problems created'; -$mech->get_ok('/'); +$mech->get_ok('/report/' . $edinburgh_problems[2]->id); $mech->content_contains('Front page Test 3 for 2651', 'problem to be marked non public visible'); -$mech->content_contains('5</big> reports recently', 'number of recent problems correct'); +is $problem_rs->count, $num+5; my $private = $edinburgh_problems[2]; ok $private->update( { non_public => 1 } ), 'problem marked non public'; -$mech->get_ok('/'); -$mech->content_lacks('Front page Test 3 for 2651', 'non public problem is not visible'); -$mech->content_contains('5</big> reports recently', 'non public problems listed in recent problems stats'); +ok $mech->get('/report/' . $edinburgh_problems[2]->id); +is $mech->res->code, 403, 'page forbidden'; +is $problem_rs->count, $num+5; done_testing(); diff --git a/t/app/controller/questionnaire.t b/t/app/controller/questionnaire.t index 3475307fb..3a6a3d6ad 100644 --- a/t/app/controller/questionnaire.t +++ b/t/app/controller/questionnaire.t @@ -190,6 +190,25 @@ foreach my $test ( # update => 'Dummy', Error for not setting this tested below }, }, + { + desc => 'Closed report, said fixed, reported before, no update, no further questionnaire', + problem_state => 'closed', + fields => { + been_fixed => 'Yes', + reported => 'Yes', + another => 'No', + }, + }, + { + desc => 'Closed report, said not fixed, reported before, no update, no further questionnaire', + problem_state => 'closed', + fields => { + been_fixed => 'No', + reported => 'Yes', + another => 'No', + }, + lastupdate_static => 1, + }, ) { subtest $test->{desc} => sub { $report->state ( $test->{problem_state} ); @@ -224,7 +243,8 @@ foreach my $test ( $result = 'fixed' if $test->{fields}{been_fixed} eq 'Yes' && $test->{problem_state} eq 'fixed'; - $result = 'confirmed' if $test->{fields}{been_fixed} eq 'No'; + $result = 'confirmed' if $test->{fields}{been_fixed} eq 'No' && $test->{problem_state} ne 'closed'; + $result = 'closed' if $test->{fields}{been_fixed} eq 'No' && $test->{problem_state} eq 'closed'; $result = 'unknown' if $test->{fields}{been_fixed} eq 'Unknown'; my $another = 0; @@ -234,10 +254,12 @@ foreach my $test ( $mech->content_like( qr/<title>[^<]*Questionnaire/m ); $mech->content_contains( 'glad to hear it’s been fixed' ) if $result =~ /fixed/; + $mech->content_lacks( 'glad to hear it’s been fixed' ) + if $result !~ /fixed/; $mech->content_contains( 'get some more information about the status of your problem' ) if $result eq 'unknown'; $mech->content_contains( "sorry to hear that" ) - if $result eq 'confirmed'; + if $result eq 'confirmed' || $result eq 'closed'; # Check the database has the right information $report->discard_changes; diff --git a/t/app/controller/report_interest_count.t b/t/app/controller/report_interest_count.t new file mode 100644 index 000000000..dd44a83d4 --- /dev/null +++ b/t/app/controller/report_interest_count.t @@ -0,0 +1,143 @@ +use strict; +use warnings; +use Test::More; + +use FixMyStreet::TestMech; +use Web::Scraper; +use Path::Class; +use DateTime; + +my $mech = FixMyStreet::TestMech->new; + +# create a test user and report +$mech->delete_user('test@example.com'); +my $user = + FixMyStreet::App->model('DB::User') + ->find_or_create( { email => 'test@example.com', name => 'Test User' } ); +ok $user, "created test user"; + +my $user2 = + FixMyStreet::App->model('DB::User') + ->find_or_create( { email => 'test2@example.com', name => 'Other User' } ); +ok $user2, "created test user"; + +my $dt = DateTime->new( + year => 2011, + month => 04, + day => 16, + hour => 15, + minute => 47, + second => 23 +); + +my $report = FixMyStreet::App->model('DB::Problem')->find_or_create( + { + postcode => 'SW1A 1AA', + council => '2504', + areas => ',105255,11806,11828,2247,2504,', + category => 'Other', + title => 'Test 2', + detail => 'Test 2 Detail', + used_map => 't', + name => 'Test User', + anonymous => 'f', + state => 'confirmed', + confirmed => $dt->ymd . ' ' . $dt->hms, + lang => 'en-gb', + service => '', + cobrand => 'default', + cobrand_data => '', + send_questionnaire => 't', + latitude => '51.5016605453401', + longitude => '-0.142497580865087', + user_id => $user->id, + } +); +my $report_id = $report->id; +ok $report, "created test report - $report_id"; + +SKIP: { + skip( "Need 'fixmybarangay' in ALLOWED_COBRANDS config", 29 ) + unless FixMyStreet::Cobrand->exists('fixmybarangay'); + for my $test ( + { + desc => 'if not from council then no supporter button', + from_council => 0, + support_string => 'No supporters', + }, + { + desc => 'from council user can increment supported count', + from_council => 2504, + support_string => 'No supporters', + updated_support => '1 supporter' + }, + { + desc => 'correct grammar for more than one supporter', + from_council => 2504, + support_string => '1 supporter', + updated_support => '2 supporters' + }, + ) { + subtest $test->{desc} => sub { + ok $mech->host('fixmybarangay.com'), 'changed to fixmybarangay'; + $mech->log_in_ok( $user->email ); + $user->from_council( $test->{from_council} ); + $user->update; + + $report->discard_changes; + $report->council( $test->{report_council} ); + $report->update; + + $mech->get_ok("/report/$report_id"); + $mech->content_contains( $test->{support_string} ); + + if ( $test->{from_council} ) { + $mech->content_contains('Add support'); + $mech->submit_form_ok( { form_number => 1 } ); + + is $mech->uri, "http://fixmybarangay.com/report/$report_id", 'add support redirects to report page'; + + $mech->content_contains($test->{updated_support}); + } else { + $mech->content_lacks( 'Add support' ); + } + }; + } + + subtest 'check non council user cannot increment support count' => sub { + ok $mech->host('fixmybarangay.com'), 'changed to fixmybarangay'; + $report->discard_changes; + $report->interest_count(1); + ok $report->update(), 'updated interest count'; + + $report->discard_changes; + is $report->interest_count, 1, 'correct interest count'; + + $mech->get_ok("/report/$report_id"); + $mech->content_contains( '1 supporter' ); + + $mech->post_ok("/report/support", { id => $report_id } ); + + is $mech->uri, "http://fixmybarangay.com/report/$report_id", 'add support redirects to report page'; + + $mech->content_contains( '1 supporter' ); + }; +}; + +subtest 'check support details not shown if not enabled in cobrand' => sub { + ok $mech->host('fixmystreet.com'), 'changed to fixmystreet'; + + $report->interest_count(1); + ok $report->update, 'updated interest count'; + + $mech->get_ok("/report/$report_id"); + $mech->content_lacks( '1 supporter' ); +}; + +$report->discard_changes; +$report->council( 2504 ); +$report->update; + +# tidy up +$mech->delete_user('test@example.com'); +done_testing(); diff --git a/t/app/controller/report_new.t b/t/app/controller/report_new.t index 2e7e60f75..77afb071c 100644 --- a/t/app/controller/report_new.t +++ b/t/app/controller/report_new.t @@ -1028,6 +1028,53 @@ for my $test ( }; } +subtest 'user title not reset if no user title in submission' => sub { + $mech->log_out_ok; + $mech->host( 'http://fixmystreet.com' ); + + my $user = $mech->log_in_ok( 'userwithtitle@example.com' ); + + ok $user->update( + { + name => 'Has Title', + phone => '0789 654321', + title => 'MR', + } + ), + "set users details"; + + + my $submission_fields = { + title => "Test Report", + detail => 'Test report details.', + photo => '', + name => 'Has Title', + may_show_name => '1', + phone => '07903 123 456', + category => 'Trees', + }; + + $mech->get_ok('/'); + $mech->submit_form_ok( { with_fields => { pc => 'EH99 1SP', } }, + "submit location" ); + $mech->follow_link_ok( + { text_regex => qr/skip this step/i, }, + "follow 'skip this step' link" + ); + + my $fields = $mech->visible_form_values('mapSkippedForm'); + ok !exists( $fields->{fms_extra_title} ), 'user title field not displayed'; + + $mech->submit_form_ok( { with_fields => $submission_fields }, + "submit good details" ); + + $user->discard_changes; + my $report = $user->problems->first; + ok $report, "Found report"; + is $report->title, "Test Report", "Report title correct"; + is $user->title, 'MR', 'User title unchanged'; +}; + SKIP: { skip( "Need 'lichfielddc' in ALLOWED_COBRANDS config", 100 ) unless FixMyStreet::Cobrand->exists('lichfielddc'); diff --git a/t/app/model/alert_type.t b/t/app/model/alert_type.t index 7df4c44c0..c592e9d3f 100644 --- a/t/app/model/alert_type.t +++ b/t/app/model/alert_type.t @@ -22,6 +22,10 @@ my $user2 = ->find_or_create( { email => 'commenter@example.com', name => 'Commenter' } ); ok $user2, "created comment user"; +my $user3 = + FixMyStreet::App->model('DB::User') + ->find_or_create( { email => 'bystander@example.com', name => 'Bystander' } ); +ok $user3, "created bystander"; my $dt = DateTime->new( year => 2011, @@ -96,6 +100,16 @@ my $alert = FixMyStreet::App->model('DB::Alert')->find_or_create( } ); +my $alert3 = FixMyStreet::App->model('DB::Alert')->find_or_create( + { + user => $user3, + parameter => $report_id, + alert_type => 'new_updates', + whensubscribed => $dt->ymd . ' ' . $dt->hms, + confirmed => 1, + } +); + for my $test ( { state => 'closed', @@ -115,7 +129,7 @@ for my $test ( my $sent = FixMyStreet::App->model('DB::AlertSent')->search( { - alert_id => $alert->id, + alert_id => [ $alert->id, $alert3->id ], parameter => $comment->id, } )->delete; @@ -125,18 +139,25 @@ for my $test ( FixMyStreet::App->model('DB::AlertType')->email_alerts(); - $mech->email_count_is( 1 ); - my $email = $mech->get_email; + $mech->email_count_is( 2 ); + my @emails = $mech->get_email; my $msg = $test->{msg}; - my $body = $email->body; - - like $body, qr/$msg/, 'email says problem is ' . $test->{state}; - like $body, qr{report/$report_id}, 'contains problem url'; - like $body, qr/This is some update text/, 'contains update text'; - unlike $body, qr/This is other update text/, 'does not contains other update text'; + for my $email (@emails) { + my $body = $email->body; + my $to = $email->header('To'); + + like $body, qr/$msg/, 'email says problem is ' . $test->{state}; + if ($to eq $user->email) { + like $body, qr{/M/}, 'contains problem login url'; + } elsif ($to eq $user3->email) { + like $body, qr{/report/$report_id}, 'contains problem url'; + } + like $body, qr/This is some update text/, 'contains update text'; + unlike $body, qr/This is other update text/, 'does not contains other update text'; - my $comments = $body =~ s/(------)//gs; - is $comments, 1, 'only 1 update'; + my $comments = $body =~ s/(------)//gs; + is $comments, 1, 'only 1 update'; + } }; } @@ -166,7 +187,6 @@ subtest "correct text for title after URL" => sub { )->delete; FixMyStreet::App->model('DB::AlertType')->email_alerts(); - $mech->email_count_is( 1 ); my $email = $mech->get_email; (my $title = $report->title) =~ s/ /\\s+/; my $body = $email->body; @@ -300,7 +320,6 @@ foreach my $test ( FixMyStreet::App->model('DB::AlertType')->email_alerts(); - $mech->email_count_is( 1 ); my $email = $mech->get_email; my $body = $email->body; @@ -406,7 +425,6 @@ subtest "check alerts from cobrand send main site url for alerts for different c FixMyStreet::App->model('DB::AlertType')->email_alerts(); - $mech->email_count_is( 1 ); my $email = $mech->get_email; my $body = $email->body; @@ -444,7 +462,6 @@ subtest "check local alerts from cobrand send main site url for alerts for diffe FixMyStreet::App->model('DB::AlertType')->email_alerts(); - $mech->email_count_is( 1 ); my $email = $mech->get_email; my $body = $email->body; diff --git a/t/app/model/problem.t b/t/app/model/problem.t index 8aabce4f7..9aa52c3cf 100644 --- a/t/app/model/problem.t +++ b/t/app/model/problem.t @@ -483,6 +483,10 @@ foreach my $test ( { }, ) { subtest $test->{ desc } => sub { + if ( $test->{cobrand} && $test->{cobrand} =~ /lichfielddc/ && !FixMyStreet::Cobrand->exists('lichfielddc') ) { + plan skip_all => 'Skipping Lichfield tests without Lichfield cobrand'; + } + $mech->clear_emails_ok; FixMyStreet::App->model('DB::Problem')->search( @@ -491,10 +495,6 @@ foreach my $test ( { } )->update( { whensent => \'ms_current_timestamp()' } ); - if ( $test->{cobrand} && $test->{cobrand} =~ /lichfielddc/ && !FixMyStreet::Cobrand->exists('lichfielddc') ) { - plan skip_all => 'Skipping Lichfield tests without Lichfield cobrand'; - } - $problem->discard_changes; $problem->update( { council => $test->{ council }, diff --git a/t/cobrand/councils.t b/t/cobrand/councils.t new file mode 100644 index 000000000..8fb10cfbe --- /dev/null +++ b/t/cobrand/councils.t @@ -0,0 +1,18 @@ +use strict; +use warnings; +use Test::More; + +use FixMyStreet::TestMech; +my $mech = FixMyStreet::TestMech->new; + +foreach my $council (qw/southampton reading bromley/) { + SKIP: { + skip( "Need '$council' in ALLOWED_COBRANDS config", 3 ) + unless FixMyStreet::Cobrand->exists($council); + ok $mech->host("$council.fixmystreet.com"), "change host to $council"; + $mech->get_ok('/'); + $mech->content_like( qr/$council/i ); + } +} + +done_testing(); diff --git a/t/cobrand/get_council_sender.t b/t/cobrand/get_council_sender.t index 9004a47f5..e61f36370 100644 --- a/t/cobrand/get_council_sender.t +++ b/t/cobrand/get_council_sender.t @@ -13,8 +13,8 @@ mySociety::Locale::gettext_domain( 'FixMyStreet' ); my $c = FixMyStreet::Cobrand::FixMyStreet->new(); -is $c->get_council_sender( '1000', { type => 'DIS' } ), 'Email', 'defaults to email'; -is $c->get_council_sender( '1000', { type => 'LBO' } ), 'London', 'returns london report it if London borough'; +is_deeply $c->get_council_sender( '1000', { type => 'DIS' } ), { method => 'Email' }, 'defaults to email'; +is_deeply $c->get_council_sender( '1000', { type => 'LBO' } ), { method=> 'London' }, 'returns london report it if London borough'; my $conf = FixMyStreet::App->model('DB::Open311Conf')->find_or_create( area_id => 1000, @@ -22,8 +22,8 @@ my $conf = FixMyStreet::App->model('DB::Open311Conf')->find_or_create( send_method => 'TestMethod' ); -is $c->get_council_sender( '1000', { type => 'LBO' } ), 'TestMethod', 'uses send_method in preference to London'; -is $c->get_council_sender( '1000', { type => 'DIS' } ), 'TestMethod', 'uses send_method in preference to Email'; +is $c->get_council_sender( '1000', { type => 'LBO' } )->{ method }, 'TestMethod', 'uses send_method in preference to London'; +is $c->get_council_sender( '1000', { type => 'DIS' } )->{ method }, 'TestMethod', 'uses send_method in preference to Email'; $conf->delete; @@ -7,6 +7,7 @@ use FixMyStreet; use mySociety::Locale; use Encode; use Data::Dumper; +use HTTP::Headers; use Sort::Key qw(keysort); use POSIX 'strcoll'; local $Data::Dumper::Sortkeys = 1; @@ -18,6 +19,16 @@ die "You need to run 'commonlib/bin/gettext-makemo --quiet FixMyStreet' " unless -e FixMyStreet->path_to( 'locale/cy_GB.UTF-8/LC_MESSAGES/FixMyStreet-EmptyHomes.mo'); +# Test the language negotiation works +my $lang = mySociety::Locale::negotiate_language( + 'en-gb,English,en_GB|cy,Cymraeg,cy_GB|es,Spanish,es_ES', + undef, + HTTP::Headers->new( + Accept_Language => 'es,en-gb;q=0.6,en;q=0.4' + ) +); +is $lang, 'es', 'Language negotiation works okay'; + # Example strings my $english = "Please enter a valid email"; my $welsh = "Cofnodwch gyfeiriad e-bost dilys"; diff --git a/t/open311.t b/t/open311.t index 15a3f2646..2371c53bc 100644 --- a/t/open311.t +++ b/t/open311.t @@ -37,9 +37,10 @@ my $p = FixMyStreet::App->model('DB::Problem')->new( { title => 'title', detail => 'detail', user => $u, + id => 1, } ); -my $expected_error = qr{.*request failed: 500 Can.t connect to 192.168.50.1:80 \([^)]*\).*}; +my $expected_error = qr{Failed to submit problem 1 over Open311}ism; warning_like {$o2->send_service_request( $p, { url => 'http://example.com/' }, 1 )} $expected_error, 'warning generated on failed call'; |