diff options
author | Matthew Somerville <matthew@mysociety.org> | 2013-02-01 15:28:08 +0000 |
---|---|---|
committer | Matthew Somerville <matthew@mysociety.org> | 2013-02-04 06:53:02 +0000 |
commit | 488a8f21a0c1bc2b9501c9d94d69db56cccd80ae (patch) | |
tree | 68becf501e9492466a80015e8ace9a7fb1557cfa /t/app/controller | |
parent | 3e0d12e8584d132b573f536ab5cd01e24241827b (diff) | |
parent | 28aa1dd7fb1c9bc93aa204afae67cf68fe36ee6b (diff) |
Merge remote branch 'origin/zurich'
Conflicts:
bin/open311-populate-service-list
bin/send-comments
bin/update-all-reports
conf/crontab.ugly
db/schema.sql
perllib/FixMyStreet/App/Controller/Admin.pm
perllib/FixMyStreet/App/Controller/Report/New.pm
perllib/FixMyStreet/App/Controller/Reports.pm
perllib/FixMyStreet/Cobrand/Default.pm
perllib/FixMyStreet/Cobrand/LichfieldDC.pm
perllib/FixMyStreet/DB/Result/Open311conf.pm
perllib/FixMyStreet/DB/Result/Problem.pm
perllib/FixMyStreet/DB/ResultSet/Problem.pm
perllib/FixMyStreet/SendReport.pm
perllib/FixMyStreet/SendReport/Email.pm
perllib/FixMyStreet/SendReport/Open311.pm
perllib/Open311/GetServiceRequestUpdates.pm
perllib/Open311/PopulateServiceList.pm
t/app/controller/report_new.t
t/app/controller/rss.t
templates/web/bromley/report/display.html
templates/web/default/admin/council_contacts.html
templates/web/default/common_header_tags.html
templates/web/default/dashboard/index.html
templates/web/default/front/stats.html
templates/web/default/report/_main.html
templates/web/default/report/update-form.html
templates/web/emptyhomes/index.html
templates/web/emptyhomes/report/display.html
templates/web/emptyhomes/report/new/councils_text_all.html
templates/web/emptyhomes/reports/body.html
templates/web/emptyhomes/reports/index.html
templates/web/fixmystreet/report/new/fill_in_details_form.html
templates/web/fixmystreet/report/update-form.html
web/cobrands/fixmystreet/fixmystreet.js
web/js/fixmystreet.js
Diffstat (limited to 't/app/controller')
-rw-r--r-- | t/app/controller/admin.t | 116 | ||||
-rw-r--r-- | t/app/controller/alert_new.t | 6 | ||||
-rw-r--r-- | t/app/controller/around.t | 2 | ||||
-rw-r--r-- | t/app/controller/dashboard.t | 14 | ||||
-rw-r--r-- | t/app/controller/index.t | 4 | ||||
-rw-r--r-- | t/app/controller/json.t | 8 | ||||
-rw-r--r-- | t/app/controller/questionnaire.t | 2 | ||||
-rw-r--r-- | t/app/controller/report_display.t | 114 | ||||
-rw-r--r-- | t/app/controller/report_interest_count.t | 40 | ||||
-rw-r--r-- | t/app/controller/report_new.t | 88 | ||||
-rw-r--r-- | t/app/controller/report_new_open311.t | 16 | ||||
-rw-r--r-- | t/app/controller/report_updates.t | 26 | ||||
-rw-r--r-- | t/app/controller/reports.t | 13 | ||||
-rw-r--r-- | t/app/controller/rss.t | 64 |
14 files changed, 365 insertions, 148 deletions
diff --git a/t/app/controller/admin.t b/t/app/controller/admin.t index 9ec15ec21..8963e417d 100644 --- a/t/app/controller/admin.t +++ b/t/app/controller/admin.t @@ -45,7 +45,7 @@ my $dt = DateTime->new( my $report = FixMyStreet::App->model('DB::Problem')->find_or_create( { postcode => 'SW1A 1AA', - council => '2504', + bodies_str => '2504', areas => ',105255,11806,11828,2247,2504,', category => 'Other', title => 'Report to Edit', @@ -84,7 +84,7 @@ subtest 'check summary counts' => sub { my $problem_count = $problems->count; $problems->update( { cobrand => '' } ); - FixMyStreet::App->model('DB::Problem')->search( { council => 2489 } )->update( { council => 1 } ); + FixMyStreet::App->model('DB::Problem')->search( { bodies_str => 2489 } )->update( { bodies_str => 1 } ); my $q = FixMyStreet::App->model('DB::Questionnaire')->find_or_new( { problem => $report, }); $q->whensent( \'ms_current_timestamp()' ); @@ -118,7 +118,7 @@ subtest 'check summary counts' => sub { my ($num_alerts) = $mech->content =~ /(\d+) confirmed alerts/; my ($num_qs) = $mech->content =~ /(\d+) questionnaires sent/; - $report->council(2489); + $report->bodies_str(2489); $report->cobrand('barnet'); $report->update; @@ -131,7 +131,7 @@ subtest 'check summary counts' => sub { $mech->content_contains( ($num_alerts+1) . " confirmed alerts" ); $mech->content_contains( ($num_qs+1) . " questionnaires sent" ); - $report->council(2504); + $report->bodies_str(2504); $report->cobrand(''); $report->update; @@ -139,28 +139,30 @@ subtest 'check summary counts' => sub { $alert->update; } - FixMyStreet::App->model('DB::Problem')->search( { council => 1 } )->update( { council => 2489 } ); + FixMyStreet::App->model('DB::Problem')->search( { bodies_str => 1 } )->update( { bodies_str => 2489 } ); ok $mech->host('fixmystreet.com'); }; my $host = FixMyStreet->config('BASE_URL'); -$mech->get_ok('/admin/council_contacts/2650'); + +my $body = $mech->create_body_ok(2650, 'Aberdeen City Council'); +$mech->get_ok('/admin/body/2650'); $mech->content_contains('Aberdeen City Council'); $mech->content_like(qr{AB\d\d}); $mech->content_contains("$host/around"); subtest 'check contact creation' => sub { my $contact = FixMyStreet::App->model('DB::Contact')->search( - { area_id => 2650, category => [ 'test category', 'test/category' ] } + { body_id => 2650, category => [ 'test category', 'test/category' ] } ); $contact->delete_all; my $history = FixMyStreet::App->model('DB::ContactsHistory')->search( - { area_id => 2650, category => [ 'test category', 'test/category' ] } + { body_id => 2650, category => [ 'test category', 'test/category' ] } ); $history->delete_all; - $mech->get_ok('/admin/council_contacts/2650'); + $mech->get_ok('/admin/body/2650'); $mech->submit_form_ok( { with_fields => { category => 'test category', @@ -190,12 +192,12 @@ subtest 'check contact creation' => sub { note => 'test/note', non_public => 'on', } } ); - $mech->get_ok('/admin/council_edit/2650/test/category'); + $mech->get_ok('/admin/body_edit/2650/test/category'); }; subtest 'check contact editing' => sub { - $mech->get_ok('/admin/council_edit/2650/test%20category'); + $mech->get_ok('/admin/body_edit/2650/test%20category'); $mech->submit_form_ok( { with_fields => { email => 'test2@example.com', @@ -216,31 +218,29 @@ subtest 'check contact editing' => sub { $mech->content_contains( '<td>Non Public' ); - $mech->get_ok('/admin/council_edit/2650/test%20category'); + $mech->get_ok('/admin/body_edit/2650/test%20category'); $mech->content_contains( '<td><strong>test2@example.com' ); }; subtest 'check contact updating' => sub { - $mech->get_ok('/admin/council_edit/2650/test%20category'); + $mech->get_ok('/admin/body_edit/2650/test%20category'); $mech->content_like(qr{test2\@example.com</strong>[^<]*</td>[^<]*<td>No}s); - $mech->get_ok('/admin/council_contacts/2650'); + $mech->get_ok('/admin/body/2650'); $mech->form_number( 1 ); $mech->tick( 'confirmed', 'test category' ); $mech->submit_form_ok({form_number => 1}); $mech->content_like(qr'test2@example.com</td>[^<]*<td>Yes's); - $mech->get_ok('/admin/council_edit/2650/test%20category'); + $mech->get_ok('/admin/body_edit/2650/test%20category'); $mech->content_like(qr{test2\@example.com[^<]*</td>[^<]*<td><strong>Yes}s); }; -my $open311 = - FixMyStreet::App->model('DB::Open311Conf')->search( { area_id => 2650 } ); -$open311->delete if $open311; +$body->update({ send_method => undef }); subtest 'check open311 configuring' => sub { - $mech->get_ok('/admin/council_contacts/2650/'); + $mech->get_ok('/admin/body/2650'); $mech->content_lacks('Council contacts configured via Open311'); $mech->form_number(3); @@ -258,11 +258,7 @@ subtest 'check open311 configuring' => sub { $mech->content_contains('Council contacts configured via Open311'); $mech->content_contains('Configuration updated - contacts will be generated automatically later'); - $open311 = - FixMyStreet::App->model('DB::Open311Conf')->search( { area_id => 2650 } ); - - is $open311->count, 1, 'only one configuration'; - my $conf = $open311->first; + my $conf = FixMyStreet::App->model('DB::Body')->find( 2650 ); is $conf->endpoint, 'http://example.com/open311', 'endpoint configured'; is $conf->api_key, 'api key', 'api key configured'; is $conf->jurisdiction, 'mySociety', 'jurisdiction configures'; @@ -282,18 +278,14 @@ subtest 'check open311 configuring' => sub { $mech->content_contains('Configuration updated'); - $open311 = - FixMyStreet::App->model('DB::Open311Conf')->search( { area_id => 2650 } ); - - is $open311->count, 1, 'only one configuration'; - $conf = $open311->first; + $conf = FixMyStreet::App->model('DB::Body')->find( 2650 ); is $conf->endpoint, 'http://example.org/open311', 'endpoint updated'; is $conf->api_key, 'new api key', 'api key updated'; is $conf->jurisdiction, 'open311', 'jurisdiction configures'; }; subtest 'check text output' => sub { - $mech->get_ok('/admin/council_contacts/2650?text=1'); + $mech->get_ok('/admin/body/2650?text=1'); is $mech->content_type, 'text/plain'; $mech->content_contains('test category'); }; @@ -845,6 +837,8 @@ for my $test ( }; } +$mech->create_body_ok(2504, 'Westminster City Council'); + for my $test ( { desc => 'user is problem owner', @@ -853,17 +847,17 @@ for my $test ( update_fixed => 0, update_reopen => 0, update_state => undef, - user_council => undef, + user_body => undef, content => 'user is problem owner', }, { - desc => 'user is council user', + desc => 'user is body user', problem_user => $user, update_user => $user2, update_fixed => 0, update_reopen => 0, update_state => undef, - user_council => 2504, + user_body => 2504, content => 'user is from same council as problem - 2504', }, { @@ -873,7 +867,7 @@ for my $test ( update_fixed => 0, update_reopen => 0, update_state => 'planned', - user_council => 2504, + user_body => 2504, content => 'Update changed problem state to planned', }, { @@ -883,7 +877,7 @@ for my $test ( update_fixed => 1, update_reopen => 0, update_state => undef, - user_council => undef, + user_body => undef, content => 'Update marked problem as fixed', }, { @@ -893,7 +887,7 @@ for my $test ( update_fixed => 0, update_reopen => 1, update_state => undef, - user_council => undef, + user_body => undef, content => 'Update reopened problem', }, ) { @@ -907,7 +901,7 @@ for my $test ( $update->mark_open( $test->{update_reopen} ); $update->update; - $test->{update_user}->from_council( $test->{user_council} ); + $test->{update_user}->from_body( $test->{user_body} ); $test->{update_user}->update; $mech->get_ok('/admin/update_edit/' . $update->id ); @@ -1033,14 +1027,14 @@ subtest 'report search' => sub { $update->user($report->user); $update->update; - $mech->get_ok('/admin/search_reports'); - $mech->get_ok('/admin/search_reports?search=' . $report->id ); + $mech->get_ok('/admin/reports'); + $mech->get_ok('/admin/reports?search=' . $report->id ); $mech->content_contains( $report->title ); my $r_id = $report->id; $mech->content_like( qr{href="http://[^/]*[^.]/report/$r_id/">$r_id</a>} ); - $mech->get_ok('/admin/search_reports?search=' . $report->user->email); + $mech->get_ok('/admin/reports?search=' . $report->user->email); my $u_id = $update->id; $mech->content_like( qr{href="http://[^/]*[^.]/report/$r_id/">$r_id</a>} ); @@ -1049,25 +1043,25 @@ subtest 'report search' => sub { $update->state('hidden'); $update->update; - $mech->get_ok('/admin/search_reports?search=' . $report->user->email); + $mech->get_ok('/admin/reports?search=' . $report->user->email); $mech->content_like( qr{<tr [^>]*hidden[^>]*> \s* <td> \s* $u_id \s* </td>}xs ); $report->state('hidden'); $report->update; - $mech->get_ok('/admin/search_reports?search=' . $report->user->email); + $mech->get_ok('/admin/reports?search=' . $report->user->email); $mech->content_like( qr{<tr [^>]*hidden[^>]*> \s* <td> \s* $r_id \s* </td>}xs ); $report->state('fixed - user'); $report->update; - $mech->get_ok('/admin/search_reports?search=' . $report->user->email); + $mech->get_ok('/admin/reports?search=' . $report->user->email); $mech->content_like( qr{href="http://[^/]*[^.]/report/$r_id/">$r_id</a>} ); }; subtest 'search abuse' => sub { - $mech->get_ok( '/admin/search_users?search=example' ); - $mech->content_like(qr/test4\@example.com.*\n.*\n.*Email in abuse table/); + $mech->get_ok( '/admin/users?search=example' ); + $mech->content_like(qr{test4\@example.com.*</td>\s*<td>.*?</td>\s*<td>\(Email in abuse table}); }; subtest 'show flagged entries' => sub { @@ -1077,27 +1071,29 @@ subtest 'show flagged entries' => sub { $user->flagged( 1 ); $user->update; - $mech->get_ok('/admin/list_flagged'); + $mech->get_ok('/admin/flagged'); $mech->content_contains( $report->title ); $mech->content_contains( $user->email ); }; +$mech->create_body_ok(2509, 'Haringey Borough Council'); + subtest 'user search' => sub { - $mech->get_ok('/admin/search_users'); - $mech->get_ok('/admin/search_users?search=' . $user->name); + $mech->get_ok('/admin/users'); + $mech->get_ok('/admin/users?search=' . $user->name); $mech->content_contains( $user->name); my $u_id = $user->id; $mech->content_like( qr{user_edit/$u_id">Edit</a>} ); - $mech->get_ok('/admin/search_users?search=' . $user->email); + $mech->get_ok('/admin/users?search=' . $user->email); $mech->content_like( qr{user_edit/$u_id">Edit</a>} ); - $user->from_council(2509); + $user->from_body(2509); $user->update; - $mech->get_ok('/admin/search_users?search=2509' ); - $mech->content_contains(2509); + $mech->get_ok('/admin/users?search=2509' ); + $mech->content_contains('Haringey'); }; $log_entries = FixMyStreet::App->model('DB::AdminLog')->search( @@ -1115,13 +1111,15 @@ is $log_entries->count, 0, 'no admin log entries'; $user->flagged( 0 ); $user->update; +$mech->create_body_ok(2607, 'Southend-on-Sea Borough Council'); + for my $test ( { desc => 'edit user name', fields => { name => 'Test User', email => 'test@example.com', - council => 2509, + body => 2509, flagged => undef, }, changes => { @@ -1135,7 +1133,7 @@ for my $test ( fields => { name => 'Changed User', email => 'test@example.com', - council => 2509, + body => 2509, flagged => undef, }, changes => { @@ -1145,15 +1143,15 @@ for my $test ( log_entries => [qw/edit edit/], }, { - desc => 'edit user council', + desc => 'edit user body', fields => { name => 'Changed User', email => 'changed@example.com', - council => 2509, + body => 2509, flagged => undef, }, changes => { - council => 2607, + body => 2607, }, log_count => 3, log_entries => [qw/edit edit edit/], @@ -1163,7 +1161,7 @@ for my $test ( fields => { name => 'Changed User', email => 'changed@example.com', - council => 2607, + body => 2607, flagged => undef, }, changes => { @@ -1177,7 +1175,7 @@ for my $test ( fields => { name => 'Changed User', email => 'changed@example.com', - council => 2607, + body => 2607, flagged => 'on', }, changes => { diff --git a/t/app/controller/alert_new.t b/t/app/controller/alert_new.t index c849b9485..6f130279b 100644 --- a/t/app/controller/alert_new.t +++ b/t/app/controller/alert_new.t @@ -382,7 +382,7 @@ subtest "Test normal alert signups and that alerts are sent" => sub { my $report_time = '2011-03-01 12:00:00'; my $report = FixMyStreet::App->model('DB::Problem')->find_or_create( { postcode => 'EH1 1BB', - council => '2651', + bodies_str => '2651', areas => ',11808,135007,14419,134935,2651,20728,', category => 'Street lighting', title => 'Testing', @@ -532,7 +532,7 @@ for my $test ( my $report = FixMyStreet::App->model('DB::Problem')->find_or_create( { postcode => 'EH1 1BB', - council => '2651', + bodies_str => '2651', areas => ',11808,135007,14419,134935,2651,20728,', category => 'Street lighting', title => 'Alert test for non public reports', @@ -590,7 +590,7 @@ subtest 'check new updates alerts for non public reports only go to report owner my $report = FixMyStreet::App->model('DB::Problem')->find_or_create( { postcode => 'EH1 1BB', - council => '2651', + bodies_str => '2651', areas => ',11808,135007,14419,134935,2651,20728,', category => 'Street lighting', title => 'Alert test for non public reports', diff --git a/t/app/controller/around.t b/t/app/controller/around.t index d973543ce..0f01a9ea9 100644 --- a/t/app/controller/around.t +++ b/t/app/controller/around.t @@ -90,7 +90,7 @@ subtest 'check non public reports are not displayed on around page' => sub { longitude => -3.17492254484, }; my @edinburgh_problems = - $mech->create_problems_for_council( 5, 2651, 'Around page', $params ); + $mech->create_problems_for_body( 5, 2651, 'Around page', $params ); $mech->get_ok('/'); $mech->submit_form_ok( { with_fields => { pc => 'EH99 1SP' } }, diff --git a/t/app/controller/dashboard.t b/t/app/controller/dashboard.t index 25e144464..091335040 100644 --- a/t/app/controller/dashboard.t +++ b/t/app/controller/dashboard.t @@ -12,6 +12,8 @@ my $test_pass = 'password'; my $test_council = 2651; my $test_ward = 20723; +$mech->create_body_ok($test_council, 'City of Edinburgh Council'); + $mech->delete_user( $test_user ); my $user = FixMyStreet::App->model('DB::User')->create( { email => $test_user, @@ -33,7 +35,7 @@ $mech->submit_form( is $mech->status, '404', 'If not council user get 404'; -$user->from_council( $test_council ); +$user->from_body( $test_council ); $user->update; $mech->log_out_ok; @@ -44,7 +46,7 @@ $mech->submit_form_ok( { $mech->content_contains( 'City of Edinburgh' ); -FixMyStreet::App->model('DB::Contact')->search( { area_id => $test_council } ) +FixMyStreet::App->model('DB::Contact')->search( { body_id => $test_council } ) ->delete; delete_problems(); @@ -53,7 +55,7 @@ my @cats = qw( Grafitti Litter Potholes Other ); for my $contact ( @cats ) { FixMyStreet::App->model('DB::Contact')->create( { - area_id => $test_council, + body_id => $test_council, category => $contact, email => "$contact\@example.org", confirmed => 1, @@ -608,7 +610,7 @@ sub make_problem { confirmed => $args->{conf_dt}, whensent => $args->{conf_dt}, lastupdate => $args->{mark_dt} || $args->{conf_dt}, - council => $test_council, + bodies_str => $test_council, postcode => 'EH99 1SP', latitude => '51', longitude => '1', @@ -662,10 +664,10 @@ sub check_report_counts { sub delete_problems { FixMyStreet::App->model('DB::Comment') - ->search( { 'problem.council' => $test_council }, { join => 'problem' } ) + ->search( { 'problem.bodies_str' => $test_council }, { join => 'problem' } ) ->delete; FixMyStreet::App->model('DB::Problem') - ->search( { council => $test_council } )->delete(); + ->search( { bodies_str => $test_council } )->delete(); } done_testing; diff --git a/t/app/controller/index.t b/t/app/controller/index.t index 462b21064..47c08291f 100644 --- a/t/app/controller/index.t +++ b/t/app/controller/index.t @@ -55,12 +55,12 @@ subtest "does pc, (x,y), (e,n) or (lat,lon) go to /around" => sub { } }; -$mech->delete_problems_for_council( 2651 ); +$mech->delete_problems_for_body( 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'); +my @edinburgh_problems = $mech->create_problems_for_body(5, 2651, 'Front page'); is scalar @edinburgh_problems, 5, 'correct number of edinburgh problems created'; $mech->get_ok('/report/' . $edinburgh_problems[2]->id); diff --git a/t/app/controller/json.t b/t/app/controller/json.t index 468fa5b31..405a84821 100644 --- a/t/app/controller/json.t +++ b/t/app/controller/json.t @@ -45,9 +45,11 @@ is_deeply # # put an entry in the database for this test my $user = $mech->create_user_ok('test@example.com'); +my $body = $mech->create_body_ok(2501, 'Wandsworth Borough Council'); + my $problem_args = { postcode => 'sw1a 1aa', - council => '2501', + bodies_str => '2501', areas => ',105164,11806,11827,2247,2501,34817,42011,66045,70786,8519,', category => 'test category', title => 'Test title', @@ -86,7 +88,7 @@ is_deeply # 'category' => 'test category', 'confirmed' => '2000-01-01 12:01:00', 'lastupdate' => '2000-01-01 12:00:00', - 'council' => 'Wandsworth Borough Council', + 'bodies_str' => 'Wandsworth Borough Council', 'detail' => 'Test detail', 'id' => $problem->id, 'name' => 'Test Name', @@ -103,7 +105,7 @@ is_deeply # 'category' => 'test category', 'confirmed' => '2000-01-01 12:02:00', 'lastupdate' => '2000-01-01 12:00:00', - 'council' => 'Wandsworth Borough Council', + 'bodies_str' => 'Wandsworth Borough Council', 'detail' => 'Test detail', 'id' => $anon_problem->id, 'name' => '', diff --git a/t/app/controller/questionnaire.t b/t/app/controller/questionnaire.t index d8d1eb4f3..5c81a43d1 100644 --- a/t/app/controller/questionnaire.t +++ b/t/app/controller/questionnaire.t @@ -30,7 +30,7 @@ my $sent_time = $sent->ymd . ' ' . $sent->hms; my $report = FixMyStreet::App->model('DB::Problem')->find_or_create( { postcode => 'EH1 1BB', - council => '2651', + bodies_str => '2651', areas => ',11808,135007,14419,134935,2651,20728,', category => 'Street lighting', title => 'Testing', diff --git a/t/app/controller/report_display.t b/t/app/controller/report_display.t index aa04e499b..a3c4edfc7 100644 --- a/t/app/controller/report_display.t +++ b/t/app/controller/report_display.t @@ -5,6 +5,7 @@ use Test::More; use FixMyStreet::TestMech; use Web::Scraper; use Path::Class; +use Test::LongString; use DateTime; my $mech = FixMyStreet::TestMech->new; @@ -33,7 +34,7 @@ my $dt = DateTime->new( my $report = FixMyStreet::App->model('DB::Problem')->find_or_create( { postcode => 'SW1A 1AA', - council => '2504', + bodies_str => '2504', areas => ',105255,11806,11828,2247,2504,', category => 'Other', title => 'Test 2', @@ -94,6 +95,19 @@ subtest "change report to unconfirmed and check for 404 status" => sub { ok $report->update( { state => 'confirmed' } ), 'confirm report again'; }; + +subtest "Zurich unconfirmeds are 200" => sub { + if ( !FixMyStreet::Cobrand->exists('zurich') ) { + plan skip_all => 'Skipping Zurich test without Zurich cobrand'; + } + $mech->host( 'zurich.fixmystreet.com' ); + ok $report->update( { state => 'unconfirmed' } ), 'unconfirm report'; + $mech->get_ok("/report/$report_id"); + $mech->content_contains( 'This report is awaiting moderation' ); + ok $report->update( { state => 'confirmed' } ), 'confirm report again'; + $mech->host( 'www.fixmystreet.com' ); +}; + subtest "change report to hidden and check for 410 status" => sub { ok $report->update( { state => 'hidden' } ), 'hide report'; ok $mech->get("/report/$report_id"), "get '/report/$report_id'"; @@ -385,39 +399,111 @@ for my $test ( }; } +subtest "Zurich banners are displayed correctly" => sub { + if ( !FixMyStreet::Cobrand->exists('zurich') ) { + plan skip_all => 'Skipping Zurich test without Zurich cobrand'; + } + $mech->host( 'zurich.fixmystreet.com' ); + + for my $test ( + { + description => 'new report', + state => 'unconfirmed', + banner_id => 'closed', + banner_text => 'Erfasst' + }, + { + description => 'confirmed report', + state => 'confirmed', + banner_id => 'closed', + banner_text => 'Aufgenommen', + }, + { + description => 'fixed report', + state => 'fixed - council', + banner_id => 'fixed', + banner_text => 'Erledigt', + }, + { + description => 'closed report', + state => 'closed', + banner_id => 'fixed', + banner_text => 'Erledigt', + }, + { + description => 'in progress report', + state => 'in progress', + banner_id => 'progress', + banner_text => 'In Bearbeitung', + }, + { + description => 'planned report', + state => 'planned', + banner_id => 'progress', + banner_text => 'In Bearbeitung', + }, + ) { + subtest "banner for $test->{description}" => sub { + $report->state( $test->{state} ); + $report->update; + + $mech->get_ok("/report/$report_id"); + is $mech->uri->path, "/report/$report_id", "at /report/$report_id"; + my $banner = $mech->extract_problem_banner; + if ( $banner->{text} ) { + $banner->{text} =~ s/^ //g; + $banner->{text} =~ s/ $//g; + } + + is $banner->{id}, $test->{banner_id}, 'banner id'; + if ($test->{banner_text}) { + like_string( $banner->{text}, qr/$test->{banner_text}/i, 'banner text is ' . $test->{banner_text} ); + } else { + is $banner->{text}, $test->{banner_text}, 'banner text'; + } + + }; + } + + $mech->host( 'www.fixmystreet.com' ); +}; + +$mech->create_body_ok(2504, 'Westminster City Council'); +$mech->create_body_ok(2505, 'Camden Borough Council'); + for my $test ( { desc => 'no state dropdown if user not from authority', - from_council => 0, + from_body => undef, no_state => 1, - report_council => '2504', + report_body => '2504', }, { desc => 'state dropdown if user from authority', - from_council => 2504, + from_body => 2504, no_state => 0, - report_council => '2504', + report_body => '2504', }, { - desc => 'no state dropdown if user not from same council as problem', - from_council => 2505, + desc => 'no state dropdown if user not from same body as problem', + from_body => 2505, no_state => 1, - report_council => '2504', + report_body => '2504', }, { - desc => 'state dropdown if user from authority and problem sent to multiple councils', - from_council => 2504, + desc => 'state dropdown if user from authority and problem sent to multiple bodies', + from_body => 2504, no_state => 0, - report_council => '2504,2506', + report_body => '2504,2506', }, ) { subtest $test->{desc} => sub { $mech->log_in_ok( $user->email ); - $user->from_council( $test->{from_council} ); + $user->from_body( $test->{from_body} ); $user->update; $report->discard_changes; - $report->council( $test->{report_council} ); + $report->bodies_str( $test->{report_body} ); $report->update; $mech->get_ok("/report/$report_id"); @@ -431,7 +517,7 @@ for my $test ( } $report->discard_changes; -$report->council( 2504 ); +$report->bodies_str( 2504 ); $report->update; # tidy up diff --git a/t/app/controller/report_interest_count.t b/t/app/controller/report_interest_count.t index dd44a83d4..bfd1a8d1f 100644 --- a/t/app/controller/report_interest_count.t +++ b/t/app/controller/report_interest_count.t @@ -16,11 +16,6 @@ my $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, @@ -33,7 +28,7 @@ my $dt = DateTime->new( my $report = FixMyStreet::App->model('DB::Problem')->find_or_create( { postcode => 'SW1A 1AA', - council => '2504', + bodies_str => '2504', areas => ',105255,11806,11828,2247,2504,', category => 'Other', title => 'Test 2', @@ -59,21 +54,24 @@ ok $report, "created test report - $report_id"; SKIP: { skip( "Need 'fixmybarangay' in ALLOWED_COBRANDS config", 29 ) unless FixMyStreet::Cobrand->exists('fixmybarangay'); + + $mech->create_body_ok(2504, 'Westminster City Council'); + for my $test ( { - desc => 'if not from council then no supporter button', - from_council => 0, + desc => 'if not from body then no supporter button', + from_body => undef, support_string => 'No supporters', }, { - desc => 'from council user can increment supported count', - from_council => 2504, + desc => 'from body user can increment supported count', + from_body => 2504, support_string => 'No supporters', updated_support => '1 supporter' }, { desc => 'correct grammar for more than one supporter', - from_council => 2504, + from_body => 2504, support_string => '1 supporter', updated_support => '2 supporters' }, @@ -81,17 +79,17 @@ SKIP: { 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->from_body( $test->{from_body} ); $user->update; - $report->discard_changes; - $report->council( $test->{report_council} ); - $report->update; + $report->update( { + bodies_str => $test->{report_council} + } ); $mech->get_ok("/report/$report_id"); $mech->content_contains( $test->{support_string} ); - if ( $test->{from_council} ) { + if ( $test->{from_body} ) { $mech->content_contains('Add support'); $mech->submit_form_ok( { form_number => 1 } ); @@ -104,18 +102,16 @@ SKIP: { }; } - subtest 'check non council user cannot increment support count' => sub { + subtest 'check non body 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; + ok $report->update({ interest_count => 1 }), 'updated interest count'; is $report->interest_count, 1, 'correct interest count'; $mech->get_ok("/report/$report_id"); $mech->content_contains( '1 supporter' ); + # This doesn't send cookie, so is logged out $mech->post_ok("/report/support", { id => $report_id } ); is $mech->uri, "http://fixmybarangay.com/report/$report_id", 'add support redirects to report page'; @@ -135,7 +131,7 @@ subtest 'check support details not shown if not enabled in cobrand' => sub { }; $report->discard_changes; -$report->council( 2504 ); +$report->bodies_str( 2504 ); $report->update; # tidy up diff --git a/t/app/controller/report_new.t b/t/app/controller/report_new.t index 0206feed3..868977953 100644 --- a/t/app/controller/report_new.t +++ b/t/app/controller/report_new.t @@ -33,49 +33,61 @@ my %contact_params = ( whenedited => \'current_timestamp', note => 'Created for test', ); + +for my $body ( + { id => 2651, name => 'City of Edinburgh Council' }, + { id => 2226, name => 'Gloucestershire County Council' }, + { id => 2326, name => 'Cheltenham Borough Council' }, + { id => 2482, name => 'Bromley Council' }, + { id => 2240, name => 'Staffordshire County Council' }, + { id => 2434, name => 'Lichfield District Council' }, +) { + $mech->create_body_ok($body->{id}, $body->{name}); +} + # Let's make some contacts to send things to! FixMyStreet::App->model('DB::Contact')->search( { email => { 'like', '%example.com' }, } )->delete; my $contact1 = FixMyStreet::App->model('DB::Contact')->find_or_create( { %contact_params, - area_id => 2651, # Edinburgh + body_id => 2651, # Edinburgh category => 'Street lighting', email => 'highways@example.com', } ); my $contact2 = FixMyStreet::App->model('DB::Contact')->find_or_create( { %contact_params, - area_id => 2226, # Gloucestershire + body_id => 2226, # Gloucestershire category => 'Potholes', email => 'potholes@example.com', } ); my $contact3 = FixMyStreet::App->model('DB::Contact')->find_or_create( { %contact_params, - area_id => 2326, # Cheltenham + body_id => 2326, # Cheltenham category => 'Trees', email => 'trees@example.com', } ); my $contact4 = FixMyStreet::App->model('DB::Contact')->find_or_create( { %contact_params, - area_id => 2482, # Bromley + body_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 + body_id => 2651, # Edinburgh category => 'Trees', email => 'trees@example.com', } ); my $contact6 = FixMyStreet::App->model('DB::Contact')->find_or_create( { %contact_params, - area_id => 2434, # Lichfield + body_id => 2434, # Lichfield category => 'Trees', email => 'trees@example.com', } ); my $contact7 = FixMyStreet::App->model('DB::Contact')->find_or_create( { %contact_params, - area_id => 2240, # Lichfield + body_id => 2240, # Lichfield category => 'Street lighting', email => 'highways@example.com', } ); @@ -92,6 +104,57 @@ ok $contact7, "created test contact 7"; foreach my $test ( { msg => 'all fields empty', + pc => 'OX1 3DH', + fields => { + title => '', + detail => '', + photo => '', + name => '', + may_show_name => '1', + email => '', + phone => '', + password_sign_in => '', + password_register => '', + remember_me => undef, + }, + changes => {}, + errors => [ + 'Please enter a subject', + 'Please enter some details', + # No category error, as no categories for Oxon at all, so is skipped + 'Please enter your email', + 'Please enter your name', + ], + }, + { + msg => 'all fields empty, bad category', + pc => 'GL50 2PR', + fields => { + title => '', + detail => '', + photo => '', + name => '', + may_show_name => '1', + email => '', + phone => '', + category => 'Something bad', + password_sign_in => '', + password_register => '', + remember_me => undef, + }, + changes => { + category => '-- Pick a category --', + }, + errors => [ + 'Please enter a subject', + 'Please enter some details', + 'Please choose a category', + 'Please enter your email', + 'Please enter your name', + ], + }, + { + msg => 'all fields empty except category', pc => 'SW1A 1AA', fields => { title => '', @@ -503,7 +566,7 @@ foreach my $test ( is $mech->get( '/report/' . $report->id )->code, 404, "report not found"; # Check the report has been assigned appropriately - is $report->council, 2651; + is $report->bodies_str, 2651; # receive token my $email = $mech->get_email; @@ -659,7 +722,7 @@ subtest "test report creation for a user who is signing in as they report" => su is $mech->uri->path, "/report/" . $report->id, "redirected to report page"; # Check the report has been assigned appropriately - is $report->council, 2651; + is $report->bodies_str, 2651; # check that no emails have been sent $mech->email_count_is(0); @@ -750,7 +813,7 @@ foreach my $test ( ok $report, "Found the report"; # Check the report has been assigned appropriately - is $report->council, $test->{council}; + is $report->bodies_str, $test->{council}; # check that we got redirected to /report/ is $mech->uri->path, "/report/" . $report->id, "redirected to report page"; @@ -1155,7 +1218,7 @@ SKIP: { ok $report, "Found the report"; # Check the report has been assigned appropriately - is $report->council, $test->{council}; + is $report->bodies_str, $test->{council}; if ( $test->{redirect} ) { is $mech->uri->path, "/report/" . $report->id, "redirected to report page"; @@ -1210,9 +1273,10 @@ SKIP: { my $cobrand = FixMyStreet::Cobrand::SeeSomething->new(); + $mech->create_body_ok(2535, 'Sandwell Borough Council'); my $bus_contact = FixMyStreet::App->model('DB::Contact')->find_or_create( { %contact_params, - area_id => 2535, + body_id => 2535, category => 'Bus', email => 'bus@example.com', non_public => 1, diff --git a/t/app/controller/report_new_open311.t b/t/app/controller/report_new_open311.t index 55c5a92e8..22d2d1f97 100644 --- a/t/app/controller/report_new_open311.t +++ b/t/app/controller/report_new_open311.t @@ -7,12 +7,12 @@ use Web::Scraper; my $mech = FixMyStreet::TestMech->new; -my $open311Conf = FixMyStreet::App->model('DB::Open311Conf')->find_or_create( { - area_id => 2651, - endpoint => 'http://example.com/open311', - jurisdiction => 'mySociety', - api_key => 'apikey', -} ); +my $body = $mech->create_body_ok(2651, 'City of Edinburgh Council'); +$body->update({ + endpoint => 'http://example.com/open311', + jurisdiction => 'mySociety', + api_key => 'apikey', +}); my %contact_params = ( confirmed => 1, @@ -24,7 +24,7 @@ my %contact_params = ( # Let's make some contacts to send things to! my $contact1 = FixMyStreet::App->model('DB::Contact')->find_or_create( { %contact_params, - area_id => 2651, # Edinburgh + body_id => 2651, # Edinburgh category => 'Street lighting', email => '100', extra => [ { description => 'Lamppost number', code => 'number', required => 'True' }, @@ -35,7 +35,7 @@ my $contact1 = FixMyStreet::App->model('DB::Contact')->find_or_create( { } ); my $contact2 = FixMyStreet::App->model('DB::Contact')->find_or_create( { %contact_params, - area_id => 2651, # Edinburgh + body_id => 2651, # Edinburgh category => 'Graffiti Removal', email => '101', } ); diff --git a/t/app/controller/report_updates.t b/t/app/controller/report_updates.t index 3986d01b5..2765ed246 100644 --- a/t/app/controller/report_updates.t +++ b/t/app/controller/report_updates.t @@ -35,7 +35,7 @@ my $dt = DateTime->new( my $report = FixMyStreet::App->model('DB::Problem')->find_or_create( { postcode => 'SW1A 1AA', - council => '2504', + bodies_str => '2504', areas => ',105255,11806,11828,2247,2504,', category => 'Other', title => 'Test 2', @@ -409,7 +409,7 @@ $report->update; subtest 'check non authority user cannot change set state' => sub { $mech->log_in_ok( $user->email ); - $user->from_council( 0 ); + $user->from_body( undef ); $user->update; $mech->get_ok("/report/$report_id"); @@ -434,10 +434,12 @@ subtest 'check non authority user cannot change set state' => sub { is $report->state, 'confirmed', 'state unchanged'; }; +$mech->create_body_ok(2504, 'Westminster City Council'); + for my $state ( qw/unconfirmed hidden partial/ ) { subtest "check that update cannot set state to $state" => sub { $mech->log_in_ok( $user->email ); - $user->from_council( 2504 ); + $user->from_body( 2504 ); $user->update; $mech->get_ok("/report/$report_id"); @@ -586,18 +588,18 @@ for my $test ( state => 'fixed', }, state => 'fixed - council', - report_councils => '2504,2505', + report_bodies => '2504,2505', }, ) { subtest $test->{desc} => sub { $report->comments->delete; - if ( $test->{ report_councils } ) { - $report->council( $test->{ report_councils } ); + if ( $test->{ report_bodies } ) { + $report->bodies_str( $test->{ report_bodies } ); $report->update; } $mech->log_in_ok( $user->email ); - $user->from_council( 2504 ); + $user->from_body( 2504 ); $user->update; $mech->get_ok("/report/$report_id"); @@ -670,7 +672,7 @@ subtest 'check meta correct for comments marked confirmed but not marked open' = subtest "check first comment with no status change has no status in meta" => sub { $mech->log_in_ok( $user->email ); - $user->from_council( 0 ); + $user->from_body( undef ); $user->update; my $comment = $report->comments->first; @@ -684,7 +686,7 @@ subtest "check first comment with no status change has no status in meta" => sub subtest "check comment with no status change has not status in meta" => sub { $mech->log_in_ok( $user->email ); - $user->from_council( 0 ); + $user->from_body( undef ); $user->update; my $comment = $report->comments->first; @@ -718,7 +720,7 @@ subtest "check comment with no status change has not status in meta" => sub { my $update_meta = $mech->extract_update_metas; unlike $update_meta->[1], qr/marked as/, 'update meta does not include state change'; - $user->from_council( 2504 ); + $user->from_body( 2504 ); $user->update; $mech->get_ok("/report/$report_id"); @@ -820,11 +822,11 @@ subtest 'check meta correct for second comment marking as reopened' => sub { like $update_meta->[1], qr/reopened$/, 'update meta says reopened'; }; -$user->from_council(0); +$user->from_body(undef); $user->update; $report->state('confirmed'); -$report->council('2504'); +$report->bodies_str('2504'); $report->update; for my $test ( diff --git a/t/app/controller/reports.t b/t/app/controller/reports.t index a4dab6597..503950d8a 100644 --- a/t/app/controller/reports.t +++ b/t/app/controller/reports.t @@ -8,11 +8,15 @@ use DateTime; ok( my $mech = FixMyStreet::TestMech->new, 'Created mech object' ); -$mech->delete_problems_for_council( 2504 ); -$mech->delete_problems_for_council( 2651 ); +$mech->create_body_ok(2514, 'Birmingham City Council'); +$mech->create_body_ok(2651, 'City of Edinburgh Council'); +$mech->create_body_ok(2504, 'Westminster City Council'); -my @edinburgh_problems = $mech->create_problems_for_council(3, 2651, 'All reports'); -my @westminster_problems = $mech->create_problems_for_council(5, 2504, 'All reports'); +$mech->delete_problems_for_body( 2504 ); +$mech->delete_problems_for_body( 2651 ); + +my @edinburgh_problems = $mech->create_problems_for_body(3, 2651, 'All reports'); +my @westminster_problems = $mech->create_problems_for_body(5, 2504, 'All reports'); is scalar @westminster_problems, 5, 'correct number of westminster problems created'; is scalar @edinburgh_problems, 3, 'correct number of edinburgh problems created'; @@ -63,6 +67,7 @@ SKIP: { skip( "Need 'fiksgatami' in ALLOWED_COBRANDS config", 8 ) unless FixMyStreet::Cobrand->exists('fiksgatami'); + $mech->create_body_ok(3, 'Oslo'); 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/controller/rss.t b/t/app/controller/rss.t index 456067e6c..f04a17151 100644 --- a/t/app/controller/rss.t +++ b/t/app/controller/rss.t @@ -17,7 +17,7 @@ my $user1 = FixMyStreet::App->model('DB::User') my $report = FixMyStreet::App->model('DB::Problem')->find_or_create( { postcode => 'eh1 1BB', - council => '2651', + bodies_str => '2651', areas => ',11808,135007,14419,134935,2651,20728,', category => 'Street lighting', title => 'Testing', @@ -113,6 +113,68 @@ $mech->content_contains( "Testing, 10th October" ); $mech->content_contains( '18 North Bridge, Edinburgh' ); $report->delete(); + +my $now = DateTime->now(); +my $report_to_council = FixMyStreet::App->model('DB::Problem')->find_or_create( + { + postcode => 'WS13 6YY', + bodies_str => '2434', + areas => ',2434,2240,', + category => 'Other', + title => 'council report', + detail => 'Test 2 Detail', + used_map => 't', + name => 'Test User', + anonymous => 'f', + state => 'closed', + confirmed => $now->ymd . ' ' . $now->hms, + lang => 'en-gb', + service => '', + cobrand => 'default', + cobrand_data => '', + send_questionnaire => 't', + latitude => '52.727588', + longitude => '-1.731322', + user_id => $user1->id, + } +); + +my $report_to_county_council = FixMyStreet::App->model('DB::Problem')->find_or_create( + { + postcode => 'WS13 6YY', + bodies_str => '2240', + areas => ',2434,2240,', + category => 'Other', + title => 'county report', + detail => 'Test 2 Detail', + used_map => 't', + name => 'Test User', + anonymous => 'f', + state => 'closed', + confirmed => $now->ymd . ' ' . $now->hms, + lang => 'en-gb', + service => '', + cobrand => 'default', + cobrand_data => '', + send_questionnaire => 't', + latitude => '52.727588', + longitude => '-1.731322', + user_id => $user1->id, + } +); + +subtest "check RSS feeds on cobrand have correct URLs for non-cobrand reports" => sub { + $mech->host('lichfielddc.fixmystreet.com'); + $mech->get_ok("/rss/area/Lichfield"); + + my $expected1 = mySociety::Config::get('BASE_URL') . '/report/' . $report_to_county_council->id; + my $cobrand = FixMyStreet::Cobrand->get_class_for_moniker('lichfielddc')->new(); + my $expected2 = $cobrand->base_url . '/report/' . $report_to_council->id; + + $mech->content_contains($expected1, 'non cobrand area report point to fixmystreet.com'); + $mech->content_contains($expected2, 'cobrand area report point to cobrand url'); +}; + $mech->delete_user( $user1 ); done_testing(); |