diff options
Diffstat (limited to 't/app')
-rw-r--r-- | t/app/controller/about.t | 2 | ||||
-rw-r--r-- | t/app/controller/admin.t | 49 | ||||
-rw-r--r-- | t/app/controller/alert_new.t | 32 | ||||
-rw-r--r-- | t/app/controller/questionnaire.t | 132 | ||||
-rw-r--r-- | t/app/controller/report_import.t | 2 | ||||
-rw-r--r-- | t/app/controller/report_new.t | 228 | ||||
-rw-r--r-- | t/app/controller/report_updates.t | 20 | ||||
-rw-r--r-- | t/app/controller/reports.t | 4 | ||||
-rw-r--r-- | t/app/model/problem.t | 130 | ||||
-rw-r--r-- | t/app/uri_for.t | 57 |
10 files changed, 517 insertions, 139 deletions
diff --git a/t/app/controller/about.t b/t/app/controller/about.t index ea7b1af20..4e49cdac9 100644 --- a/t/app/controller/about.t +++ b/t/app/controller/about.t @@ -13,7 +13,7 @@ $mech->content_contains('html class="no-js" lang="en-gb"'); SKIP: { skip( "Need 'emptyhomes' in ALLOWED_COBRANDS config", 8 ) - unless FixMyStreet::App->config->{ALLOWED_COBRANDS} =~ m{emptyhomes}; + unless FixMyStreet::Cobrand->exists('emptyhomes'); # check that geting the page as EHA produces a different page ok $mech->host("reportemptyhomes.co.uk"), 'change host to reportemptyhomes'; diff --git a/t/app/controller/admin.t b/t/app/controller/admin.t index d8a1c24a1..09d99cfdf 100644 --- a/t/app/controller/admin.t +++ b/t/app/controller/admin.t @@ -105,34 +105,39 @@ subtest 'check summary counts' => sub { $mech->content_contains( "$q_count questionnaires sent" ); - ok $mech->host('barnet.fixmystreet.com'); + SKIP: { + skip( "Need 'barnet' in ALLOWED_COBRANDS config", 7 ) + unless FixMyStreet::Cobrand->exists('barnet'); - $mech->get_ok('/admin'); - $mech->title_like(qr/Summary/); + ok $mech->host('barnet.fixmystreet.com'); - my ($num_live) = $mech->content =~ /(\d+)<\/strong> live problems/; - my ($num_alerts) = $mech->content =~ /(\d+) confirmed alerts/; - my ($num_qs) = $mech->content =~ /(\d+) questionnaires sent/; + $mech->get_ok('/admin'); + $mech->title_like(qr/Summary/); - $report->council(2489); - $report->cobrand('barnet'); - $report->update; + my ($num_live) = $mech->content =~ /(\d+)<\/strong> live problems/; + my ($num_alerts) = $mech->content =~ /(\d+) confirmed alerts/; + my ($num_qs) = $mech->content =~ /(\d+) questionnaires sent/; - $alert->cobrand('barnet'); - $alert->update; + $report->council(2489); + $report->cobrand('barnet'); + $report->update; - $mech->get_ok('/admin'); + $alert->cobrand('barnet'); + $alert->update; - $mech->content_contains( ($num_live+1) . "</strong> live problems" ); - $mech->content_contains( ($num_alerts+1) . " confirmed alerts" ); - $mech->content_contains( ($num_qs+1) . " questionnaires sent" ); + $mech->get_ok('/admin'); - $report->council(2504); - $report->cobrand(''); - $report->update; + $mech->content_contains( ($num_live+1) . "</strong> live problems" ); + $mech->content_contains( ($num_alerts+1) . " confirmed alerts" ); + $mech->content_contains( ($num_qs+1) . " questionnaires sent" ); + + $report->council(2504); + $report->cobrand(''); + $report->update; - $alert->cobrand(''); - $alert->update; + $alert->cobrand(''); + $alert->update; + } FixMyStreet::App->model('DB::Problem')->search( { council => 1 } )->update( { council => 2489 } ); ok $mech->host('fixmystreet.com'); @@ -222,6 +227,8 @@ subtest 'check open311 configuring' => sub { api_key => 'api key', endpoint => 'http://example.com/open311', jurisdiction => 'mySociety', + send_comments => 0, + send_method => 'Open311', } } ); @@ -244,6 +251,8 @@ subtest 'check open311 configuring' => sub { api_key => 'new api key', endpoint => 'http://example.org/open311', jurisdiction => 'open311', + send_comments => 0, + send_method => 'Open311', } } ); diff --git a/t/app/controller/alert_new.t b/t/app/controller/alert_new.t index 3a4c2ef81..7ba887824 100644 --- a/t/app/controller/alert_new.t +++ b/t/app/controller/alert_new.t @@ -142,25 +142,18 @@ foreach my $test ( } foreach my $test ( - { - email => 'test-new@example.com', - type => 'area', - content => 'your alert will not be activated', - email_text => 'confirm the alert', - uri => -'/alert/subscribe?type=local&rznvy=test-new@example.com&feed=area:1000:A_Location', - param1 => 1000 - } + { exist => 0 }, + { exist => 1 }, ) { - subtest "use existing unlogged in user in a alert" => sub { + subtest "use existing unlogged in user in a alert ($test->{exist})" => sub { $mech->log_out_ok(); - my $type = $test->{type} . '_problems'; + my $type = 'area_problems'; my $user = FixMyStreet::App->model('DB::User') - ->find_or_create( { email => $test->{email} } ); + ->find_or_create( { email => 'test-new@example.com' } ); my $alert = FixMyStreet::App->model('DB::Alert')->find( { @@ -169,24 +162,26 @@ foreach my $test ( } ); # clear existing data so we can be sure we're creating it - ok $alert->delete() if $alert; + ok $alert->delete() if $alert && !$test->{exist}; - $mech->get_ok( $test->{uri} ); + $mech->get_ok( '/alert/subscribe?type=local&rznvy=test-new@example.com&feed=area:1000:A_Location' ); $alert = FixMyStreet::App->model('DB::Alert')->find( { user => $user, alert_type => $type, - parameter => $test->{param1}, - parameter2 => $test->{param2}, - confirmed => 0, + parameter => 1000, + parameter2 => undef, + confirmed => $test->{exist}, } ); $mech->content_contains( 'Now check your email' ); + $alert->confirm(); ok $alert, 'New alert created with existing user'; - $mech->delete_user($user); + + $mech->delete_user($user) if $test->{exist}; }; } @@ -445,6 +440,7 @@ subtest "Test normal alert signups and that alerts are sent" => sub { ok $update, "created test update - $update_id"; FixMyStreet::App->model('DB::AlertType')->email_alerts(); + # TODO Note the below will fail if the db has an existing alert that matches $mech->email_count_is(3); my @emails = $mech->get_email; my $count; diff --git a/t/app/controller/questionnaire.t b/t/app/controller/questionnaire.t index 0e2a71184..2d4fdb711 100644 --- a/t/app/controller/questionnaire.t +++ b/t/app/controller/questionnaire.t @@ -322,67 +322,79 @@ for my $test ( }; } -# EHA extra checking -ok $mech->host("reportemptyhomes.com"), 'change host to reportemptyhomes'; - -# Reset, and all the questionaire sending function - FIXME should it detect site itself somehow? -$report->send_questionnaire( 1 ); -$report->update; -$questionnaire->delete; -FixMyStreet::App->model('DB::Questionnaire')->send_questionnaires( { - site => 'emptyhomes' -} ); -$email = $mech->get_email; -ok $email, "got an email"; -$mech->clear_emails_ok; - -like $email->body, qr/fill in this short questionnaire/i, "got questionnaire email"; -($token) = $email->body =~ m{http://.*?/Q/(\S+)}; -ok $token, "extracted questionnaire token '$token'"; - -$mech->get_ok("/Q/" . $token); -$mech->content_contains( 'should have reported what they have done' ); - -# Test already answered the ever reported question, so not shown again -$dt = $dt->add( weeks => 4 ); -my $questionnaire2 = FixMyStreet::App->model('DB::Questionnaire')->find_or_create( - { - problem_id => $report->id, - whensent => $dt->ymd . ' ' . $dt->hms, - ever_reported => 1, - } -); -ok $questionnaire2, 'added another questionnaire'; -ok $mech->host("fixmystreet.com"), 'change host to fixmystreet'; -$mech->get_ok("/Q/" . $token); -$mech->title_like( qr/Questionnaire/ ); -$mech->content_contains( 'Has this problem been fixed?' ); -$mech->content_lacks( 'ever reported' ); - -# EHA extra checking -ok $mech->host("reportemptyhomes.com"), 'change host to reportemptyhomes'; -$mech->get_ok("/Q/" . $token); -$mech->content_contains( 'made a lot of progress' ); - -$token = FixMyStreet::App->model("DB::Token")->find( { scope => 'questionnaire', token => $token } ); -ok $token, 'found token for questionnaire'; -$questionnaire = FixMyStreet::App->model('DB::Questionnaire')->find( { id => $token->data } ); -ok $questionnaire, 'found questionnaire'; - -# I18N Unicode extra testing using FiksGataMi -$report->send_questionnaire( 1 ); -$report->cobrand( 'fiksgatami' ); -$report->update; -$questionnaire->delete; -$questionnaire2->delete; -FixMyStreet::App->model('DB::Questionnaire')->send_questionnaires( { site => 'fixmystreet' } ); # It's either fixmystreet or emptyhomes -$email = $mech->get_email; -ok $email, "got an email"; -$mech->clear_emails_ok; +SKIP: { + skip( "Need 'emptyhomes' in ALLOWED_COBRANDS config", 18 ) + unless FixMyStreet::Cobrand->exists('emptyhomes'); + + # EHA extra checking + ok $mech->host("reportemptyhomes.com"), 'change host to reportemptyhomes'; + + # Reset, and all the questionaire sending function - FIXME should it detect site itself somehow? + $report->send_questionnaire( 1 ); + $report->update; + $questionnaire->delete; + + FixMyStreet::App->model('DB::Questionnaire')->send_questionnaires( { + site => 'emptyhomes' + } ); + $email = $mech->get_email; + ok $email, "got an email"; + $mech->clear_emails_ok; + + like $email->body, qr/fill in this short questionnaire/i, "got questionnaire email"; + ($token) = $email->body =~ m{http://.*?/Q/(\S+)}; + ok $token, "extracted questionnaire token '$token'"; + + $mech->get_ok("/Q/" . $token); + $mech->content_contains( 'should have reported what they have done' ); + + # Test already answered the ever reported question, so not shown again + $dt = $dt->add( weeks => 4 ); + my $questionnaire2 = FixMyStreet::App->model('DB::Questionnaire')->find_or_create( + { + problem_id => $report->id, + whensent => $dt->ymd . ' ' . $dt->hms, + ever_reported => 1, + } + ); + ok $questionnaire2, 'added another questionnaire'; + ok $mech->host("fixmystreet.com"), 'change host to fixmystreet'; + $mech->get_ok("/Q/" . $token); + $mech->title_like( qr/Questionnaire/ ); + $mech->content_contains( 'Has this problem been fixed?' ); + $mech->content_lacks( 'ever reported' ); + + # EHA extra checking + ok $mech->host("reportemptyhomes.com"), 'change host to reportemptyhomes'; + $mech->get_ok("/Q/" . $token); + $mech->content_contains( 'made a lot of progress' ); + + $token = FixMyStreet::App->model("DB::Token")->find( { scope => 'questionnaire', token => $token } ); + ok $token, 'found token for questionnaire'; + $questionnaire = FixMyStreet::App->model('DB::Questionnaire')->find( { id => $token->data } ); + ok $questionnaire, 'found questionnaire'; + + $questionnaire2->delete; +} -like $email->body, qr/Testing =96 Detail/, 'email contains encoded character from user'; -like $email->body, qr/sak p=E5 FiksGataMi/, 'email contains encoded character from template'; -is $email->header('Content-Type'), 'text/plain; charset="windows-1252"', 'email is in right encoding'; +SKIP: { + skip( "Need 'fiksgatami' in ALLOWED_COBRANDS config", 5 ) + unless FixMyStreet::Cobrand->exists('fiksgatami'); + + # I18N Unicode extra testing using FiksGataMi + $report->send_questionnaire( 1 ); + $report->cobrand( 'fiksgatami' ); + $report->update; + $questionnaire->delete; + FixMyStreet::App->model('DB::Questionnaire')->send_questionnaires( { site => 'fixmystreet' } ); # It's either fixmystreet or emptyhomes + $email = $mech->get_email; + ok $email, "got an email"; + $mech->clear_emails_ok; + + like $email->body, qr/Testing =96 Detail/, 'email contains encoded character from user'; + like $email->body, qr/sak p=E5 FiksGataMi/, 'email contains encoded character from template'; + is $email->header('Content-Type'), 'text/plain; charset="windows-1252"', 'email is in right encoding'; +} $mech->delete_user('test@example.com'); done_testing(); diff --git a/t/app/controller/report_import.t b/t/app/controller/report_import.t index 934bf0346..eb686b44e 100644 --- a/t/app/controller/report_import.t +++ b/t/app/controller/report_import.t @@ -266,7 +266,7 @@ subtest "Submit a correct entry (with location) to cobrand" => sub { SKIP: { skip( "Need 'fiksgatami' in ALLOWED_COBRANDS config", 20 ) - unless FixMyStreet::App->config->{ALLOWED_COBRANDS} =~ m{fiksgatami}; + unless FixMyStreet::Cobrand->exists('fiksgatami'); mySociety::MaPit::configure('http://mapit.nuug.no/'); ok $mech->host("fiksgatami.no"), 'change host to fiksgatami'; diff --git a/t/app/controller/report_new.t b/t/app/controller/report_new.t index 625c7531f..29fb650e5 100644 --- a/t/app/controller/report_new.t +++ b/t/app/controller/report_new.t @@ -6,10 +6,14 @@ use utf8; use FixMyStreet::TestMech; use Web::Scraper; +use Path::Class; my $mech = FixMyStreet::TestMech->new; $mech->get_ok('/report/new'); +my $sample_file = file(__FILE__)->parent->file("sample.jpg")->stringify; +ok -e $sample_file, "sample file $sample_file exists"; + subtest "test that bare requests to /report/new get redirected" => sub { $mech->get_ok('/report/new'); @@ -48,9 +52,23 @@ my $contact3 = FixMyStreet::App->model('DB::Contact')->find_or_create( { category => 'Trees', email => 'trees@example.com', } ); +my $contact4 = FixMyStreet::App->model('DB::Contact')->find_or_create( { + %contact_params, + area_id => 2482, # Bromley + category => 'Trees', + email => 'trees@example.com', +} ); +my $contact5 = FixMyStreet::App->model('DB::Contact')->find_or_create( { + %contact_params, + area_id => 2651, # Edinburgh + category => 'Trees', + email => 'trees@example.com', +} ); ok $contact1, "created test contact 1"; ok $contact2, "created test contact 2"; ok $contact3, "created test contact 3"; +ok $contact4, "created test contact 4"; +ok $contact5, "created test contact 5"; # test that the various bit of form get filled in and errors correctly # generated. @@ -282,6 +300,69 @@ foreach my $test ( }, errors => [ 'Please enter a subject', 'Please enter some details', ], }, + { + msg => 'non-photo upload gives error', + pc => 'SW1A 1AA', + fields => { + title => 'Title', + detail => 'Detail', + photo => [ [ undef, 'bad.txt', Content => 'This is not a JPEG', Content_Type => 'text/plain' ], 1 ], + name => 'Bob Jones', + may_show_name => '1', + email => 'bob@example.com', + phone => '', + category => 'Street lighting', + password_sign_in => '', + password_register => '', + remember_me => undef, + }, + changes => { + photo => '', + }, + errors => [ "Please upload a JPEG image only" ], + }, + { + msg => 'bad photo upload gives error', + pc => 'SW1A 1AA', + fields => { + title => 'Title', + detail => 'Detail', + photo => [ [ undef, 'fake.jpeg', Content => 'This is not a JPEG', Content_Type => 'image/jpeg' ], 1 ], + name => 'Bob Jones', + may_show_name => '1', + email => 'bob@example.com', + phone => '', + category => 'Street lighting', + password_sign_in => '', + password_register => '', + remember_me => undef, + }, + changes => { + photo => '', + }, + errors => [ "That image doesn't appear to have uploaded correctly (Please upload a JPEG image only ), please try again." ], + }, + { + msg => 'photo with octet-stream gets through okay', + pc => 'SW1A 1AA', + fields => { + title => '', + detail => 'Detail', + photo => [ [ $sample_file, undef, Content_Type => 'application/octet-stream' ], 1 ], + name => 'Bob Jones', + may_show_name => '1', + email => 'bob@example.com', + phone => '', + category => 'Street lighting', + password_sign_in => '', + password_register => '', + remember_me => undef, + }, + changes => { + photo => '', + }, + errors => [ "Please enter a subject" ], + }, ) { subtest "check form errors where $test->{msg}" => sub { @@ -293,7 +374,7 @@ foreach my $test ( is_deeply $mech->form_errors, [], "no errors for pc '$test->{pc}'"; # click through to the report page - $mech->follow_link_ok( { text => 'skip this step', }, + $mech->follow_link_ok( { text_regex => qr/skip this step/i, }, "follow 'skip this step' link" ); # submit the main form @@ -473,7 +554,7 @@ subtest "test password errors for a user who is signing in as they report" => su "submit location" ); # click through to the report page - $mech->follow_link_ok( { text => 'Skip this step', }, + $mech->follow_link_ok( { text_regex => qr/skip this step/i, }, "follow 'skip this step' link" ); $mech->submit_form_ok( @@ -520,7 +601,7 @@ subtest "test report creation for a user who is signing in as they report" => su "submit location" ); # click through to the report page - $mech->follow_link_ok( { text => 'Skip this step', }, + $mech->follow_link_ok( { text_regex => qr/skip this step/i, }, "follow 'skip this step' link" ); $mech->submit_form_ok( @@ -614,7 +695,7 @@ foreach my $test ( "submit location" ); # click through to the report page - $mech->follow_link_ok( { text => 'Skip this step', }, + $mech->follow_link_ok( { text_regex => qr/skip this step/i, }, "follow 'skip this step' link" ); # check that the fields are correctly prefilled @@ -717,7 +798,7 @@ subtest "check that a lat/lon off coast leads to /around" => sub { is $mech->uri->path, '/around', "redirected to '/around'"; is_deeply # - $mech->page_errors, + $mech->form_errors, [ 'That spot does not appear to be covered by a council. If you have' . ' tried to report an issue past the shoreline, for example, please' . ' specify the closest point on land.' ], # @@ -725,8 +806,145 @@ subtest "check that a lat/lon off coast leads to /around" => sub { }; +for my $test ( + { + desc => 'user title not set if not bromley problem', + host => 'http://www.fixmystreet.com', + postcode => 'EH99 1SP', + fms_extra_title => '', + extra => undef, + user_title => undef, + }, + { + desc => 'title shown for bromley problem on main site', + host => 'http://www.fixmystreet.com', + postcode => 'BR1 3UH', + fms_extra_title => 'MR', + extra => [ + { + name => 'fms_extra_title', + value => 'MR', + description => 'FMS_EXTRA_TITLE', + }, + ], + user_title => 'MR', + }, + { + desc => + 'title, first and last name shown for bromley problem on cobrand', + host => 'http://bromley.fixmystreet.com', + postcode => 'BR1 3UH', + first_name => 'Test', + last_name => 'User', + fms_extra_title => 'MR', + extra => [ + { + name => 'fms_extra_title', + value => 'MR', + description => 'FMS_EXTRA_TITLE', + }, + { + name => 'first_name', + value => 'Test', + description => 'FIRST_NAME', + }, + { + name => 'last_name', + value => 'User', + description => 'LAST_NAME', + }, + ], + user_title => 'MR', + }, + ) +{ + subtest $test->{desc} => sub { + $mech->host( $test->{host} ); + + $mech->log_out_ok; + $mech->clear_emails_ok; + + $mech->get_ok('/'); + $mech->submit_form_ok( { with_fields => { pc => $test->{postcode}, } }, + "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'); + if ( $test->{fms_extra_title} ) { + ok exists( $fields->{fms_extra_title} ), 'user title field displayed'; + } else { + ok !exists( $fields->{fms_extra_title} ), 'user title field not displayed'; + } + if ( $test->{first_name} ) { + ok exists( $fields->{first_name} ), 'first name field displayed'; + ok exists( $fields->{last_name} ), 'last name field displayed'; + ok !exists( $fields->{name} ), 'no name field displayed'; + } + else { + ok !exists( $fields->{first_name} ), + 'first name field not displayed'; + ok !exists( $fields->{last_name} ), 'last name field not displayed'; + ok exists( $fields->{name} ), 'name field displayed'; + } + + my $submission_fields = { + title => "Test Report", + detail => 'Test report details.', + photo => '', + email => 'firstlast@example.com', + may_show_name => '1', + phone => '07903 123 456', + category => 'Trees', + password_register => '', + }; + + $submission_fields->{fms_extra_title} = $test->{fms_extra_title} + if $test->{fms_extra_title}; + + if ( $test->{first_name} ) { + $submission_fields->{first_name} = $test->{first_name}; + $submission_fields->{last_name} = $test->{last_name}; + } + else { + $submission_fields->{name} = 'Test User'; + } + + $mech->submit_form_ok( { with_fields => $submission_fields }, + "submit good details" ); + + my $email = $mech->get_email; + ok $email, "got an email"; + like $email->body, qr/confirm the problem/i, "confirm the problem"; + + my ($url) = $email->body =~ m{(https?://\S+)}; + ok $url, "extracted confirm url '$url'"; + + # confirm token in order to update the user details + $mech->get_ok($url); + + my $user = + FixMyStreet::App->model('DB::User') + ->find( { email => 'firstlast@example.com' } ); + + my $report = $user->problems->first; + ok $report, "Found the report"; + my $extras = $report->extra; + is $user->title, $test->{'user_title'}, 'user title correct'; + is_deeply $extras, $test->{extra}, 'extra contains correct values'; + + $user->problems->delete; + $user->alerts->delete; + $user->delete; + }; +} + $contact1->delete; $contact2->delete; $contact3->delete; +$contact4->delete; +$contact5->delete; done_testing(); diff --git a/t/app/controller/report_updates.t b/t/app/controller/report_updates.t index 9c2b0861b..0337a881b 100644 --- a/t/app/controller/report_updates.t +++ b/t/app/controller/report_updates.t @@ -872,7 +872,11 @@ for my $test ( is_deeply $values, $test->{initial_values}, 'initial form values'; - is $mech->extract_problem_banner->{text}, $test->{initial_banner}, 'initial banner'; + if ( !defined( $test->{initial_banner} ) ) { + is $mech->extract_problem_banner->{text}, undef, 'initial banner'; + } else { + like $mech->extract_problem_banner->{text}, qr/@{[ $test->{initial_banner} ]}/i, 'initial banner'; + } $mech->submit_form_ok( { @@ -883,7 +887,11 @@ for my $test ( is $mech->uri->path, "/report/" . $report_id, "redirected to report page"; - is $mech->extract_problem_banner->{text}, $test->{endstate_banner}, 'submitted banner'; + if ( !defined( $test->{endstate_banner} ) ) { + is $mech->extract_problem_banner->{text}, undef, 'endstate banner'; + } else { + like $mech->extract_problem_banner->{text}, qr/@{[ $test->{endstate_banner} ]}/i, 'endstate banner'; + } $mech->email_count_is(0); @@ -1029,8 +1037,12 @@ foreach my $test ( is_deeply $values, $test->{initial_values}, 'initial form values'; - is $mech->extract_problem_banner->{text}, $test->{initial_banner}, - 'initial banner'; + if ( !defined( $test->{initial_banner} ) ) { + is $mech->extract_problem_banner->{text}, undef, 'initial banner'; + } else { + like $mech->extract_problem_banner->{text}, qr/@{[ $test->{initial_banner} ]}/i, + 'initial banner'; + } $mech->submit_form_ok( { with_fields => $test->{fields}, }, 'submit update' ); diff --git a/t/app/controller/reports.t b/t/app/controller/reports.t index 58803d778..801dbeddb 100644 --- a/t/app/controller/reports.t +++ b/t/app/controller/reports.t @@ -17,14 +17,14 @@ $mech->follow_link_ok( { text_regex => qr/Birmingham/ } ); SKIP: { skip( "Need 'emptyhomes' in ALLOWED_COBRANDS config", 8 ) - unless FixMyStreet::App->config->{ALLOWED_COBRANDS} =~ m{emptyhomes}; + unless FixMyStreet::Cobrand->exists('emptyhomes'); ok $mech->host("reportemptyhomes.com"), 'change host to reportemptyhomes'; $mech->get_ok('/reports'); # EHA lacks one column the others have $mech->content_lacks('state unknown'); skip( "Need 'fiksgatami' in ALLOWED_COBRANDS config", 8 ) - unless FixMyStreet::App->config->{ALLOWED_COBRANDS} =~ m{fiksgatami}; + unless FixMyStreet::Cobrand->exists('fiksgatami'); mySociety::MaPit::configure('http://mapit.nuug.no/'); ok $mech->host("fiksgatami.no"), 'change host to fiksgatami'; $mech->get_ok('/reports'); diff --git a/t/app/model/problem.t b/t/app/model/problem.t index 638e89200..a7415851b 100644 --- a/t/app/model/problem.t +++ b/t/app/model/problem.t @@ -7,6 +7,7 @@ use Test::More; use FixMyStreet; use FixMyStreet::App; +use FixMyStreet::TestMech; use mySociety::Locale; mySociety::Locale::gettext_domain('FixMyStreet'); @@ -16,8 +17,8 @@ my $problem_rs = FixMyStreet::App->model('DB::Problem'); my $problem = $problem_rs->new( { postcode => 'EH99 1SP', - latitude => 1, - longitude => 1, + latitude => '51.5016605453401', + longitude => '-0.142497580865087', areas => 1, title => '', detail => '', @@ -345,6 +346,131 @@ for my $test ( }; } +my $mech = FixMyStreet::TestMech->new(); + +FixMyStreet::App->model('DB::Contact')->find_or_create( + { + area_id => 2651, + category => 'potholes', + email => 'test@example.org', + confirmed => 1, + deleted => 0, + editor => 'test', + whenedited => \'ms_current_timestamp()', + note => '', + } +); + +FixMyStreet::App->model('DB::Contact')->find_or_create( + { + area_id => 2226, + category => 'potholes', + email => '2226@example.org', + confirmed => 1, + deleted => 0, + editor => 'test', + whenedited => \'ms_current_timestamp()', + note => '', + } +); + +FixMyStreet::App->model('DB::Contact')->find_or_create( + { + area_id => 2326, + category => 'potholes', + email => '2326@example.org', + confirmed => 1, + deleted => 0, + editor => 'test', + whenedited => \'ms_current_timestamp()', + note => '', + } +); + +foreach my $test ( { + desc => 'sends an email', + unset_whendef => 1, + email_count => 1, + email => 'system_user@example.com', + name => 'Andrew Smith', + dear => qr'Dear City of Edinburgh Council', + to => qr'City of Edinburgh Council', + council => 2651, + }, + { + desc => 'no email sent if no unsent problems', + unset_whendef => 0, + email_count => 0, + email => 'system_user@example.com', + name => 'Andrew Smith', + council => 2651, + }, + { + desc => 'email to two tier council', + unset_whendef => 1, + email_count => 1, + email => 'system_user@example.com', + name => 'Andrew Smith', + to => qr'Gloucestershire County Council.*Cheltenham Borough Council', + dear => qr'Dear Gloucestershire County Council and Cheltenham Borough', + council => '2226,2326', + multiple => 1, + }, + { + desc => 'email to two tier council with one missing details', + unset_whendef => 1, + email_count => 1, + email => 'system_user@example.com', + name => 'Andrew Smith', + to => qr'Gloucestershire County Council', + dear => qr'Dear Gloucestershire County Council,', + council => '2226|2649', + missing => qr'problem might be the responsibility of Fife.*Council'ms, + }, +) { + subtest $test->{ desc } => sub { + $mech->clear_emails_ok; + + FixMyStreet::App->model('DB::Problem')->search( + { + whensent => undef + } + )->update( { whensent => \'ms_current_timestamp()' } ); + + $problem->discard_changes; + $problem->update( { + council => $test->{ council }, + state => 'confirmed', + confirmed => \'ms_current_timestamp()', + whensent => $test->{ unset_whendef } ? undef : \'ms_current_timestamp()', + category => 'potholes', + name => $test->{ name }, + } ); + + FixMyStreet::App->model('DB::Problem')->send_reports(); + + $mech->email_count_is( $test->{ email_count } ); + if ( $test->{ email_count } ) { + my $email = $mech->get_email; + like $email->header('To'), $test->{ to }, 'to line looks correct'; + is $email->header('From'), sprintf('"%s" <%s>', $test->{ name }, $test->{ email } ), 'from line looks correct'; + like $email->header('Subject'), qr/A Title/, 'subject line looks correct'; + like $email->body, qr/A user of FixMyStreet/, 'email body looks a bit like a report'; + like $email->body, qr/Subject: A Title/, 'more email body checking'; + like $email->body, $test->{ dear }, 'Salutation looks correct'; + + if ( $test->{multiple} ) { + like $email->body, qr/This email has been sent to several councils /, 'multiple council text correct'; + } elsif ( $test->{ missing } ) { + like $email->body, $test->{ missing }, 'missing council information correct'; + } + + $problem->discard_changes; + ok defined( $problem->whensent ), 'whensent set'; + } + }; +} + $problem->comments->delete; $problem->delete; $user->delete; diff --git a/t/app/uri_for.t b/t/app/uri_for.t index 51a6e8a0e..eecf30e32 100644 --- a/t/app/uri_for.t +++ b/t/app/uri_for.t @@ -78,31 +78,36 @@ 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' -); +SKIP: { + skip( "Need 'emptyhomes' in ALLOWED_COBRANDS config", 2 ) + unless FixMyStreet::Cobrand->exists('emptyhomes'); + + 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' + ); +} done_testing(); |